Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / basis-library / system / unix.sml
1 (* Copyright (C) 2004-2006 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 *
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
6 *)
7
8 (* Rewritten by wesley@terpstra.ca on 2004-11-23 to use MLtonProcess for the
9 * implementation.
10 *)
11
12 structure Unix: UNIX =
13 struct
14
15 structure Status = OS_Process.Status
16 structure Process = MLtonProcess
17 local
18 open Process
19 in
20 structure Child = Child
21 structure Param = Param
22 end
23
24 type signal = Posix.Signal.signal
25 datatype exit_status = datatype Posix.Process.exit_status
26
27 val fromStatus = Posix.Process.fromStatus
28
29 type ('in, 'out) proc = ('out, 'in, Process.none) Process.t
30
31 local
32 fun create {args, env, path} =
33 Process.create {args = args,
34 env = env,
35 path = path,
36 stderr = Param.self,
37 stdin = Param.pipe,
38 stdout = Param.pipe}
39 in
40 fun execute (path, args) =
41 create {args = args, env = NONE, path = path}
42 fun executeInEnv (path, args, env) =
43 create {args = args, env = SOME env, path = path}
44 end
45
46 fun binInstreamOf proc = Child.binIn (Process.getStdout proc)
47 fun binOutstreamOf proc = Child.binOut (Process.getStdin proc)
48 fun textInstreamOf proc = Child.textIn (Process.getStdout proc)
49 fun textOutstreamOf proc = Child.textOut (Process.getStdin proc)
50
51 fun streamsOf pr = (textInstreamOf pr, textOutstreamOf pr)
52
53 val kill = Process.kill
54
55 fun reap z = Status.fromPosix (Process.reap z)
56
57 fun exit (w: Word8.word): 'a =
58 OS.Process.exit (Status.fromInt (Word8.toInt w))
59
60 end