@@ -22,6 +22,16 @@ elseif is_linux()
2222 pw_dir:: Cstring
2323 pw_shell:: Cstring
2424 end
25+ else
26+ immutable Cpasswd
27+ pw_name:: Cstring
28+ pw_uid:: Cint
29+ pw_gid:: Cint
30+ pw_dir:: Cstring
31+ pw_shell:: Cstring
32+ end
33+
34+ Cpasswd () = Cpasswd (pointer (" NA" ), 0 , 0 , pointer (" NA" ), pointer (" NA" ))
2535end
2636
2737immutable Cgroup
@@ -30,16 +40,16 @@ immutable Cgroup
3040 gr_gid:: Cint
3141end
3242
43+ Cgroup () = Cgroup (pointer (" NA" ), pointer (" NA" ), 0 )
44+
3345immutable User
3446 name:: String
3547 uid:: UInt64
3648 gid:: UInt64
3749 dir:: String
3850 shell:: String
3951
40- function User (passwd:: Ptr{Cpasswd} )
41- ps = unsafe_load (passwd)
42-
52+ function User (ps:: Cpasswd )
4353 new (
4454 unsafe_string (ps. pw_name),
4555 UInt64 (ps. pw_uid),
@@ -50,54 +60,71 @@ immutable User
5060 end
5161end
5262
63+ User (passwd:: Ptr{Cpasswd} ) = User (unsafe_load (passwd))
64+
5365function Base. show (io:: IO , user:: User )
5466 print (io, " $(user. uid) ($(user. name) )" )
5567end
5668
5769function User (name:: String )
58- ps = ccall ((:getpwnam , " libc" ), Ptr{Cpasswd}, (Ptr{UInt8},), name)
70+ ps = @static if is_unix ()
71+ ccall ((:getpwnam , " libc" ), Ptr{Cpasswd}, (Ptr{UInt8},), name)
72+ else
73+ Cpasswd ()
74+ end
75+
5976 User (ps)
6077end
6178
6279function User (uid:: UInt64 )
63- ps = ccall ((:getpwuid , " libc" ), Ptr{Cpasswd}, (UInt64,), uid)
80+ ps = @static if is_unix ()
81+ ccall ((:getpwuid , " libc" ), Ptr{Cpasswd}, (UInt64,), uid)
82+ else
83+ Cpasswd ()
84+ end
85+
6486 User (ps)
6587end
6688
6789function User ()
68- uid = ccall ((:geteuid , " libc" ), Cint, ())
90+ uid = @static is_unix () ? ccall ((:geteuid , " libc" ), Cint, ()) : 0
6991 User (UInt64 (uid))
7092end
7193
7294immutable Group
7395 name:: String
7496 gid:: UInt64
7597
76- function Group (group:: Ptr{Cgroup} )
77- gr = unsafe_load (group)
78-
79- new (
80- unsafe_string (gr. gr_name),
81- UInt64 (gr. gr_gid)
82- )
83- end
98+ Group (gr:: Cgroup ) = new (unsafe_string (gr. gr_name), UInt64 (gr. gr_gid))
8499end
85100
101+ Group (group:: Ptr{Cgroup} ) = Group (unsafe_load (group))
102+
86103function Base. show (io:: IO , group:: Group )
87104 print (io, " $(group. gid) ($(group. name) )" )
88105end
89106
90107function Group (name:: String )
91- ps = ccall ((:getgrnam , " libc" ), Ptr{Cgroup}, (Ptr{UInt8},), name)
108+ ps = @static if is_unix ()
109+ ccall ((:getgrnam , " libc" ), Ptr{Cgroup}, (Ptr{UInt8},), name)
110+ else
111+ Cgroup ()
112+ end
113+
92114 Group (ps)
93115end
94116
95117function Group (gid:: UInt64 )
96- gr = ccall ((:getgrgid , " libc" ), Ptr{Cgroup}, (UInt64,), gid)
118+ gr = @static if is_unix ()
119+ ccall ((:getgrgid , " libc" ), Ptr{Cgroup}, (UInt64,), gid)
120+ else
121+ Cgroup ()
122+ end
123+
97124 Group (gr)
98125end
99126
100127function Group ()
101- gid = ccall ((:getegid , " libc" ), Cint, ())
128+ gid = @static is_unix () ? ccall ((:getegid , " libc" ), Cint, ()) : 0
102129 Group (UInt64 (gid))
103130end
0 commit comments