Skip to content

Commit 0db11db

Browse files
committed
add perl.is_admin()
1 parent 1ef4f4d commit 0db11db

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

+stdlib/+perl/is_admin.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function [y, cmd] = is_admin()
2+
3+
if ispc()
4+
% https://metacpan.org/pod/Win32#Win32::IsAdminUser()
5+
c = 'use Win32; print Win32::IsAdminUser() ? 1 : 0';
6+
else
7+
% check if the user ID is 0 (root)
8+
c = 'print $< == 0 ? 1 : 0';
9+
end
10+
11+
cmd = sprintf('"%s" -e "%s"', stdlib.perl_exe(), c);
12+
13+
[s, m] = system(cmd);
14+
15+
y = s == 0 && m == "1";
16+
17+
end

+stdlib/is_admin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
function [ok, b] = is_admin(backend)
88
arguments
9-
backend (1,:) string = ["java", "dotnet", "python", "sys"]
9+
backend (1,:) string = ["java", "dotnet", "perl", "python", "sys"]
1010
end
1111

1212
o = stdlib.Backend(mfilename(), backend);
File renamed without changes.

0 commit comments

Comments
 (0)