Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / basis-library / system / unix.sml
CommitLineData
7f918cf1
CE
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
12structure Unix: UNIX =
13struct
14
15structure Status = OS_Process.Status
16structure Process = MLtonProcess
17local
18 open Process
19in
20 structure Child = Child
21 structure Param = Param
22end
23
24type signal = Posix.Signal.signal
25datatype exit_status = datatype Posix.Process.exit_status
26
27val fromStatus = Posix.Process.fromStatus
28
29type ('in, 'out) proc = ('out, 'in, Process.none) Process.t
30
31local
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}
39in
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}
44end
45
46fun binInstreamOf proc = Child.binIn (Process.getStdout proc)
47fun binOutstreamOf proc = Child.binOut (Process.getStdin proc)
48fun textInstreamOf proc = Child.textIn (Process.getStdout proc)
49fun textOutstreamOf proc = Child.textOut (Process.getStdin proc)
50
51fun streamsOf pr = (textInstreamOf pr, textOutstreamOf pr)
52
53val kill = Process.kill
54
55fun reap z = Status.fromPosix (Process.reap z)
56
57fun exit (w: Word8.word): 'a =
58 OS.Process.exit (Status.fromInt (Word8.toInt w))
59
60end