


## posix-id.pkg
# Compiled by:
# src/lib/std/src/standard-core.sublib# API for POSIX 1003.1 process dictionary submodule
stipulate
package time = time_guts; # time_guts is from src/lib/std/src/time-guts.pkg# package f8b = eight_byte_float_guts; # eight_byte_float_guts is from src/lib/std/src/eight-byte-float-guts.pkg package uh = host_unt_guts; # host_unt_guts is from src/lib/std/src/bind-sysword-32.pkg package ci = mythryl_callable_c_library_interface; # mythryl_callable_c_library_interface is from src/lib/std/src/unsafe/mythryl-callable-c-library-interface.pkgherein
# This package gets 'include'-ed in
#
# src/lib/std/src/posix-1003.1b/posix-1003-1b.pkg #
package posix_id {
#
package fs = posix_file; # posix_file is from src/lib/std/src/posix-1003.1b/posix-file.pkg package p = posix_process; # posix_process is from src/lib/std/src/posix-1003.1b/posix-process.pkg fun cfun fun_name
=
ci::find_c_function { lib_name => "posix_process_environment", fun_name };
Process_Id = p::Process_Id;
User_Id = fs::User_Id;
Group_Id = fs::Group_Id;
File_Descriptor = fs::File_Descriptor;
Sy_Int = host_int::Int;
fun uid_to_unt i = i;
fun unt_to_uid i = i;
fun gid_to_unt i = i;
fun unt_to_gid i = i;
my get_process_id : Void -> Sy_Int = cfun "getpid"; # getpid def in src/c/lib/posix-process-environment/getpid.c
my get_parent_process_id : Void -> Sy_Int = cfun "getppid"; # getppid def in src/c/lib/posix-process-environment/getppid.c
fun get_process_id' () = p::PID (get_process_id ());
fun get_parent_process_id' () = p::PID (get_parent_process_id ());
my get_user_id: Void -> host_int::Int = cfun "getuid"; # getuid def in src/c/lib/posix-process-environment/getuid.c
my get_effective_user_id: Void -> host_int::Int = cfun "geteuid"; # geteuid def in src/c/lib/posix-process-environment/geteuid.c
my get_group_id : Void -> host_int::Int = cfun "getgid"; # getgid def in src/c/lib/posix-process-environment/getgid.c
my get_effective_group_id : Void -> host_int::Int = cfun "getegid"; # getegid def in src/c/lib/posix-process-environment/getegid.c
fun get_user_id' () = (uh::from_int (get_user_id ()));
fun get_effective_user_id' () = (uh::from_int (get_effective_user_id ()));
fun get_group_id' () = (uh::from_int (get_group_id ()));
fun get_effective_group_id' () = (uh::from_int (get_effective_group_id ()));
my set_user_id : host_int::Int -> Void = cfun "setuid"; # setuid def in src/c/lib/posix-process-environment/setuid.c
my set_group_id : host_int::Int -> Void = cfun "setgid"; # setgid def in src/c/lib/posix-process-environment/setgid.c
fun set_user_id' uid = set_user_id (uh::to_int uid);
fun set_group_id' gid = set_group_id (uh::to_int gid);
my get_group_ids : Void -> List( host_int::Int ) = cfun "getgroups"; # getgroups def in src/c/lib/posix-process-environment/getgroups.c
#
fun get_group_ids' ()
=
map
uh::from_int
(get_group_ids ());
my get_login: Void -> String = cfun "getlogin"; # getlogin def in src/c/lib/posix-process-environment/getlogin.c
my get_process_group: Void -> Sy_Int = cfun "getpgrp"; # getpgrp def in src/c/lib/posix-process-environment/getpgrp.c
my set_session_id: Void -> Sy_Int = cfun "setsid"; # setsid def in src/c/lib/posix-process-environment/setsid.c
my set_process_group_id: (Sy_Int, Sy_Int) -> Void = cfun "setpgid"; # setpgid def in src/c/lib/posix-process-environment/setpgid.c
#
fun get_process_group' ()
=
p::PID (get_process_group ());
fun set_session_id' ()
=
p::PID (set_session_id ());
fun set_process_group_id'
{ pid: Null_Or( Process_Id ),
pgid: Null_Or( Process_Id )
}
=
set_process_group_id (convert pid, convert pgid)
where
fun convert (THE (p::PID pid)) => pid;
convert NULL => 0;
end;
end;
my uname: Void -> List( (String, String) ) = cfun "uname"; # uname def in src/c/lib/posix-process-environment/uname.c
sysconf = p::sysconf;
my time : Void -> one_word_int::Int = cfun "time"; # time def in src/c/lib/posix-process-environment/time.c
#
time' = time::from_seconds o one_word_int_guts::to_multiword_int o time;
# Times in clock ticks:
my times' : Void -> (one_word_int::Int, one_word_int::Int, one_word_int::Int, one_word_int::Int, one_word_int::Int) = cfun "times"; # times def in src/c/lib/posix-process-environment/times.c
ticks_per_sec
=
int_guts::to_multiword_int (uh::to_int_x (sysconf "CLK_TCK"));
ticks_to_time
=
case (multiword_int_guts::quot_rem (time_guts::fractions_per_second, ticks_per_sec))
#
(factor, 0)
=>
(fn ticks = time::from_fractions (factor * one_word_int_guts::to_multiword_int ticks));
_ =>
(fn ticks = time::from_fractions
(multiword_int_guts::quot (time_guts::fractions_per_second
* one_word_int_guts::to_multiword_int ticks,
ticks_per_sec)));
esac;
fun times ()
=
{ my (e, u, s, cu, cs)
=
times' ();
{ elapsed => ticks_to_time e,
utime => ticks_to_time u,
stime => ticks_to_time s,
cutime => ticks_to_time cu,
cstime => ticks_to_time cs
};
};
my getenv: String -> Null_Or( String ) = cfun "getenv"; # getenv def in src/c/lib/posix-process-environment/getenv.c
my environment: Void -> List( String ) = cfun "environ"; # environ def in src/c/lib/posix-process-environment/environ.c
my ctermid: Void -> String = cfun "ctermid"; # ctermid def in src/c/lib/posix-process-environment/ctermid.c
my ttyname' : Sy_Int -> String = cfun "ttyname"; # ttyname def in src/c/lib/posix-process-environment/ttyname.c
#
fun ttyname fd
=
ttyname' (fs::fd_to_int fd);
my isatty' : Sy_Int -> Bool = cfun "isatty"; # isatty def in src/c/lib/posix-process-environment/isatty.c
#
fun isatty fd
=
isatty' (fs::fd_to_int fd);
}; # package posix_id
end;


