Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/branches/primop-branch/src/system/Basis/Implementation/Posix/posix-procenv.sml
ViewVC logotype

Annotation of /sml/branches/primop-branch/src/system/Basis/Implementation/Posix/posix-procenv.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1471 - (view) (download)

1 : monnier 416 (* posix-procenv.sml
2 :     *
3 :     * COPYRIGHT (c) 1995 AT&T Bell Laboratories.
4 :     *
5 :     * Signature for POSIX 1003.1 process environment submodule
6 :     *
7 :     *)
8 :    
9 :     local
10 :     structure Time = TimeImp
11 :     structure Real = RealImp
12 :     structure SysWord = SysWordImp
13 :     in
14 :     structure POSIX_ProcEnv =
15 :     struct
16 :    
17 :     structure FS = POSIX_FileSys
18 :     structure P = POSIX_Process
19 :    
20 :     fun cfun x = CInterface.c_function "POSIX-ProcEnv" x
21 :    
22 :     type pid = P.pid
23 :     type uid = FS.uid
24 :     type gid = FS.gid
25 :     type file_desc = FS.file_desc
26 :    
27 :     type s_int = SysInt.int
28 :    
29 :     fun uidToWord (FS.UID i) = i
30 :     fun wordToUid i = FS.UID i
31 :    
32 :     fun gidToWord (FS.GID i) = i
33 :     fun wordToGid i = FS.GID i
34 :    
35 :     val getpid' : unit -> s_int = cfun "getpid"
36 :     val getppid' : unit -> s_int = cfun "getppid"
37 :     fun getpid () = P.PID(getpid' ())
38 :     fun getppid () = P.PID(getppid' ())
39 :    
40 :     val getuid' : unit -> SysWord.word = cfun "getuid"
41 :     val geteuid' : unit -> SysWord.word = cfun "geteuid"
42 :     val getgid' : unit -> SysWord.word = cfun "getgid"
43 :     val getegid' : unit -> SysWord.word = cfun "getegid"
44 :     fun getuid () = FS.UID(getuid' ())
45 :     fun geteuid () = FS.UID(geteuid' ())
46 :     fun getgid () = FS.GID(getgid' ())
47 :     fun getegid () = FS.GID(getegid' ())
48 :    
49 :     val setuid' : SysWord.word -> unit = cfun "setuid"
50 :     val setgid' : SysWord.word -> unit = cfun "setgid"
51 :     fun setuid (FS.UID uid) = setuid' uid
52 :     fun setgid (FS.GID gid) = setgid' gid
53 :    
54 :     val getgroups' : unit -> SysWord.word list = cfun "getgroups"
55 :     fun getgroups () = List.map FS.GID (getgroups'())
56 :    
57 :     val getlogin : unit -> string = cfun "getlogin"
58 :    
59 :     val getpgrp' : unit -> s_int = cfun "getpgrp"
60 :     val setsid' : unit -> s_int = cfun "setsid"
61 :     val setpgid' : s_int * s_int -> unit = cfun "setpgid"
62 :     fun getpgrp () = P.PID(getpgrp' ())
63 :     fun setsid () = P.PID(setsid' ())
64 :     fun setpgid {pid : pid option, pgid : pid option} = let
65 :     fun cvt NONE = 0
66 :     | cvt (SOME(P.PID pid)) = pid
67 :     in
68 :     setpgid'(cvt pid, cvt pgid)
69 :     end
70 :    
71 :     val uname : unit -> (string * string) list = cfun "uname"
72 :    
73 :     val sysconf = P.sysconf
74 :    
75 :     val time' : unit -> Int32.int = cfun "time"
76 : mblume 1347 val time = Time.fromSeconds o Int32Imp.toLarge o time'
77 : monnier 416
78 :     (* times in clock ticks *)
79 :     val times' : unit -> Int32.int * Int32.int * Int32.int * Int32.int * Int32.int
80 :     = cfun "times"
81 : mblume 1368
82 :     val ticksPerSec = IntImp.toLarge (SysWord.toIntX (sysconf "CLK_TCK"))
83 :    
84 :     val ticksToTime =
85 : macqueen 1471 case IntInfImp.quotRem (TimeImp.fractionsPerSecond, ticksPerSec) of
86 : mblume 1368 (factor, 0) =>
87 : macqueen 1471 (fn ticks => Time.fromFractions
88 : mblume 1368 (factor * Int32Imp.toLarge ticks))
89 : macqueen 1471 | _ =>
90 : mblume 1368 (fn ticks =>
91 : macqueen 1471 Time.fromFractions
92 :     (IntInfImp.quot (TimeImp.fractionsPerSecond
93 :     * Int32Imp.toLarge ticks,
94 : mblume 1368 ticksPerSec)))
95 :    
96 : monnier 416 fun times () = let
97 : mblume 1368 val (e,u,s,cu,cs) = times' ()
98 :     in
99 :     { elapsed = ticksToTime e,
100 :     utime = ticksToTime u,
101 :     stime = ticksToTime s,
102 :     cutime = ticksToTime cu,
103 :     cstime = ticksToTime cs }
104 :     end
105 : monnier 416
106 :     val getenv : string -> string option = cfun "getenv"
107 :     val environ : unit -> string list = cfun "environ"
108 :    
109 :     val ctermid : unit -> string = cfun "ctermid"
110 :    
111 :     val ttyname' : s_int -> string = cfun "ttyname"
112 :     fun ttyname fd = ttyname' (FS.intOf fd)
113 :    
114 :     val isatty' : s_int -> bool = cfun "isatty"
115 :     fun isatty fd = isatty' (FS.intOf fd)
116 :    
117 :     end (* structure POSIX_Proc_Env *)
118 :     end
119 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0