## posix-id.pkg
#
# API for POSIX 1003.1 process dictionary submodule
# Compiled by:
#
src/lib/std/src/standard-core.sublibstipulate
package ci = mythryl_callable_c_library_interface; # mythryl_callable_c_library_interface is from
src/lib/std/src/unsafe/mythryl-callable-c-library-interface.pkg# package f8b = eight_byte_float_guts; # eight_byte_float_guts is from
src/lib/std/src/eight-byte-float-guts.pkg package hi = host_int; # host_int is from
src/lib/std/src/psx/host-int.pkg package hug = host_unt_guts; # host_unt_guts is from
src/lib/std/src/bind-sysword-32.pkg package i1w = one_word_int; # one_word_int is from
src/lib/std/types-only/basis-structs.pkg package ig = int_guts; # int_guts is from
src/lib/std/src/int-guts.pkg package iwg = one_word_int_guts; # one_word_int_guts is from
src/lib/std/src/one-word-int-guts.pkg package mig = multiword_int_guts; # multiword_int_guts is from
src/lib/std/src/multiword-int-guts.pkg package pf = posix_file; # posix_file is from
src/lib/std/src/psx/posix-file.pkg package pp = posix_process; # posix_process is from
src/lib/std/src/psx/posix-process.pkg package tg = time_guts; # time_guts is from
src/lib/std/src/time-guts.pkg #
fun cfun fun_name
=
ci::find_c_function'' { lib_name => "posix_process_environment", fun_name };
herein
# This package gets 'include'-ed in
#
#
src/lib/std/src/psx/posixlib.pkg #
package posix_id { # Posix_Id is from
src/lib/std/src/psx/posix-id.api #
Process_Id = pp::Process_Id;
User_Id = pf::User_Id;
Group_Id = pf::Group_Id;
File_Descriptor = pf::File_Descriptor;
Sy_Int = hi::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;
(cfun "getpid") # getpid def in src/c/lib/posix-process-environment/getpid.c
->
( get_process_id__syscall: Void -> Sy_Int,
get_process_id__ref,
set__get_process_id__ref
);
fun get_process_id ()
=
*get_process_id__ref ();
(cfun "getppid") # getppid def in src/c/lib/posix-process-environment/getppid.c
->
( get_parent_process_id__syscall: Void -> Sy_Int,
get_parent_process_id__ref,
set__get_parent_process_id__ref
);
fun get_parent_process_id ()
=
*get_parent_process_id__ref ();
fun get_process_id' () = pp::PID (get_process_id ());
fun get_parent_process_id' () = pp::PID (get_parent_process_id ());
(cfun "getuid") # getuid def in src/c/lib/posix-process-environment/getuid.c
->
( get_user_id__syscall: Void -> hi::Int,
get_user_id__ref,
set__get_user_id__ref
);
fun get_user_id ()
=
*get_user_id__ref ();
(cfun "geteuid") # geteuid def in src/c/lib/posix-process-environment/geteuid.c
->
( get_effective_user_id__syscall: Void -> hi::Int,
get_effective_user_id__ref,
set__get_effective_user_id__ref
);
fun get_effective_user_id ()
=
*get_effective_user_id__ref ();
(cfun "getgid") # getgid def in src/c/lib/posix-process-environment/getgid.c
->
( get_group_id__syscall: Void -> hi::Int,
get_group_id__ref,
set__get_group_id__ref
);
fun get_group_id ()
=
*get_group_id__ref ();
(cfun "getegid") # getegid def in src/c/lib/posix-process-environment/getegid.c
->
( get_effective_group_id__syscall: Void -> hi::Int,
get_effective_group_id__ref,
set__get_effective_group_id__ref
);
fun get_effective_group_id ()
=
*get_effective_group_id__ref ();
fun get_user_id' () = (hug::from_int (get_user_id ()));
fun get_effective_user_id' () = (hug::from_int (get_effective_user_id ()));
fun get_group_id' () = (hug::from_int (get_group_id ()));
fun get_effective_group_id' () = (hug::from_int (get_effective_group_id ()));
(cfun "setuid") # setuid def in src/c/lib/posix-process-environment/setuid.c
->
( set_user_id__syscall: hi::Int -> Void,
set_user_id__ref,
set__set_user_id__ref
);
fun set_user_id id
=
*set_user_id__ref id;
(cfun "setgid") # setgid def in src/c/lib/posix-process-environment/setgid.c
->
( set_group_id__syscall: hi::Int -> Void,
set_group_id__ref,
set__set_group_id__ref
);
fun set_group_id id
=
*set_group_id__ref id;
fun set_user_id' uid = set_user_id (hug::to_int uid);
fun set_group_id' gid = set_group_id (hug::to_int gid);
(cfun "getgroups") # getgroups def in src/c/lib/posix-process-environment/getgroups.c
->
( get_group_ids__syscall: Void -> List( hi::Int ),
get_group_ids__ref,
set__get_group_ids__ref
);
fun get_group_ids ()
=
*get_group_ids__ref ();
#
fun get_group_ids' ()
=
map
hug::from_int
(get_group_ids ());
(cfun "getlogin") # getlogin def in src/c/lib/posix-process-environment/getlogin.c
->
( get_login__syscall: Void -> String,
get_login__ref,
set__get_login__ref
);
fun get_login ()
=
*get_login__ref ();
(cfun "getpgrp") # getpgrp def in src/c/lib/posix-process-environment/getpgrp.c
->
( get_process_group__syscall: Void -> Sy_Int,
get_process_group__ref,
set__get_process_group__ref
);
fun get_process_group ()
=
*get_process_group__ref ();
(cfun "setsid") # setsid def in src/c/lib/posix-process-environment/setsid.c
->
( set_session_id__syscall: Void -> Sy_Int, # Yes, set_session_id really is Void -> Sy_Int. Maybe it should be called start_new_session().
set_session_id__ref,
set__set_session_id__ref
);
fun set_session_id ()
=
*set_session_id__ref ();
(cfun "setpgid") # setpgid def in src/c/lib/posix-process-environment/setpgid.c
->
( set_process_group_id__syscall: (Sy_Int, Sy_Int) -> Void,
set_process_group_id__ref,
set__set_process_group_id__ref
);
fun set_process_group_id args
=
*set_process_group_id__ref args;
#
fun get_process_group' ()
=
pp::PID (get_process_group ());
fun set_session_id' ()
=
pp::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 (pp::PID pid)) => pid;
convert NULL => 0;
end;
end;
(cfun "uname") # uname def in src/c/lib/posix-process-environment/uname.c
-> # "uname" derives from something like "get name of unix system".
( get_kernel_info__syscall: Void -> List( (String, String) ),
get_kernel_info__ref,
set__get_kernel_info__ref
);
fun get_kernel_info ()
=
*get_kernel_info__ref ();
sysconf = pp::sysconf;
(cfun "time") # time def in src/c/lib/posix-process-environment/time.c
-> # Return time expressed as elapsed seconds since 1970-01-01 00:00:00 +0000 (UTC).
( get_elapsed_seconds_since_1970__syscall: Void -> i1w::Int,
get_elapsed_seconds_since_1970__ref,
set__get_elapsed_seconds_since_1970__ref
);
fun get_elapsed_seconds_since_1970 ()
=
*get_elapsed_seconds_since_1970__ref ();
#
get_elapsed_seconds_since_1970'
= tg::from_seconds
o iwg::to_multiword_int
o get_elapsed_seconds_since_1970;
# Times in clock ticks:
(cfun "times") # times def in src/c/lib/posix-process-environment/times.c
->
( times__syscall: Void -> (i1w::Int, i1w::Int, i1w::Int, i1w::Int, i1w::Int),
times__ref,
set__times__ref
);
fun times ()
=
*times__ref ();
ticks_per_sec
=
ig::to_multiword_int (hug::to_int_x (sysconf "CLK_TCK"));
ticks_to_time
=
case (mig::quot_rem (tg::fractions_per_second, ticks_per_sec))
#
(factor, 0)
=>
(\\ ticks = tg::from_fractions (factor * iwg::to_multiword_int ticks));
_ =>
(\\ ticks = tg::from_fractions
(mig::quot (tg::fractions_per_second
* iwg::to_multiword_int ticks,
ticks_per_sec)));
esac;
fun times ()
=
{ (*times__ref ())
->
(e, u, s, cu, cs);
{ 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
};
};
(cfun "getenv") # getenv def in src/c/lib/posix-process-environment/getenv.c
->
( getenv__syscall: String -> Null_Or( String ),
getenv__ref,
set__getenv__ref
);
fun getenv key
=
*getenv__ref key;
(cfun "environ") # environ def in src/c/lib/posix-process-environment/environ.c
->
( environment__syscall: Void -> List(String),
environment__ref,
set__environment__ref
);
fun environment ()
=
*environment__ref ();
(cfun "ctermid") # ctermid def in src/c/lib/posix-process-environment/ctermid.c
-> # "ctermid" is probably "controlling terminal id"
( get_name_of_controlling_terminal__syscall: Void -> String,
get_name_of_controlling_terminal__ref,
set__get_name_of_controlling_terminal__ref
);
fun get_name_of_controlling_terminal ()
=
*get_name_of_controlling_terminal__ref ();
(cfun "ttyname") # ttyname def in src/c/lib/posix-process-environment/ttyname.c
-> # "tty" is "teletype", once upon a time synonymous with "terminal".
( get_name_of_terminal__syscall: Sy_Int -> String,
get_name_of_terminal__ref,
set__get_name_of_terminal__ref
);
#
fun get_name_of_terminal fd
=
*get_name_of_terminal__ref (pf::fd_to_int fd);
(cfun "isatty") # isatty def in src/c/lib/posix-process-environment/isatty.c
-> # "isatty" == "is a teletype" -- in practice, "is a live user" (vs a file or socket or such).
( is_a_terminal__syscall: Sy_Int -> Bool,
is_a_terminal__ref,
set__is_a_terminal__ref
);
#
fun is_a_terminal fd
=
*is_a_terminal__ref (pf::fd_to_int fd);
}; # package posix_id
end;