Skip to content

Commit 5789f2a

Browse files
committed
os_version: return char
1 parent 5d3981b commit 5789f2a

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

+stdlib/+dotnet/os_version.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
v = System.Environment.OSVersion.VersionString;
44
% https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.versionstring
55
vs = split(string(v), ' ');
6-
version = vs(end);
7-
os = join(vs(1:end-1));
6+
7+
version = char(vs(end));
8+
os = char(join(vs(1:end-1)));
89

910
end

+stdlib/+java/os_version.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
function [os, version] = os_version()
22

3-
os = javaMethod("getProperty", "java.lang.System", "os.name");
4-
version = javaMethod("getProperty", "java.lang.System", "os.version");
5-
os = string(os);
6-
version = string(version);
3+
os = char(javaMethod("getProperty", "java.lang.System", "os.name"));
4+
version = char(javaMethod("getProperty", "java.lang.System", "os.version"));
75

86
end

+stdlib/+python/os_version.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function [os, version] = os_version()
22

33
try
4-
os = string(py.platform.system());
5-
version = string(py.platform.version());
4+
os = char(py.platform.system());
5+
version = char(py.platform.version());
66
catch e
77
warning(e.identifier, 'Failed to get OS version using Python: %s', e.message)
8-
os = string.empty();
9-
version = string.empty();
8+
os = '';
9+
version = '';
1010
end
1111

1212
end

+stdlib/+sys/os_version.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44
cmd1 = 'pwsh -c "(Get-CimInstance -ClassName Win32_OperatingSystem).Caption"';
55
cmd2 = 'pwsh -c "(Get-CimInstance -ClassName Win32_OperatingSystem).Version"';
66
else
7-
cmd1 = "uname -s";
8-
cmd2 = "uname -r";
7+
cmd1 = 'uname -s';
8+
cmd2 = 'uname -r';
99
end
1010

1111
[s, os] = system(cmd1);
1212
if s == 0
1313
os = strip(os);
1414
else
15-
error("Failed to get OS name: %s", os);
15+
os = '';
1616
end
1717

1818
[s, version] = system(cmd2);
1919
if s == 0
2020
version = strip(version);
2121
else
22-
error("Failed to get OS version: %s", version);
22+
version = '';
2323
end
2424

2525
end

test/TestSys.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ function test_os_version(tc, all_fun)
117117
return
118118
end
119119

120+
tc.verifyClass(os, 'char')
121+
tc.verifyClass(ver, 'char')
120122
tc.verifyGreaterThan(strlength(os), 0, "expected non-empty os")
121123
tc.verifyGreaterThan(strlength(ver), 0, "expected non-empty version")
122124
end

0 commit comments

Comments
 (0)