mkstemp
Stephen Weeks
MLton@sourcelight.com
Thu, 21 Jun 2001 12:33:42 -0700
I propose adding the following to MLton's basis. Comments?
val MLton.TextIO.mkstemp: string -> string * TextIO.outstream
Here is the implementation (within the context of the basis library
implementation).
val mkstemp = _ffi "mkstemp": char array -> int;
val mkstemp: string -> string * outstream =
fn s =>
let
val s = String.concat [s, "XXXXXX\000"]
val n = String.size s
val a = Array.tabulate (n, fn i => String.sub (s, i))
val fd = mkstemp a
val _ = PosixError.checkResult fd
val name = String.tabulate (n - 1, fn i => Array.sub (a, i))
in
(name, newOut (PosixPrimitive.FD fd))
end