Skip to content

Commit 5693bbb

Browse files
committed
getpid => get_pid()
1 parent 8a1888d commit 5693bbb

File tree

14 files changed

+80
-52
lines changed

14 files changed

+80
-52
lines changed

+stdlib/get_pid.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
%% GET_PID process ID of Matlab session
2+
3+
function pid = get_pid()
4+
5+
if stdlib.isoctave
6+
pid = getpid();
7+
else
8+
pid = feature("getpid");
9+
end
10+
11+
end
12+
13+
%!assert(get_pid() > 0, "expected positive PID")

+stdlib/getpid.m

Lines changed: 0 additions & 4 deletions
This file was deleted.

+stdlib/is_absolute.m

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
%% IS_ABSOLUTE is path absolute?
2-
%
3-
%!assert(is_absolute('', false), false)
4-
%!test
5-
%! if ispc
6-
%! assert(is_absolute('C:\', false), true)
7-
%! assert(is_absolute('C:/', false), true)
8-
%! assert(is_absolute('C:', false), false)
9-
%! assert(is_absolute('C', false), false)
10-
%! else
11-
%! assert(is_absolute('/', false), true)
12-
%! assert(is_absolute('/usr', false), true)
13-
%! assert(is_absolute('usr', false), false)
14-
%! endif
2+
% on Windows, absolute paths must be at least 3 character long, starting with a root name followed by a slash
3+
% on non-Windows, absolute paths must start with a slash
4+
155

166
function isabs = is_absolute(p, use_java)
177
arguments
@@ -33,10 +23,24 @@
3323
else
3424
L = strlength(p);
3525
if ispc
36-
isabs = L > 2 && strlength(stdlib.root_name(p)) && any(extractBetween(p, 3, 3) == ["/", "\"]);
26+
s = extractBetween(p, 3, 3);
27+
isabs = L > 2 && strlength(stdlib.root_name(p)) && (s == '/' || s == '\');
3728
else
3829
isabs = L >= 1 && startsWith(p, "/");
3930
end
4031
end
4132

4233
end
34+
35+
%!assert(is_absolute('', false), false)
36+
%!test
37+
%! if ispc
38+
%! assert(is_absolute('C:\', false), true)
39+
%! assert(is_absolute('C:/', false), true)
40+
%! assert(is_absolute('C:', false), false)
41+
%! assert(is_absolute('C', false), false)
42+
%! else
43+
%! assert(is_absolute('/', false), true)
44+
%! assert(is_absolute('/usr', false), true)
45+
%! assert(is_absolute('usr', false), false)
46+
%! endif

+stdlib/is_exe.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
%% IS_EXE is file executable
22
%
33
% false if file does not exist
4-
%
5-
%!assert (is_exe('', false), false)
4+
65

76
function ok = is_exe(file, use_java)
87
arguments
@@ -30,4 +29,9 @@
3029
ok = status ~= 0 && (v.UserExecute || (~isnan(v.GroupExecute) && v.GroupExecute) || (~isnan(v.OtherExecute) && v.OtherExecute));
3130

3231
end
32+
3333
end
34+
35+
%!assert (is_exe('', false), false)
36+
%!assert (is_exe(tempname, false), false)
37+
%!assert (is_exe(program_invocation_name, 0), true)

+stdlib/is_readable.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
%% IS_READABLE is file readable
22
%
3-
% Ref: https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#isReadable(java.nio.file.Path)
4-
%
5-
%!assert (is_readable('is_readable.m', false))
6-
%!assert (is_readable('', false), false)
3+
% non-existant file is false
74

85
function ok = is_readable(file, use_java)
96
arguments
@@ -16,6 +13,7 @@
1613
% needs absolute()
1714
file = stdlib.absolute(file, "", false, use_java);
1815

16+
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#isReadable(java.nio.file.Path)
1917
ok = java.nio.file.Files.isReadable(java.io.File(file).toPath());
2018
else
2119
[status, v] = fileattrib(file);
@@ -24,3 +22,6 @@
2422
end
2523

2624
end
25+
26+
%!assert (is_readable('is_readable.m', false))
27+
%!assert (is_readable('', false), false)

+stdlib/is_writable.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
%% IS_WRITABLE is path writable
22
%
3-
%!assert (is_writable('is_writable.m', false))
4-
%!assert (is_writable('', false), false)
3+
% non-existant file is false
54

65
function ok = is_writable(file, use_java)
76
arguments
@@ -23,3 +22,6 @@
2322
end
2423

2524
end
25+
26+
%!assert (is_writable('is_writable.m', false))
27+
%!assert (is_writable('', false), false)

+stdlib/null_file.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
%% NULL_FILE get null file path
22

33
function nul = null_file()
4+
45
if ispc
56
nul = "NUL";
67
else

+stdlib/posix.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
% convert a path to a Posix string path separated with "/" even on Windows.
33
% If Windows path also have escaping "\" this breaks
44
%
5-
%!assert (posix('/'), '/')
65

76
function r = posix(p)
87
arguments
@@ -16,3 +15,5 @@
1615
end
1716

1817
end
18+
19+
%!assert (posix('/'), '/')

+stdlib/root.m

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
%% ROOT get root path
22
% ROOT(P) returns the root path of P.
33
% root is the root_name + root_directory.
4-
%
5-
%!assert(root('', 0), '')
6-
%!assert(root('/', 0), '/')
7-
%!test
8-
%! if ispc
9-
%! assert(root('C:\', 0), 'C:/')
10-
%! assert(root('C:/', 0), 'C:/')
11-
%! assert(root('C:', 0), 'C:')
12-
%! assert(root('C', 0), '')
13-
%! endif
4+
145

156
function r = root(p, use_java)
167
arguments
@@ -66,3 +57,13 @@
6657
end
6758

6859
end
60+
61+
%!assert(root('', 0), '')
62+
%!assert(root('/', 0), '/')
63+
%!test
64+
%! if ispc
65+
%! assert(root('C:\', 0), 'C:/')
66+
%! assert(root('C:/', 0), 'C:/')
67+
%! assert(root('C:', 0), 'C:')
68+
%! assert(root('C', 0), '')
69+
%! endif

+stdlib/root_name.m

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,7 @@
33
% root_name is the drive letter on Windows without the trailing slash
44
% or an empty string if P is not an absolute path.
55
% on non-Windows platforms, root_name is always an empty string.
6-
%
7-
%!assert(root_name(''), '')
8-
%!assert(root_name('/'), '')
9-
%!test
10-
%! if ispc
11-
%! assert(root_name('C:\'), 'C:')
12-
%! assert(root_name('C:/'), 'C:')
13-
%! assert(root_name('C:'), 'C:')
14-
%! assert(root_name('C'), '')
15-
%! endif
6+
167

178
function r = root_name(p)
189
arguments
@@ -36,3 +27,13 @@
3627
end
3728

3829
end
30+
31+
%!assert(root_name(''), '')
32+
%!assert(root_name('/'), '')
33+
%!test
34+
%! if ispc
35+
%! assert(root_name('C:\'), 'C:')
36+
%! assert(root_name('C:/'), 'C:')
37+
%! assert(root_name('C:'), 'C:')
38+
%! assert(root_name('C'), '')
39+
%! endif

0 commit comments

Comments
 (0)