[MLton-commit] r4328

Matthew Fluet MLton@mlton.org
Sun, 29 Jan 2006 13:06:46 -0800


Continue re-integration of generated ML-side basis library imports. Eliminated PosixPrimitive.
----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/basis-library/io/bin-io.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/io/text-io.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/misc/basic.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/exit.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/proc-env.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sig
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/syslog.sig
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/syslog.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/world.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/net/socket.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/file-sys.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/io.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/proc-env.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/process.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/stub-mingw.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/sys-db.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/tty.sml
D   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/posix-primitive.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/primitive.mlb
U   mlton/branches/on-20050822-x86_64-branch/basis-library/system/io.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/system/pre-os.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/system/process.sml
U   mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/FLock-consts.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/fcntl-consts.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/pipe.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/Posix/ProcEnv/getgroups.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/Posix/TTY.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def
U   mlton/branches/on-20050822-x86_64-branch/runtime/platform/linux.c

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/io/bin-io.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/io/bin-io.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/io/bin-io.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -13,7 +13,7 @@
     structure Vector = Word8Vector
     structure VectorSlice = Word8VectorSlice
     val chunkSize = Primitive.TextIO.bufSize
-    val fileTypeFlags = [PosixPrimitive.FileSys.O.binary]
+    val fileTypeFlags = [SysWord.fromInt PrimitiveFFI.Posix.FileSys.O.BINARY]
     val line = NONE
     val mkReader = Posix.IO.mkBinReader
     val mkWriter = Posix.IO.mkBinWriter

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/io/text-io.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/io/text-io.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/io/text-io.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -16,7 +16,7 @@
           structure Vector = CharVector
           structure VectorSlice = CharVectorSlice
           val chunkSize = Primitive.TextIO.bufSize
-          val fileTypeFlags = [PosixPrimitive.FileSys.O.text]
+          val fileTypeFlags = [SysWord.fromInt PrimitiveFFI.Posix.FileSys.O.TEXT]
           val line = SOME {isLine = fn c => c = #"\n",
                            lineElem = #"\n"}
           val mkReader = Posix.IO.mkTextReader

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/misc/basic.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/misc/basic.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/misc/basic.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -20,7 +20,7 @@
 
 fun die (s: string): 'a =
    (Primitive.Stdio.print s
-    ; PosixPrimitive.Process.exit 1
+    ; PrimitiveFFI.Posix.Process.exit 1
     ; let exception DieFailed
       in raise DieFailed
       end)

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/exit.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/exit.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/exit.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -7,7 +7,14 @@
 
 structure Exit =
    struct
-      structure Status = PosixPrimitive.Process.Status
+      structure Status = 
+         struct
+            type t = C.Status.t
+            val fromInt =C.Status.fromInt
+            val toInt = C.Status.toInt
+            val failure = fromInt 1
+            val success = fromInt 0
+         end
 
       val exiting = ref false
 

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/proc-env.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/proc-env.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/proc-env.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -8,7 +8,7 @@
 
 structure MLtonProcEnv: MLTON_PROC_ENV =
    struct
-      type gid = PosixPrimitive.ProcEnv.gid
+      type gid = C.GId.t
 
       fun setenv {name, value} =
          let
@@ -16,10 +16,15 @@
             val value = NullString.nullTerm value
          in
             PosixError.SysCall.simple
-            (fn () => PosixPrimitive.ProcEnv.setenv (name, value))
+            (fn () => PrimitiveFFI.Posix.ProcEnv.setenv (name, value))
          end
 
       fun setgroups gs =
-         PosixError.SysCall.simple
-         (fn () => PosixPrimitive.ProcEnv.setgroups (Array.fromList gs))
+         let
+            val v = Vector.fromList gs
+            val n = Vector.length v
+         in
+            PosixError.SysCall.simple
+            (fn () => PrimitiveFFI.Posix.ProcEnv.setgroups (n, v))
+         end
    end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sig
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sig	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sig	2006-01-29 21:06:37 UTC (rev 4328)
@@ -21,7 +21,8 @@
       val numFiles: t            (* NOFILE  max number of open files *)  
       val stackSize: t           (* STACK   max stack size *)
       val virtualMemorySize: t   (* AS      virtual memory limit *)
-(*
+
+(* NOT STANDARD
       val lockedInMemorySize: t  (* MEMLOCK max locked address space *)
       val numProcesses: t        (* NPROC   max number of processes *)
       val residentSetSize: t     (* RSS     max resident set size *)

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -35,7 +35,7 @@
       val stackSize = STACK
       val virtualMemorySize = AS
 
-(*
+(* NOT STANDARD
       val lockedInMemorySize = MEMLOCK
       val numProcesses = NPROC
       val residentSetSize = RSS

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/syslog.sig
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/syslog.sig	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/syslog.sig	2006-01-29 21:06:37 UTC (rev 4328)
@@ -22,7 +22,7 @@
       val NDELAY   : openflag
       val NOWAIT   : openflag
       val ODELAY   : openflag
-(*
+(* NOT STANDARD
       val PERROR   : openflag
 *)
       val PID      : openflag
@@ -44,7 +44,7 @@
       val LPR      : facility
       val MAIL     : facility
       val NEWS     : facility
-(*
+(* NOT STANDARD
       val SYSLOG   : facility
 *)
       val USER     : facility

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/syslog.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/syslog.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/syslog.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -48,7 +48,7 @@
    val LPR = LOG_LPR
    val MAIL = LOG_MAIL
    val NEWS = LOG_NEWS
-(*
+(* NOT STANDARD
    val SYSLOG = LOG_SYSLOG
 *)
    val USER = LOG_USER

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/world.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/world.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/world.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -25,7 +25,7 @@
                   open Posix.FileSys
                   val flags =
                      O.flags [O.trunc,
-                              PosixPrimitive.FileSys.O.binary]
+                              SysWord.fromInt PrimitiveFFI.Posix.FileSys.O.BINARY]
                   val mode =
                      let
                         open S

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/net/socket.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/net/socket.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/net/socket.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -267,11 +267,11 @@
    nonBlock' ({restart = true}, f, post, Error.again, no)
 
 local
-   structure PIO = PosixPrimitive.IO
+   structure PIO = PrimitiveFFI.Posix.IO
 in
    fun withNonBlock (s, f: unit -> 'a) =
       let
-         val fd = PosixPrimitive.FileDesc.fromInt (Prim.toInt s)
+         val fd = Primitive.FileDesc.fromInt (Prim.toInt s)
          val flags = 
             Syscall.simpleResultRestart (fn () => PIO.fcntl2 (fd, PIO.F_GETFL))
          val _ =
@@ -280,7 +280,7 @@
              PIO.fcntl3 (fd, PIO.F_SETFL,
                          Word.toIntX
                          (Word.orb (Word.fromInt flags,
-                                    PosixPrimitive.FileSys.O.nonblock))))
+                                    SysWord.fromInt PrimitiveFFI.Posix.FileSys.O.NONBLOCK))))
       in
          DynamicWind.wind
          (f, fn () =>

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/file-sys.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/file-sys.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/file-sys.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -25,17 +25,17 @@
          end
       
       structure SysCall = Error.SysCall
-      structure Prim = PosixPrimitive.FileSys
+      structure Prim = PrimitiveFFI.Posix.FileSys
       open Prim
       structure Stat = Prim.Stat
       structure Flags = BitFlags
 
-      type file_desc = Prim.file_desc
-      type uid = Prim.uid
-      type gid = Prim.gid
+      type file_desc = C.Fd.t
+      type uid = C.UId.t
+      type gid = C.GId.t
 
-      val fdToWord = PosixPrimitive.FileDesc.toWord
-      val wordToFD = PosixPrimitive.FileDesc.fromWord
+      val fdToWord = Primitive.FileDesc.toWord
+      val wordToFD = Primitive.FileDesc.fromWord
       val fdToIOD = OS.IO.fromFD
       val iodToFD = SOME o OS.IO.toFD
 
@@ -45,7 +45,7 @@
 
       local
          structure Prim = Prim.Dirstream
-         datatype dirstream = DS of Prim.dirstream option ref
+         datatype dirstream = DS of C.DirP.t option ref
 
          fun get (DS r) =
             case !r of
@@ -61,9 +61,10 @@
                SysCall.syscall
                (fn () =>
                 let
-                   val d = Prim.opendir s
+                   val d = Prim.openDir s
+                   val p = Primitive.Pointer.fromWord d
                 in
-                   (if Primitive.Pointer.isNull d then ~1 else 0,
+                   (if Primitive.Pointer.isNull p then ~1 else 0,
                     fn () => DS (ref (SOME d)))
                 end)
             end
@@ -78,7 +79,7 @@
                         ({clear = true, restart = false},
                          fn () =>
                          let
-                            val cs = Prim.readdir d
+                            val cs = Prim.readDir d
                          in
                             {return = if Primitive.Pointer.isNull cs
                                          then ~1
@@ -111,7 +112,7 @@
                SysCall.syscallErr
                ({clear = true, restart = false},
                 fn () =>
-                let val () = Prim.rewinddir d
+                let val () = Prim.rewindDir d
                 in
                    {return = ~1,
                     post = fn () => (),
@@ -122,7 +123,7 @@
          fun closedir (DS r) =
             case !r of
                NONE => ()
-             | SOME d => (SysCall.simple (fn () => Prim.closedir d); r := NONE)
+             | SOME d => (SysCall.simple (fn () => Prim.closeDir d); r := NONE)
       end
          
       fun chdir s =
@@ -150,14 +151,14 @@
          fun extract a = extractToChar (a, #"\000")
       in
          fun getcwd () =
-            if Primitive.Pointer.isNull (Prim.getcwd (!buffer, !size))
+            if Primitive.Pointer.isNull (Prim.getcwd (!buffer, C.Size.fromInt (!size)))
                then (size := 2 * !size
                      ; buffer := make ()
                      ; getcwd ())
             else extract (!buffer)
       end
 
-      val FD = PosixPrimitive.FileDesc.fromInt
+      val FD = Primitive.FileDesc.fromInt
 
       val stdin = FD 0
       val stdout = FD 1
@@ -166,25 +167,63 @@
       structure S =
          struct
             open S Flags
+            type mode = C.Mode.t
+            val ifblk = IFBLK
+            val ifchr = IFCHR
+            val ifdir = IFDIR
+            val ififo = IFIFO
+            val iflnk = IFLNK
+            val ifmt = IFMT
+            val ifreg = IFREG
+            val ifsock = IFSOCK
+            val irgrp = IRGRP
+            val iroth = IROTH
+            val irusr = IRUSR
+            val irwxg = IRWXG
+            val irwxo = IRWXO
+            val irwxu = IRWXU
+            val isgid = ISGID
+            val isuid = ISUID
+            val isvtx = ISVTX
+            val iwgrp = IWGRP
+            val iwoth = IWOTH
+            val iwusr = IWUSR
+            val ixgrp = IXGRP
+            val ixoth = IXOTH
+            val ixusr = IXUSR
          end
 
       structure O =
          struct
             open O Flags
+            val append = SysWord.fromInt APPEND
+            val binary = SysWord.fromInt BINARY
+            val creat = SysWord.fromInt CREAT
+            val dsync = SysWord.fromInt DSYNC
+            val excl = SysWord.fromInt EXCL
+            val noctty = SysWord.fromInt NOCTTY
+            val nonblock = SysWord.fromInt NONBLOCK
+            val rdonly = SysWord.fromInt RDONLY
+            val rdwr = SysWord.fromInt RDWR
+            val rsync = SysWord.fromInt RSYNC
+            val sync = SysWord.fromInt SYNC
+            val text = SysWord.fromInt TEXT
+            val trunc = SysWord.fromInt TRUNC
+            val wronly = SysWord.fromInt WRONLY
          end
 
       datatype open_mode = O_RDONLY | O_WRONLY | O_RDWR
 
       fun wordToOpenMode w =
-         if w = o_rdonly then O_RDONLY
-         else if w = o_wronly then O_WRONLY
-              else if w = o_rdwr then O_RDWR
+         if w = O.rdonly then O_RDONLY
+         else if w = O.wronly then O_WRONLY
+              else if w = O.rdwr then O_RDWR
                    else raise Fail "wordToOpenMode: unknown word"
                       
       val openModeToWord =
-         fn O_RDONLY => o_rdonly
-          | O_WRONLY => o_wronly
-          | O_RDWR => o_rdwr
+         fn O_RDONLY => O.rdonly
+          | O_WRONLY => O.wronly
+          | O_RDWR => O.rdwr
 
       fun createf (pathname, openMode, flags, mode) =
          let
@@ -194,7 +233,7 @@
                                      O.creat]
             val fd =
                SysCall.simpleResult
-               (fn () => Prim.openn (pathname, flags, mode))
+               (fn () => Prim.open3 (pathname, SysWord.toInt flags, mode))
          in
             FD fd
          end
@@ -205,7 +244,7 @@
             val flags = Flags.flags [openModeToWord openMode, flags]
             val fd = 
                SysCall.simpleResult
-               (fn () => Prim.openn (pathname, flags, Flags.empty))
+               (fn () => Prim.open3 (pathname, SysWord.toInt flags, Flags.empty))
          in FD fd
          end
          
@@ -238,7 +277,7 @@
 
       local
          val size: int = 1024
-         val buf = Word8Array.array (size, 0w0)
+         val buf : char array = Array.array (size, #"\000")
       in
          fun readlink (path: string): string =
             let 
@@ -246,22 +285,21 @@
             in
                SysCall.syscall
                (fn () =>
-                let val len = Prim.readlink (path, Word8Array.toPoly buf, size)
+                let val len = Prim.readlink (path, buf, C.Size.fromInt size)
                 in
                    (len, fn () =>
-                    Byte.unpackString (Word8ArraySlice.slice (buf, 0, SOME len)))
+                    ArraySlice.vector (ArraySlice.slice (buf, 0, SOME len)))
                 end)
             end
       end
 
-      type dev = Prim.dev
-      val id = fn x => x
-      val wordToDev = id
-      val devToWord = id
+      type dev = C.Dev.t
+      val wordToDev = C.Dev.fromLargeWord o SysWord.toLargeWord
+      val devToWord = SysWord.fromLargeWord o C.Dev.toLargeWord
 
-      type ino = Prim.ino
-      val wordToIno = SysWord.toInt
-      val inoToWord = SysWord.fromInt
+      type ino = C.INo.t
+      val wordToIno = C.INo.fromLargeWord o SysWord.toLargeWord
+      val inoToWord = SysWord.fromLargeWord o C.INo.toLargeWord
 
       structure ST =
          struct
@@ -278,16 +316,16 @@
                      ctime: Time.time}
 
             fun fromC (): stat =
-               T {dev = Stat.dev (),
-                  ino = Stat.ino (),
-                  mode = Stat.mode (),
-                  nlink = Stat.nlink (),
-                  uid = Stat.uid (),
-                  gid = Stat.gid (),
-                  size = Stat.size (),
-                  atime = Time.fromSeconds (Stat.atime ()),
-                  mtime = Time.fromSeconds (Stat.mtime ()),
-                  ctime = Time.fromSeconds (Stat.ctime ())}
+               T {dev = Stat.getDev (),
+                  ino = Stat.getINo (),
+                  mode = Stat.getMode (),
+                  nlink = C.NLink.toInt (Stat.getNLink ()),
+                  uid = Stat.getUId (),
+                  gid = Stat.getGId (),
+                  size = Stat.getSize (),
+                  atime = Time.fromSeconds (Stat.getATime ()),
+                  mtime = Time.fromSeconds (Stat.getMTime ()),
+                  ctime = Time.fromSeconds (Stat.getCTime ())}
 
             local
                fun make sel (T r) = sel r
@@ -329,13 +367,13 @@
       datatype access_mode = A_READ | A_WRITE | A_EXEC
 
       val conv_access_mode =
-         fn A_READ => R_OK
-          | A_WRITE => W_OK
-          | A_EXEC => X_OK
+         fn A_READ => A.R_OK
+          | A_WRITE => A.W_OK
+          | A_EXEC => A.X_OK
 
       fun access (path: string, mode: access_mode list): bool =
          let 
-            val mode = Flags.flags (F_OK :: (map conv_access_mode mode))
+            val mode = SysWord.toInt (Flags.flags (map SysWord.fromInt (A.F_OK :: (map conv_access_mode mode))))
             val path = NullString.nullTerm path
          in 
             SysCall.syscallErr
@@ -372,14 +410,41 @@
             in 
                SysCall.syscallRestart
                (fn () => 
-                (U.setActime a
-                 ; U.setModtime m
+                (U.setAcTime a
+                 ; U.setModTime m
                  ; (U.utime f, fn () => 
                     ())))
             end
       end
 
       local
+         local
+            open Prim.PC
+         in
+            val properties =
+               [
+                (ALLOC_SIZE_MIN,"ALLOC_SIZE_MIN"),
+                (ASYNC_IO,"ASYNC_IO"),
+                (CHOWN_RESTRICTED,"CHOWN_RESTRICTED"),
+                (FILESIZEBITS,"FILESIZEBITS"),
+                (LINK_MAX,"LINK_MAX"),
+                (MAX_CANON,"MAX_CANON"),
+                (MAX_INPUT,"MAX_INPUT"),
+                (NAME_MAX,"NAME_MAX"),
+                (NO_TRUNC,"NO_TRUNC"),
+                (PATH_MAX,"PATH_MAX"),
+                (PIPE_BUF,"PIPE_BUF"),
+                (PRIO_IO,"PRIO_IO"),
+                (REC_INCR_XFER_SIZE,"REC_INCR_XFER_SIZE"),
+                (REC_MAX_XFER_SIZE,"REC_MAX_XFER_SIZE"),
+                (REC_MIN_XFER_SIZE,"REC_MIN_XFER_SIZE"),
+                (REC_XFER_ALIGN,"REC_XFER_ALIGN"),
+                (SYMLINK_MAX,"SYMLINK_MAX"),
+                (SYNC_IO,"SYNC_IO"),
+                (VDISABLE,"VDISABLE")
+               ]
+         end
+
          fun convertProperty s =
             case List.find (fn (_, s') => s = s') properties of
                NONE => Error.raiseSys Error.inval

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/io.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/io.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/io.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -9,17 +9,17 @@
 structure PosixIO: POSIX_IO =
 struct
 
-structure Prim = PosixPrimitive.IO
+structure Prim = PrimitiveFFI.Posix.IO
 open Prim
 structure Error = PosixError
 structure SysCall = Error.SysCall
 structure FS = PosixFileSys
 
-type file_desc = Prim.file_desc
-type pid = Pid.t
+type file_desc = C.Fd.t
+type pid = C.PId.t
 
-val FD = PosixPrimitive.FileDesc.fromInt
-val unFD = PosixPrimitive.FileDesc.toInt
+val FD = C.Fd.fromInt
+val unFD = C.Fd.toInt
    
 local
    val a: file_desc array = Array.array (2, FD 0)
@@ -41,6 +41,7 @@
 structure FD =
    struct
       open FD BitFlags
+      val cloexec = SysWord.fromInt CLOEXEC
    end
 
 structure O = PosixFileSys.O
@@ -64,8 +65,8 @@
       val n =
          SysCall.simpleResultRestart (fn () => Prim.fcntl2 (fd, F_GETFL))
       val w = Word.fromInt n
-      val flags = Word.andb (w, Word.notb O_ACCMODE)
-      val mode = Word.andb (w, O_ACCMODE)
+      val flags = Word.andb (w, Word.notb (Word.fromInt O_ACCMODE))
+      val mode = Word.andb (w, (Word.fromInt O_ACCMODE))
    in (flags, PosixFileSys.wordToOpenMode mode)
    end
       
@@ -98,27 +99,43 @@
          
 fun fsync fd : unit = SysCall.simple (fn () => Prim.fsync fd)
          
+val whenceToInt =
+   fn SEEK_SET => Prim.FLock.SEEK_SET
+    | SEEK_CUR => Prim.FLock.SEEK_CUR
+    | SEEK_END => Prim.FLock.SEEK_END
+
+fun intToWhence n =
+   if n = Prim.FLock.SEEK_SET
+      then SEEK_SET
+   else if n = Prim.FLock.SEEK_CUR
+           then SEEK_CUR
+        else if n = Prim.FLock.SEEK_END
+                then SEEK_END
+             else raise Fail "Posix.IO.intToWhence"
+
 datatype lock_type =
    F_RDLCK
   | F_WRLCK
   | F_UNLCK
 
 val lockTypeToInt =
-   fn F_RDLCK => Prim.F_RDLCK
-    | F_WRLCK => Prim.F_WRLCK
-    | F_UNLCK => Prim.F_UNLCK
+   fn F_RDLCK => Prim.FLock.F_RDLCK
+    | F_WRLCK => Prim.FLock.F_WRLCK
+    | F_UNLCK => Prim.FLock.F_UNLCK
 
 fun intToLockType n =
-   if n = Prim.F_RDLCK
+   if n = Prim.FLock.F_RDLCK
       then F_RDLCK
-   else if n = Prim.F_WRLCK
+   else if n = Prim.FLock.F_WRLCK
            then F_WRLCK
-        else if n = Prim.F_UNLCK
+        else if n = Prim.FLock.F_UNLCK
                 then F_UNLCK
              else raise Fail "Posix.IO.intToLockType"
          
 structure FLock =
    struct
+      open FLock
+
       type flock = {ltype: lock_type,
                     whence: whence,
                     start: Position.int,
@@ -146,15 +163,15 @@
          ; P.setStart start
          ; P.setLen len
          ; P.fcntl (fd, cmd)), fn () => 
-        {ltype = intToLockType (P.typ ()),
-         whence = intToWhence (P.whence ()),
-         start = P.start (),
-         len = P.len (),
-         pid = if usepid then SOME (P.pid ()) else NONE}))
+        {ltype = intToLockType (P.getType ()),
+         whence = intToWhence (P.getWhence ()),
+         start = P.getStart (),
+         len = P.getLen (),
+         pid = if usepid then SOME (P.getPId ()) else NONE}))
 in
-   val getlk = make (F_GETLK, true)
-   val setlk = make (F_SETLK, false)
-   val setlkw = make (F_SETLKW, false)
+   val getlk = make (FLock.F_GETLK, true)
+   val setlk = make (FLock.F_SETLK, false)
+   val setlkw = make (FLock.F_SETLKW, false)
 end
 
 (* Adapted from SML/NJ sources. *)
@@ -220,13 +237,13 @@
             let
                val (buf, i, sz) = ArraySlice.base (toArraySlice sl)
             in
-               SysCall.simpleResultRestart (fn () => read (fd, buf, i, sz))
+               SysCall.simpleResultRestart (fn () => read (fd, buf, i, C.Size.fromInt sz))
             end
          fun readVec (fd, n) =
             let
                val a = Primitive.Array.array n
                val bytesRead = 
-                  SysCall.simpleResultRestart (fn () => read (fd, a, 0, n))
+                  SysCall.simpleResultRestart (fn () => read (fd, a, 0, C.Size.fromInt n))
             in 
                fromVector
                (if n = bytesRead
@@ -239,7 +256,7 @@
                val (buf, i, sz) = ArraySlice.base (toArraySlice sl)
             in
                SysCall.simpleResultRestart
-               (fn () => write (fd, buf, i, sz))
+               (fn () => write (fd, buf, i, C.Size.fromInt sz))
             end
          val writeVec =
             fn (fd, sl) =>
@@ -247,7 +264,7 @@
                val (buf, i, sz) = VectorSlice.base (toVectorSlice sl)
             in
                SysCall.simpleResultRestart
-               (fn () => writeVec (fd, buf, i, sz))
+               (fn () => writeVec (fd, buf, i, C.Size.fromInt sz))
             end
          fun mkReader {fd, name, initBlkMode} =
             let
@@ -375,19 +392,19 @@
             toArraySlice = Word8ArraySlice.toPoly,
             toVectorSlice = Word8VectorSlice.toPoly,
             vectorLength = Word8Vector.length,
-            write = writeWord8,
+            write = writeWord8Arr,
             writeVec = writeWord8Vec}
    val {mkReader = mkTextReader, mkWriter = mkTextWriter, ...} =
       make {RD = TextPrimIO.RD,
             WR = TextPrimIO.WR,
             fromVector = fn v => v,
-            read = readChar,
+            read = readChar8,
             setMode = Prim.settext,
             toArraySlice = CharArraySlice.toPoly,
             toVectorSlice = CharVectorSlice.toPoly,
             vectorLength = CharVector.length,
-            write = writeChar,
-            writeVec = writeCharVec}
+            write = writeChar8Arr,
+            writeVec = writeChar8Vec}
 end
 
 end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/proc-env.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/proc-env.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/proc-env.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -8,19 +8,19 @@
 
 structure PosixProcEnv: POSIX_PROC_ENV =
    struct
-      structure Prim = PosixPrimitive.ProcEnv
+      structure Prim = PrimitiveFFI.Posix.ProcEnv
       structure Error = PosixError
       structure SysCall = Error.SysCall
       structure CS = COld.CS
 
-      type pid = Pid.t
+      type pid = C.PId.t
+      type uid = C.UId.t
+      type gid = C.GId.t
+      type file_desc = C.Fd.t
          
       local
          open Prim
       in
-         type uid = uid
-         type gid = gid
-         datatype file_desc = datatype file_desc
          val getpgrp = getpgrp (* No error checking required *)
          val getegid = getegid (* No error checking required *)
          val geteuid = geteuid (* No error checking required *)
@@ -32,8 +32,7 @@
          val setuid = fn uid => SysCall.simple (fn () => setuid uid)
       end
 
-      fun setsid () = 
-         Pid.fromInt (SysCall.simpleResult (Pid.toInt o Prim.setsid))
+      fun setsid () = SysCall.simpleResult (Prim.setsid)
 
       fun id x = x
       val uidToWord = id 
@@ -42,12 +41,13 @@
       val wordToGid = id
 
       local
-         val a: word array = Primitive.Array.array Prim.numgroups
+         val n = Prim.getgroupsN ()
+         val a: word array = Primitive.Array.array n
       in
          fun getgroups () =
             SysCall.syscall
             (fn () =>
-             let val n = Prim.getgroups a
+             let val n = Prim.getgroups (n, a)
              in (n, fn () => 
                  ArraySlice.toList (ArraySlice.slice (a, 0, SOME n)))
              end)
@@ -62,47 +62,169 @@
 
       fun setpgid {pid, pgid} =
          let
-            val f =
-               fn NONE => Pid.fromInt 0
-                | SOME pid => pid
-            val pid = f pid
-            val pgid = f pgid
+            val pid = case pid of NONE => 0 | SOME pid => pid
+            val pgid = case pgid of NONE => 0 | SOME pgid => pgid
          in
             SysCall.simple
             (fn () => Prim.setpgid (pid, pgid))
          end
 
+      fun uname () =
+         SysCall.syscall
+         (fn () =>
+          (Prim.uname (), fn () =>
+           [("sysname", CS.toString (Prim.Uname.getSysName ())),
+            ("nodename", CS.toString (Prim.Uname.getNodeName ())),
+            ("release", CS.toString (Prim.Uname.getRelease ())),
+            ("version", CS.toString (Prim.Uname.getVersion ())),
+            ("machine", CS.toString (Prim.Uname.getMachine ()))]))
+
+      val time = Time.now
+
       local
-         structure Uname = Prim.Uname
+         val sysconfNames =
+            [
+             (Prim.SC_2_CHAR_TERM,"2_CHAR_TERM"),
+             (Prim.SC_2_C_BIND,"2_C_BIND"),
+             (Prim.SC_2_C_DEV,"2_C_DEV"),
+             (Prim.SC_2_FORT_DEV,"2_FORT_DEV"),
+             (Prim.SC_2_FORT_RUN,"2_FORT_RUN"),
+             (Prim.SC_2_LOCALEDEF,"2_LOCALEDEF"),
+             (Prim.SC_2_PBS,"2_PBS"),
+             (Prim.SC_2_PBS_ACCOUNTING,"2_PBS_ACCOUNTING"),
+             (Prim.SC_2_PBS_CHECKPOINT,"2_PBS_CHECKPOINT"),
+             (Prim.SC_2_PBS_LOCATE,"2_PBS_LOCATE"),
+             (Prim.SC_2_PBS_MESSAGE,"2_PBS_MESSAGE"),
+             (Prim.SC_2_PBS_TRACK,"2_PBS_TRACK"),
+             (Prim.SC_2_SW_DEV,"2_SW_DEV"),
+             (Prim.SC_2_UPE,"2_UPE"),
+             (Prim.SC_2_VERSION,"2_VERSION"),
+             (Prim.SC_ADVISORY_INFO,"ADVISORY_INFO"),
+             (Prim.SC_AIO_LISTIO_MAX,"AIO_LISTIO_MAX"),
+             (Prim.SC_AIO_MAX,"AIO_MAX"),
+             (Prim.SC_AIO_PRIO_DELTA_MAX,"AIO_PRIO_DELTA_MAX"),
+             (Prim.SC_ARG_MAX,"ARG_MAX"),
+             (Prim.SC_ASYNCHRONOUS_IO,"ASYNCHRONOUS_IO"),
+             (Prim.SC_ATEXIT_MAX,"ATEXIT_MAX"),
+             (Prim.SC_BARRIERS,"BARRIERS"),
+             (Prim.SC_BC_BASE_MAX,"BC_BASE_MAX"),
+             (Prim.SC_BC_DIM_MAX,"BC_DIM_MAX"),
+             (Prim.SC_BC_SCALE_MAX,"BC_SCALE_MAX"),
+             (Prim.SC_BC_STRING_MAX,"BC_STRING_MAX"),
+             (Prim.SC_CHILD_MAX,"CHILD_MAX"),
+             (Prim.SC_CLK_TCK,"CLK_TCK"),
+             (Prim.SC_CLOCK_SELECTION,"CLOCK_SELECTION"),
+             (Prim.SC_COLL_WEIGHTS_MAX,"COLL_WEIGHTS_MAX"),
+             (Prim.SC_CPUTIME,"CPUTIME"),
+             (Prim.SC_DELAYTIMER_MAX,"DELAYTIMER_MAX"),
+             (Prim.SC_EXPR_NEST_MAX,"EXPR_NEST_MAX"),
+             (Prim.SC_FSYNC,"FSYNC"),
+             (Prim.SC_GETGR_R_SIZE_MAX,"GETGR_R_SIZE_MAX"),
+             (Prim.SC_GETPW_R_SIZE_MAX,"GETPW_R_SIZE_MAX"),
+             (Prim.SC_HOST_NAME_MAX,"HOST_NAME_MAX"),
+             (Prim.SC_IOV_MAX,"IOV_MAX"),
+             (Prim.SC_IPV6,"IPV6"),
+             (Prim.SC_JOB_CONTROL,"JOB_CONTROL"),
+             (Prim.SC_LINE_MAX,"LINE_MAX"),
+             (Prim.SC_LOGIN_NAME_MAX,"LOGIN_NAME_MAX"),
+             (Prim.SC_MAPPED_FILES,"MAPPED_FILES"),
+             (Prim.SC_MEMLOCK,"MEMLOCK"),
+             (Prim.SC_MEMLOCK_RANGE,"MEMLOCK_RANGE"),
+             (Prim.SC_MEMORY_PROTECTION,"MEMORY_PROTECTION"),
+             (Prim.SC_MESSAGE_PASSING,"MESSAGE_PASSING"),
+             (Prim.SC_MONOTONIC_CLOCK,"MONOTONIC_CLOCK"),
+             (Prim.SC_MQ_OPEN_MAX,"MQ_OPEN_MAX"),
+             (Prim.SC_MQ_PRIO_MAX,"MQ_PRIO_MAX"),
+             (Prim.SC_NGROUPS_MAX,"NGROUPS_MAX"),
+             (Prim.SC_OPEN_MAX,"OPEN_MAX"),
+             (Prim.SC_PAGESIZE,"PAGESIZE"),
+             (Prim.SC_PAGE_SIZE,"PAGE_SIZE"),
+             (Prim.SC_PRIORITIZED_IO,"PRIORITIZED_IO"),
+             (Prim.SC_PRIORITY_SCHEDULING,"PRIORITY_SCHEDULING"),
+             (Prim.SC_RAW_SOCKETS,"RAW_SOCKETS"),
+             (Prim.SC_READER_WRITER_LOCKS,"READER_WRITER_LOCKS"),
+             (Prim.SC_REALTIME_SIGNALS,"REALTIME_SIGNALS"),
+             (Prim.SC_REGEXP,"REGEXP"),
+             (Prim.SC_RE_DUP_MAX,"RE_DUP_MAX"),
+             (Prim.SC_RTSIG_MAX,"RTSIG_MAX"),
+             (Prim.SC_SAVED_IDS,"SAVED_IDS"),
+             (Prim.SC_SEMAPHORES,"SEMAPHORES"),
+             (Prim.SC_SEM_NSEMS_MAX,"SEM_NSEMS_MAX"),
+             (Prim.SC_SEM_VALUE_MAX,"SEM_VALUE_MAX"),
+             (Prim.SC_SHARED_MEMORY_OBJECTS,"SHARED_MEMORY_OBJECTS"),
+             (Prim.SC_SHELL,"SHELL"),
+             (Prim.SC_SIGQUEUE_MAX,"SIGQUEUE_MAX"),
+             (Prim.SC_SPAWN,"SPAWN"),
+             (Prim.SC_SPIN_LOCKS,"SPIN_LOCKS"),
+             (Prim.SC_SPORADIC_SERVER,"SPORADIC_SERVER"),
+             (Prim.SC_SS_REPL_MAX,"SS_REPL_MAX"),
+             (Prim.SC_STREAM_MAX,"STREAM_MAX"),
+             (Prim.SC_SYMLOOP_MAX,"SYMLOOP_MAX"),
+             (Prim.SC_SYNCHRONIZED_IO,"SYNCHRONIZED_IO"),
+             (Prim.SC_THREADS,"THREADS"),
+             (Prim.SC_THREAD_ATTR_STACKADDR,"THREAD_ATTR_STACKADDR"),
+             (Prim.SC_THREAD_ATTR_STACKSIZE,"THREAD_ATTR_STACKSIZE"),
+             (Prim.SC_THREAD_CPUTIME,"THREAD_CPUTIME"),
+             (Prim.SC_THREAD_DESTRUCTOR_ITERATIONS,"THREAD_DESTRUCTOR_ITERATIONS"),
+             (Prim.SC_THREAD_KEYS_MAX,"THREAD_KEYS_MAX"),
+             (Prim.SC_THREAD_PRIORITY_SCHEDULING,"THREAD_PRIORITY_SCHEDULING"),
+             (Prim.SC_THREAD_PRIO_INHERIT,"THREAD_PRIO_INHERIT"),
+             (Prim.SC_THREAD_PRIO_PROTECT,"THREAD_PRIO_PROTECT"),
+             (Prim.SC_THREAD_PROCESS_SHARED,"THREAD_PROCESS_SHARED"),
+             (Prim.SC_THREAD_SAFE_FUNCTIONS,"THREAD_SAFE_FUNCTIONS"),
+             (Prim.SC_THREAD_SPORADIC_SERVER,"THREAD_SPORADIC_SERVER"),
+             (Prim.SC_THREAD_STACK_MIN,"THREAD_STACK_MIN"),
+             (Prim.SC_THREAD_THREADS_MAX,"THREAD_THREADS_MAX"),
+             (Prim.SC_TIMEOUTS,"TIMEOUTS"),
+             (Prim.SC_TIMERS,"TIMERS"),
+             (Prim.SC_TIMER_MAX,"TIMER_MAX"),
+             (Prim.SC_TRACE,"TRACE"),
+             (Prim.SC_TRACE_EVENT_FILTER,"TRACE_EVENT_FILTER"),
+             (Prim.SC_TRACE_EVENT_NAME_MAX,"TRACE_EVENT_NAME_MAX"),
+             (Prim.SC_TRACE_INHERIT,"TRACE_INHERIT"),
+             (Prim.SC_TRACE_LOG,"TRACE_LOG"),
+             (Prim.SC_TRACE_NAME_MAX,"TRACE_NAME_MAX"),
+             (Prim.SC_TRACE_SYS_MAX,"TRACE_SYS_MAX"),
+             (Prim.SC_TRACE_USER_EVENT_MAX,"TRACE_USER_EVENT_MAX"),
+             (Prim.SC_TTY_NAME_MAX,"TTY_NAME_MAX"),
+             (Prim.SC_TYPED_MEMORY_OBJECTS,"TYPED_MEMORY_OBJECTS"),
+             (Prim.SC_TZNAME_MAX,"TZNAME_MAX"),
+             (Prim.SC_V6_ILP32_OFF32,"V6_ILP32_OFF32"),
+             (Prim.SC_V6_ILP32_OFFBIG,"V6_ILP32_OFFBIG"),
+             (Prim.SC_V6_LP64_OFF64,"V6_LP64_OFF64"),
+             (Prim.SC_V6_LPBIG_OFFBIG,"V6_LPBIG_OFFBIG"),
+             (Prim.SC_VERSION,"VERSION"),
+             (Prim.SC_XBS5_ILP32_OFF32,"XBS5_ILP32_OFF32"),
+             (Prim.SC_XBS5_ILP32_OFFBIG,"XBS5_ILP32_OFFBIG"),
+             (Prim.SC_XBS5_LP64_OFF64,"XBS5_LP64_OFF64"),
+             (Prim.SC_XBS5_LPBIG_OFFBIG,"XBS5_LPBIG_OFFBIG"),
+             (Prim.SC_XOPEN_CRYPT,"XOPEN_CRYPT"),
+             (Prim.SC_XOPEN_ENH_I18N,"XOPEN_ENH_I18N"),
+             (Prim.SC_XOPEN_LEGACY,"XOPEN_LEGACY"),
+             (Prim.SC_XOPEN_REALTIME,"XOPEN_REALTIME"),
+             (Prim.SC_XOPEN_REALTIME_THREADS,"XOPEN_REALTIME_THREADS"),
+             (Prim.SC_XOPEN_SHM,"XOPEN_SHM"),
+             (Prim.SC_XOPEN_STREAMS,"XOPEN_STREAMS"),
+             (Prim.SC_XOPEN_UNIX,"XOPEN_UNIX"),
+             (Prim.SC_XOPEN_VERSION,"XOPEN_VERSION")
+             ]
       in
-         fun uname () =
-            SysCall.syscall
-            (fn () =>
-             (Uname.uname (), fn () =>
-              [("sysname", CS.toString (Uname.sysname ())),
-               ("nodename", CS.toString (Uname.nodename ())),
-               ("release", CS.toString (Uname.release ())),
-               ("version", CS.toString (Uname.version ())),
-               ("machine", CS.toString (Uname.machine ()))]))
+         fun sysconf s =
+            case List.find (fn (_, s') => s = s') sysconfNames of
+               NONE => Error.raiseSys Error.inval
+             | SOME (n, _) =>
+                  (SysWord.fromInt o SysCall.simpleResult)
+                  (fn () => Prim.sysconf n)
       end
-
-      val time = Time.now
-
-      fun sysconf s =
-         case List.find (fn (_, s') => s = s') Prim.sysconfNames of
-            NONE => Error.raiseSys Error.inval
-          | SOME (n, _) =>
-               (SysWord.fromInt o SysCall.simpleResult)
-               (fn () => Prim.sysconf n)
                
       local
-         structure Tms = Prim.Tms
+         structure Times = Prim.Times
 
          val ticksPerSec = Int.toLarge (SysWord.toIntX (sysconf "CLK_TCK"))
 
-         fun cvt (ticks: word) =
+         fun cvt (ticks: C.Clock.t) =
             Time.fromTicks (LargeInt.quot
-                            (LargeInt.* (Word.toLargeIntX ticks,
+                            (LargeInt.* (C.Clock.toLarge ticks,
                                          Time.ticksPerSecond),
                              ticksPerSec))
       in
@@ -112,14 +234,14 @@
              let val elapsed = Prim.times () 
              in (0, fn () =>
                  {elapsed = cvt elapsed,
-                  utime = cvt (Tms.utime ()), 
-                  stime = cvt (Tms.stime ()), 
-                  cutime = cvt (Tms.cutime ()), 
-                  cstime = cvt (Tms.cstime ())})
+                  utime = cvt (Times.getUTime ()), 
+                  stime = cvt (Times.getSTime ()), 
+                  cutime = cvt (Times.getCUTime ()), 
+                  cstime = cvt (Times.getCSTime ())})
              end)
       end
 
-      fun environ () = COld.CSS.toList Prim.environ
+      fun environ () = COld.CSS.toList (Prim.environGet ())
 
       fun getenv name =
          let

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/process.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/process.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/process.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -8,7 +8,7 @@
 
 structure PosixProcess: POSIX_PROCESS_EXTRA =
    struct
-      structure Prim = PosixPrimitive.Process
+      structure Prim = PrimitiveFFI.Posix.Process
       open Prim
       structure Error = PosixError
       structure SysCall = Error.SysCall
@@ -86,10 +86,13 @@
       structure W =
          struct
             open W BitFlags
+            val continued = SysWord.fromInt CONTINUED
+            val nohang = SysWord.fromInt NOHANG
+            val untraced = SysWord.fromInt UNTRACED
          end
 
       local
-         val status: Status.t ref = ref (Status.fromInt 0)
+         val status: C.Status.t ref = ref (C.Status.fromInt 0)
          fun wait (wa, status, flags) =
             let
                val useCwait = 
@@ -108,7 +111,7 @@
                 let
                    val pid = 
                       if useCwait 
-                         then Prim.cwait (Pid.fromInt p, status)
+                         then PrimitiveFFI.MLton.Process.cwait (Pid.fromInt p, status)
                       else Prim.waitpid (Pid.fromInt p, status,
                                          SysWord.toInt flags)
                 in
@@ -126,7 +129,7 @@
 
          fun waitpid_nh (wa, flags) =
             let
-               val pid = wait (wa, status, wnohang :: flags)
+               val pid = wait (wa, status, W.nohang :: flags)
             in
                if 0 = Pid.toInt pid
                   then NONE
@@ -162,10 +165,12 @@
       local
          fun wrap prim (t: Time.time): Time.time =
             Time.fromSeconds
-            (LargeInt.fromInt 
-             (prim 
-              (LargeInt.toInt (Time.toSeconds t)
-               handle Overflow => Error.raiseSys Error.inval)))
+            (LargeInt.fromInt
+             (C.UInt.toInt
+              (prim 
+               (C.UInt.fromInt
+                (LargeInt.toInt (Time.toSeconds t)
+                 handle Overflow => Error.raiseSys Error.inval)))))
       in
          val alarm = wrap Prim.alarm
 (*       val sleep = wrap Prim.sleep *)

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/stub-mingw.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/stub-mingw.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/stub-mingw.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -19,93 +19,6 @@
                        ; Error.raiseSys Error.nosys)
       else f
 in
-   structure PosixPrimitive =
-      struct
-         open PosixPrimitive
-
-         structure FileSys =
-            struct
-               open FileSys
-
-               val chown = stub ("chown", chown)
-               val fchown = stub ("fchown", fchown)
-               val fpathconf = stub ("fpathconf", fpathconf)
-               val link = stub ("link", link)
-               val mkfifo = stub ("mkfifo", mkfifo)
-               val pathconf = stub ("pathconf", pathconf)
-               val readlink = stub ("readlink", readlink)
-               val symlink = stub ("symlink", symlink)
-            end
-
-         structure IO =
-            struct
-               open IO
-                  
-               val fcntl2 = stub ("fcntl2", fcntl2)
-               val fcntl3 = stub ("fcntl3", fcntl3)
-            end
-
-         structure Process =
-            struct
-               open Process
-
-               val exece = stub ("exece", exece)
-               val execp = stub ("execp", execp)
-               val exit = stub ("exit", exit)
-               val fork = stub ("fork", fork)
-               val kill = stub ("kill", kill)
-               val pause = stub ("pause", pause)
-               val waitpid = stub ("waitpid", waitpid)
-            end
-
-         structure ProcEnv =
-            struct
-               open ProcEnv
-
-               val ctermid = stub ("ctermid", ctermid)
-               val getegid = stub ("getegid", getegid)
-               val geteuid = stub ("geteuid", geteuid)
-               val getgid = stub ("getgid", getgid)
-               val getgroups = stub ("getgroups", getgroups)
-               val getlogin = stub ("getlogin", getlogin)
-               val getpgrp = stub ("getpgrp", getpgrp)
-               val getpid = stub ("getpid", getpid)
-               val getppid = stub ("getppid", getppid)
-               val getuid = stub ("getuid", getuid)
-               val setgid = stub ("setgid", setgid)
-               val setgroups = stub ("stegroups", setgroups)
-               val setpgid = stub ("setpgid", setpgid)
-               val setsid = stub ("setsid", setsid)
-               val setuid = stub ("setuid", setuid)
-               val sysconf = stub ("sysconf", sysconf)
-               val times = stub ("times", times)
-               val ttyname = stub ("ttyname", ttyname)
-            end
-
-         structure SysDB =
-            struct
-               open SysDB
-                  
-               val getgrgid = stub ("getgrgid", getgrgid)
-               val getgrnam = stub ("getgrnam", getgrnam)
-               val getpwuid = stub ("getpwuid", getpwuid)
-            end
-
-         structure TTY =
-            struct
-               open TTY
-                  
-               val drain = stub ("drain", drain)
-               val flow = stub ("flow", flow)
-               val flush = stub ("flush", flush)
-               val getattr = stub ("getattr", getattr)
-               val getpgrp = stub ("getpgrp", getpgrp)
-               val sendbreak = stub ("sendbreak", sendbreak)
-               val setattr = stub ("setattr", setattr)
-               val setpgrp = stub ("setpgrp", setpgrp)
-            end
-      end
-   
    structure Primitive =
       struct
          open Primitive
@@ -150,5 +63,97 @@
                      val poll = stub ("poll", poll)
                   end
             end
+
+         structure Posix =
+            struct
+               open Posix
+
+               structure FileSys =
+                  struct
+                     open FileSys
+                        
+                     val chown = stub ("chown", chown)
+                     val fchown = stub ("fchown", fchown)
+                     val fpathconf = stub ("fpathconf", fpathconf)
+                     val link = stub ("link", link)
+                     val mkfifo = stub ("mkfifo", mkfifo)
+                     val pathconf = stub ("pathconf", pathconf)
+                     val readlink = stub ("readlink", readlink)
+                     val symlink = stub ("symlink", symlink)
+                  end
+
+               structure IO =
+                  struct
+                     open IO
+                        
+                     val fcntl2 = stub ("fcntl2", fcntl2)
+                     val fcntl3 = stub ("fcntl3", fcntl3)
+                  end
+
+               structure ProcEnv =
+                  struct
+                     open ProcEnv
+                        
+                     val ctermid = stub ("ctermid", ctermid)
+                     val getegid = stub ("getegid", getegid)
+                     val geteuid = stub ("geteuid", geteuid)
+                     val getgid = stub ("getgid", getgid)
+                     val getgroups = stub ("getgroups", getgroups)
+                     val getlogin = stub ("getlogin", getlogin)
+                     val getpgrp = stub ("getpgrp", getpgrp)
+                     val getpid = stub ("getpid", getpid)
+                     val getppid = stub ("getppid", getppid)
+                     val getuid = stub ("getuid", getuid)
+                     val setgid = stub ("setgid", setgid)
+                     val setgroups = stub ("stegroups", setgroups)
+                     val setpgid = stub ("setpgid", setpgid)
+                     val setsid = stub ("setsid", setsid)
+                     val setuid = stub ("setuid", setuid)
+                     val sysconf = stub ("sysconf", sysconf)
+                     val times = stub ("times", times)
+                     val ttyname = stub ("ttyname", ttyname)
+                  end
+
+               structure Process =
+                  struct
+                     open Process
+                        
+                     val exece = stub ("exece", exece)
+                     val execp = stub ("execp", execp)
+                     val exit = stub ("exit", exit)
+                     val fork = stub ("fork", fork)
+                     val kill = stub ("kill", kill)
+                     val pause = stub ("pause", pause)
+                     val waitpid = stub ("waitpid", waitpid)
+                  end
+
+               structure SysDB =
+                  struct
+                     open SysDB
+                        
+                     val getgrgid = stub ("getgrgid", getgrgid)
+                     val getgrnam = stub ("getgrnam", getgrnam)
+                     val getpwuid = stub ("getpwuid", getpwuid)
+                  end
+
+               structure TTY =
+                  struct
+                     open TTY
+                        
+                     structure TC =
+                        struct
+                           open TC
+
+                           val drain = stub ("drain", drain)
+                           val flow = stub ("flow", flow)
+                           val flush = stub ("flush", flush)
+                           val getattr = stub ("getattr", getattr)
+                           val getpgrp = stub ("getpgrp", getpgrp)
+                           val sendbreak = stub ("sendbreak", sendbreak)
+                           val setattr = stub ("setattr", setattr)
+                           val setpgrp = stub ("setpgrp", setpgrp)
+                        end
+                  end
+            end
       end
 end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/sys-db.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/sys-db.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/sys-db.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -9,12 +9,12 @@
 structure PosixSysDB: POSIX_SYS_DB =
    struct
       structure CS = COld.CS
-      structure Prim = PosixPrimitive.SysDB
+      structure Prim = PrimitiveFFI.Posix.SysDB
       structure Error = PosixError
       structure SysCall = Error.SysCall
 
-      type uid = Prim.uid
-      type gid = Prim.gid
+      type uid = C.UId.t
+      type gid = C.GId.t
 
       structure Passwd =
          struct
@@ -24,20 +24,18 @@
                            home: string,
                            shell: string}
 
-            local
-               structure C = Prim.Passwd
-            in
-               fun fromC (f: unit -> bool): passwd =
-                  SysCall.syscall
-                  (fn () =>
-                   (if f () then 0 else ~1,
-                    fn () => {name = CS.toString(C.name()),
-                              uid = C.uid(),
-                              gid = C.gid(),
-                              home = CS.toString(C.dir()),
-                              shell = CS.toString(C.shell())}))
-            end
+            structure Passwd = Prim.Passwd
 
+            fun fromC (f: unit -> bool): passwd =
+               SysCall.syscall
+               (fn () =>
+                (if f () then 0 else ~1,
+                 fn () => {name = CS.toString(Passwd.getName ()),
+                           uid = Passwd.getUId (),
+                           gid = Passwd.getGId (),
+                           home = CS.toString(Passwd.getDir ()),
+                           shell = CS.toString(Passwd.getShell ())}))
+               
             val name: passwd -> string = #name
             val uid: passwd -> uid = #uid
             val gid: passwd -> gid = #gid
@@ -64,9 +62,9 @@
                SysCall.syscall
                (fn () =>
                 (if f () then 0 else ~1,
-                 fn () => {name = CS.toString(Group.name()),
-                           gid = Group.gid(),
-                           members = COld.CSS.toList(Group.mem())}))
+                 fn () => {name = CS.toString(Group.getName ()),
+                           gid = Group.getGId (),
+                           members = COld.CSS.toList(Group.getMem ())}))
                   
             val name: group -> string = #name
             val gid: group -> gid = #gid

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/tty.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/tty.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/tty.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -9,26 +9,39 @@
 structure PosixTTY: POSIX_TTY =
    struct
       structure Cstring = COld.CS
-      structure Prim = PosixPrimitive.TTY
+      structure Prim = PrimitiveFFI.Posix.TTY
       open Prim
       structure Error = PosixError
       structure SysCall = Error.SysCall
 
-      type pid = Pid.t
+      type pid = C.PId.t
          
-      datatype file_desc = datatype Prim.file_desc
+      type file_desc = C.Fd.t
          
       structure V =
          struct
             open V
+            val nccs = NCCS
+            val eof = VEOF
+            val eol = VEOL
+            val erase = VERASE
+            val intr = VINTR
+            val kill = VKILL
+            val min = VMIN
+            val quit = VQUIT
+            val susp = VSUSP
+            val time = VTIME
+            val start = VSTART
+            val stop = VSTOP
 
-            type cc = char array
+            type cc = C.CC.t array
 
-            val default = #"\000"
+            val default = Byte.charToByte #"\000"
 
-            fun new () = Array.array (nccs, default)
+            fun new () = Array.array (NCCS, default)
 
-            fun updates (a, l) = List.app (fn (i, c) => Array.update (a, i, c)) l
+            fun updates (a, l) = 
+               List.app (fn (i, cc) => Array.update (a, i, Byte.charToByte cc)) l
 
             fun cc l = let val a = new ()
                        in updates (a, l)
@@ -42,40 +55,117 @@
                   ; a'
                end
 
-            val sub = Array.sub
+            val sub = Byte.byteToChar o Array.sub
          end
       
-      structure I =
+      structure IFlags =
          struct
-            open I BitFlags
+            open IFlags BitFlags
+            val brkint = BRKINT
+            val icrnl = ICRNL
+            val ignbrk = IGNBRK
+            val igncr = IGNCR
+            val ignpar = IGNPAR
+            val inlcr = INLCR
+            val inpck = INPCK
+            val istrip = ISTRIP
+            val ixany = IXANY
+            val ixoff = IXOFF
+            val ixon = IXON
+            val parmrk = PARMRK
          end
       
-      structure O =
+      structure OFlags =
          struct
-            open O BitFlags
+            open OFlags BitFlags
+            val bs0 = BS0
+            val bs1 = BS1
+            val bsdly = BSDLY
+            val cr0 = CR0
+            val cr1 = CR1
+            val cr2 = CR2
+            val cr3 = CR3
+            val crdly = CRDLY
+            val ff0 = FF0
+            val ff1 = FF1
+            val ffdly = FFDLY
+            val nl0 = NL0
+            val nl1 = NL1
+            val onldly = NLDLY
+            val ocrnl = OCRNL
+            val ofill = OFILL
+            val onlcr = ONLCR
+            val onlret = ONLRET
+            val onocr = ONOCR
+            val opost = OPOST
+            val tab0 = TAB0
+            val tab1 = TAB1
+            val tab2 = TAB2
+            val tab3 = TAB3
+            val tabdly = TABDLY
+            val vt0 = VT0
+            val vt1 = VT1
+            val vtdly = VTDLY
          end
       
-      structure C =
+      structure CFlags =
          struct
-            open C BitFlags
+            open CFlags BitFlags
+            val clocal = CLOCAL
+            val cread = CREAD
+            val cs5 = CS5
+            val cs6 = CS6
+            val cs7 = CS7
+            val cs8 = CS8
+            val csize = CSIZE
+            val cstopb = CSTOPB
+            val hupcl = HUPCL
+            val parenb = PARENB
+            val parodd = PARODD
          end
       
-      structure L =
+      structure LFlags =
          struct
-            open L BitFlags
+            open LFlags BitFlags
+            val echo = ECHO
+            val echoe = ECHOE
+            val echok = ECHOK
+            val echonl = ECHONL
+            val icanon = ICANON
+            val iexten = IEXTEN
+            val isig = ISIG
+            val noflsh = NOFLSH
+            val tostop = TOSTOP
          end
 
-      type speed = Prim.speed
+      type speed = C.Speed.t
 
+      val b0 = B0
+      val b110 = B110
+      val b1200 = B1200
+      val b134 = B134
+      val b150 = B150
+      val b1800 = B1800
+      val b19200 = B19200
+      val b200 = B200
+      val b2400 = B2400
+      val b300 = B300
+      val b38400 = B38400
+      val b4800 = B4800
+      val b50 = B50
+      val b600 = B600
+      val b75 = B75
+      val b9600 = B9600
+
       val compareSpeed = SysWord.compare
       fun id x = x
       val speedToWord = id
       val wordToSpeed = id
 
-      type termios = {iflag: I.flags,
-                      oflag: O.flags,
-                      cflag: C.flags,
-                      lflag: L.flags,
+      type termios = {iflag: IFlags.flags,
+                      oflag: OFlags.flags,
+                      cflag: CFlags.flags,
+                      lflag: LFlags.flags,
                       cc: V.cc,
                       ispeed: speed,
                       ospeed: speed}
@@ -83,10 +173,10 @@
       val termios = id
       val fieldsOf = id
 
-      val getiflag: termios -> I.flags = #iflag
-      val getoflag: termios -> O.flags = #oflag
-      val getcflag: termios -> C.flags = #cflag
-      val getlflag: termios -> L.flags = #oflag
+      val getiflag: termios -> IFlags.flags = #iflag
+      val getoflag: termios -> OFlags.flags = #oflag
+      val getcflag: termios -> CFlags.flags = #cflag
+      val getlflag: termios -> LFlags.flags = #oflag
       val getcc: termios -> V.cc = #cc
 
       structure CF =
@@ -121,53 +211,73 @@
          struct
             open Prim.TC 
 
+            type set_action = C.Int.t
+            val sadrain = TCSADRAIN
+            val saflush = TCSAFLUSH
+            val sanow = TCSANOW
+
+            type flow_action = C.Int.t
+            val ioff = TCIOFF
+            val ion = TCION
+            val ooff = TCOOFF
+            val oon = TCOON
+
+            type queue_sel = C.Int.t
+            val iflush = TCIFLUSH
+            val oflush = TCOFLUSH
+            val ioflush = TCIOFLUSH
+
             fun getattr fd =
                SysCall.syscallRestart
                (fn () =>
-                (Prim.getattr fd, fn () =>
-                 {iflag = Termios.iflag (),
-                  oflag = Termios.oflag (),
-                  cflag = Termios.cflag (),
-                  lflag = Termios.lflag (),
-                  cc = Cstring.toCharArrayOfLength (Termios.cc (), V.nccs),
-                  ispeed = Termios.ispeed (),
-                  ospeed = Termios.ospeed ()}))
+                (Prim.TC.getattr fd, fn () =>
+                 {iflag = Termios.getIFlag (),
+                  oflag = Termios.getOFlag (),
+                  cflag = Termios.getCFlag (),
+                  lflag = Termios.getLFlag (),
+                  cc = let val a = V.new ()
+                       in Termios.getCC (a); a
+                       end,
+                  ispeed = Termios.cfGetISpeed (),
+                  ospeed = Termios.cfGetOSpeed ()}))
 
             fun setattr (fd, a,
                          {iflag, oflag, cflag, lflag, cc, ispeed, ospeed}) =
                SysCall.syscallRestart
                (fn () =>
-                (Termios.setiflag iflag
-                 ; Termios.setoflag oflag
-                 ; Termios.setcflag cflag
-                 ; Termios.setlflag lflag
-                 ; SysCall.simple (fn () => Termios.setospeed ospeed)
-                 ; SysCall.simple (fn () => Termios.setispeed ispeed)
-                 ; let val cs = Termios.cc () 
-                   in Util.naturalForeach
-                      (V.nccs, fn i => Cstring.update (cs, i, V.sub (cc, i)))
-                   end
-                 ; (Prim.setattr (fd, a), fn () => ())))
+                (Termios.setIFlag iflag
+                 ; Termios.setOFlag oflag
+                 ; Termios.setCFlag cflag
+                 ; Termios.setLFlag lflag
+                 ; SysCall.simple (fn () => Termios.cfSetOSpeed ospeed)
+                 ; SysCall.simple (fn () => Termios.cfSetISpeed ispeed)
+                 ; Termios.setCC cc
+                 ; (Prim.TC.setattr (fd, a), fn () => ())))
 
             fun sendbreak (fd, n) =
-               SysCall.simpleRestart (fn () => Prim.sendbreak (fd, n))
+               SysCall.simpleRestart (fn () => Prim.TC.sendbreak (fd, n))
 
-            fun drain fd = SysCall.simpleRestart (fn () => Prim.drain fd)
+            fun drain fd = SysCall.simpleRestart (fn () => Prim.TC.drain fd)
               
             fun flush (fd, n) =
-               SysCall.simpleRestart (fn () => Prim.flush (fd, n))
+               SysCall.simpleRestart (fn () => Prim.TC.flush (fd, n))
               
             fun flow (fd, n) =
-               SysCall.simpleRestart (fn () => Prim.flow (fd, n))
+               SysCall.simpleRestart (fn () => Prim.TC.flow (fd, n))
               
             fun getpgrp fd =
                SysCall.syscallRestart
                (fn () =>
-                let val pid = Prim.getpgrp fd
+                let val pid = Prim.TC.getpgrp fd
                 in (Pid.toInt pid, fn () => pid)
                 end)
               
             fun setpgrp (fd, pid) = 
-               SysCall.simpleRestart (fn () => Prim.setpgrp (fd, pid))
+               SysCall.simpleRestart (fn () => Prim.TC.setpgrp (fd, pid))
          end
+
+      structure C = CFlags
+      structure I = IFlags
+      structure L = LFlags
+      structure O = OFlags
    end

Deleted: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/posix-primitive.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/posix-primitive.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/posix-primitive.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -1,614 +0,0 @@
-(* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
- *    Jagannathan, and Stephen Weeks.
- * Copyright (C) 1997-2000 NEC Research Institute.
- *
- * MLton is released under a BSD-style license.
- * See the file MLton-LICENSE for details.
- *)
-
-structure PosixPrimitive =
-   struct
-      type cstring = Pointer.t
-      type cstringArray = Pointer.t
-
-      type uid = word
-      type gid = word
-      type size = int
-      type ssize = int
-      type mode = word
-      type time = int
-
-      structure FileDesc = Primitive.FileDesc
-      type file_desc = FileDesc.t
-      type fd = file_desc
-         
-      structure Signal =
-         struct
-            open Primitive.Signal
-         end
-      
-      structure Process =
-         struct
-            val wnohang = _const "Posix_Process_wnohang": word;
-            structure W =
-               struct
-                  type flags = word
-                  val untraced = _const "Posix_Process_W_untraced": flags;
-               end
-
-            structure Status = Primitive.Status
-            
-            val alarm = _import "Posix_Process_alarm": int -> int;
-            val exece =
-               _import "Posix_Process_exece"
-               : NullString.t * NullString.t array * NullString.t array -> int;
-            val execp =
-               _import "Posix_Process_execp"
-               : NullString.t * NullString.t array -> int;
-            val exit = _import "Posix_Process_exit": int -> unit;
-            val exitStatus = _import "Posix_Process_exitStatus": Status.t -> int;
-            val fork = _import "Posix_Process_fork": unit -> Pid.t;
-            val ifExited = _import "Posix_Process_ifExited": Status.t -> bool;
-            val ifSignaled = _import "Posix_Process_ifSignaled"
-               : Status.t -> bool;
-            val ifStopped = _import "Posix_Process_ifStopped": Status.t -> bool;
-            val kill = _import "Posix_Process_kill": Pid.t * Signal.t -> int;
-            val nanosleep =
-               _import "Posix_Process_nanosleep": int ref * int ref -> int;
-            val pause = _import "Posix_Process_pause": unit -> int;
-(*          val sleep = _import "Posix_Process_sleep": int -> int; *)
-            val stopSig = _import "Posix_Process_stopSig": Status.t -> Signal.t;
-            val system =
-               _import "Posix_Process_system": NullString.t -> Status.t;
-            val termSig = _import "Posix_Process_termSig": Status.t -> Signal.t;
-            val waitpid =
-               _import "Posix_Process_waitpid"
-               : Pid.t * Status.t ref * int -> Pid.t;
-            val cwait =
-               if let
-                     open Primitive.MLton.Platform.OS
-                  in
-                     case host of
-                        Cygwin => true
-                      | MinGW => true
-                      | _ => false
-                  end
-                  then _import "MLton_Process_cwait": Pid.t * Status.t ref -> Pid.t;
-               else fn _ => raise Fail "cwait not defined"
-         end
-
-      structure ProcEnv =
-         struct
-            val numgroups = _const "Posix_ProcEnv_numgroups": int;
-            val sysconfNames =
-               [
-                (* Required *)
-                (_const "Posix_ProcEnv_ARG_MAX": int;, "ARG_MAX"),
-                (_const "Posix_ProcEnv_CHILD_MAX": int;, "CHILD_MAX"),
-                (_const "Posix_ProcEnv_CLK_TCK": int;, "CLK_TCK"),
-                (_const "Posix_ProcEnv_NGROUPS_MAX": int;, "NGROUPS_MAX"),
-                (_const "Posix_ProcEnv_OPEN_MAX": int;, "OPEN_MAX"),
-                (_const "Posix_ProcEnv_STREAM_MAX": int;, "STREAM_MAX"),
-                (_const "Posix_ProcEnv_TZNAME_MAX": int;, "TZNAME_MAX"),
-                (_const "Posix_ProcEnv_JOB_CONTROL": int;, "JOB_CONTROL"),
-                (_const "Posix_ProcEnv_SAVED_IDS": int;, "SAVED_IDS"),
-                (_const "Posix_ProcEnv_VERSION": int;, "VERSION"),
-                (* Optional *)
-                (_const "Posix_ProcEnv_BC_BASE_MAX": int;, "BC_BASE_MAX"),
-                (_const "Posix_ProcEnv_BC_DIM_MAX": int;, "BC_DIM_MAX"),
-                (_const "Posix_ProcEnv_BC_SCALE_MAX": int;, "BC_SCALE_MAX"),
-                (_const "Posix_ProcEnv_BC_STRING_MAX": int;, "BC_STRING_MAX"),
-                (_const "Posix_ProcEnv_COLL_WEIGHTS_MAX": int;,
-                 "COLL_WEIGHTS_MAX"),
-                (_const "Posix_ProcEnv_EXPR_NEST_MAX": int;, "EXPR_NEST_MAX"),
-                (_const "Posix_ProcEnv_LINE_MAX": int;, "LINE_MAX"),
-                (_const "Posix_ProcEnv_RE_DUP_MAX": int;, "RE_DUP_MAX"),
-                (_const "Posix_ProcEnv_2_VERSION": int;, "2_VERSION"),
-                (_const "Posix_ProcEnv_2_FORT_DEV": int;, "2_FORT_DEV"),
-                (_const "Posix_ProcEnv_2_FORT_RUN": int;, "2_FORT_RUN"),
-                (_const "Posix_ProcEnv_2_SW_DEV": int;, "2_SW_DEV")
-                ]
-               
-            type gid = gid
-            type uid = uid
-            type file_desc = file_desc
-
-            val getegid = _import "Posix_ProcEnv_getegid": unit -> gid;
-            val geteuid = _import "Posix_ProcEnv_geteuid": unit -> uid;
-            val getgid = _import "Posix_ProcEnv_getgid": unit -> gid;
-            val getgroups = _import "Posix_ProcEnv_getgroups": gid array -> int;
-            val getlogin = _import "Posix_ProcEnv_getlogin": unit -> cstring;
-            val getpgrp = _import "Posix_ProcEnv_getpgrp": unit -> Pid.t;
-            val getpid = _import "Posix_ProcEnv_getpid": unit -> Pid.t;
-            val getppid = _import "Posix_ProcEnv_getppid": unit -> Pid.t;
-            val getuid = _import "Posix_ProcEnv_getuid": unit -> uid;
-            val setenv =
-               _import "Posix_ProcEnv_setenv": NullString.t * NullString.t -> int;
-            val setgid = _import "Posix_ProcEnv_setgid": gid -> int;
-            val setgroups = _import "Posix_ProcEnv_setgroups": gid array -> int;
-            val setpgid = _import "Posix_ProcEnv_setpgid": Pid.t * Pid.t -> int;
-            val setsid = _import "Posix_ProcEnv_setsid": unit -> Pid.t;
-            val setuid = _import "Posix_ProcEnv_setuid": uid -> int;
-
-            structure Uname =
-               struct
-                  val uname = _import "Posix_ProcEnv_Uname_uname": unit -> int;
-                  val sysname =
-                     _import "Posix_ProcEnv_Uname_sysname": unit -> cstring;
-                  val nodename =
-                     _import "Posix_ProcEnv_Uname_nodename": unit -> cstring;
-                  val release =
-                     _import "Posix_ProcEnv_Uname_release": unit -> cstring;
-                  val version =
-                     _import "Posix_ProcEnv_Uname_version": unit -> cstring;
-                  val machine =
-                     _import "Posix_ProcEnv_Uname_machine": unit -> cstring;
-               end
-
-            type clock_t = word
-               
-            structure Tms =
-               struct
-                  val utime = _import "Posix_ProcEnv_Tms_utime": unit -> clock_t;
-                  val stime = _import "Posix_ProcEnv_Tms_stime": unit -> clock_t;
-                  val cutime = _import "Posix_ProcEnv_Tms_cutime": unit -> clock_t;
-                  val cstime = _import "Posix_ProcEnv_Tms_cstime": unit -> clock_t;
-               end
-
-            val ctermid = _import "Posix_ProcEnv_ctermid": unit -> cstring;
-            val environ = #1 _symbol "Posix_ProcEnv_environ": cstringArray GetSet.t; ()
-            val getenv = _import "Posix_ProcEnv_getenv": NullString.t -> cstring;
-            val isatty = _import "Posix_ProcEnv_isatty": fd -> bool;
-            val sysconf = _import "Posix_ProcEnv_sysconf": int -> int;
-            val times = _import "Posix_ProcEnv_times": unit -> clock_t;
-            val ttyname = _import "Posix_ProcEnv_ttyname": fd -> cstring;
-         end 
-      
-      structure FileSys =
-         struct
-            type file_desc = file_desc
-
-            type ino = int
-            type dev = word
-            type uid = uid
-            type gid = gid
-
-            structure S =
-               struct
-                  type mode = word
-(*                val ifsock = _const "Posix_FileSys_S_ifsock": mode; *)
-(*                val iflnk = _const "Posix_FileSys_S_iflnk": mode; *)
-(*                val ifreg = _const "Posix_FileSys_S_ifreg": mode; *)
-(*                val ifblk = _const "Posix_FileSys_S_ifblk": mode; *)
-(*                val ifdir = _const "Posix_FileSys_S_ifdir": mode; *)
-(*                val ifchr = _const "Posix_FileSys_S_ifchr": mode; *)
-(*                val ififo = _const "Posix_FileSys_S_ififo": mode; *)
-                  val irwxu = _const "Posix_FileSys_S_irwxu": mode;
-                  val irusr = _const "Posix_FileSys_S_irusr": mode;
-                  val iwusr = _const "Posix_FileSys_S_iwusr": mode;
-                  val ixusr = _const "Posix_FileSys_S_ixusr": mode;
-                  val irwxg = _const "Posix_FileSys_S_irwxg": mode;
-                  val irgrp = _const "Posix_FileSys_S_irgrp": mode;
-                  val iwgrp = _const "Posix_FileSys_S_iwgrp": mode;
-                  val ixgrp = _const "Posix_FileSys_S_ixgrp": mode;
-                  val irwxo = _const "Posix_FileSys_S_irwxo": mode;
-                  val iroth = _const "Posix_FileSys_S_iroth": mode;
-                  val iwoth = _const "Posix_FileSys_S_iwoth": mode;
-                  val ixoth = _const "Posix_FileSys_S_ixoth": mode;
-                  val isuid = _const "Posix_FileSys_S_isuid": mode;
-                  val isgid = _const "Posix_FileSys_S_isgid": mode;
-               end
-
-            structure O =
-               struct
-                  type flags = word
-                  val append = _const "Posix_FileSys_O_append": flags;
-                  val creat = _const "Posix_FileSys_O_creat": flags;
-                  val excl = _const "Posix_FileSys_O_excl": flags;
-                  val noctty = _const "Posix_FileSys_O_noctty": flags;
-                  val nonblock = _const "Posix_FileSys_O_nonblock": flags;
-                  val sync = _const "Posix_FileSys_O_sync": flags;
-                  val trunc = _const "Posix_FileSys_O_trunc": flags;
-                  val text = _const "Posix_FileSys_O_text": flags;
-                  val binary = _const "Posix_FileSys_O_binary": flags;
-               end
-
-            val o_rdonly = _const "Posix_FileSys_o_rdonly": word;
-            val o_wronly = _const "Posix_FileSys_o_wronly": word;
-            val o_rdwr = _const "Posix_FileSys_o_rdwr": word;
-            val R_OK = _const "Posix_FileSys_R_OK": word;
-            val W_OK = _const "Posix_FileSys_W_OK": word;
-            val X_OK = _const "Posix_FileSys_X_OK": word;
-            val F_OK = _const "Posix_FileSys_F_OK": word;
-
-            val properties =
-               [
-                (_const "Posix_FileSys_CHOWN_RESTRICTED": int;,
-                 "CHOWN_RESTRICTED"),
-                (_const "Posix_FileSys_LINK_MAX": int;, "LINK_MAX"),
-                (_const "Posix_FileSys_MAX_CANON": int;, "MAX_CANON"),
-                (_const "Posix_FileSys_MAX_INPUT": int;, "MAX_INPUT"),
-                (_const "Posix_FileSys_NAME_MAX": int;, "NAME_MAX"),
-                (_const "Posix_FileSys_NO_TRUNC": int;, "NO_TRUNC"),
-                (_const "Posix_FileSys_PATH_MAX": int;, "PATH_MAX"),
-                (_const "Posix_FileSys_PIPE_BUF": int;, "PIPE_BUF"),
-                (_const "Posix_FileSys_VDISABLE": int;, "VDISABLE"),
-                (_const "Posix_FileSys_ASYNC_IO": int;, "ASYNC_IO"), 
-                (_const "Posix_FileSys_SYNC_IO": int;, "SYNC_IO"), 
-                (_const "Posix_FileSys_PRIO_IO": int;, "PRIO_IO")
-                ]
-
-            structure Dirstream =
-               struct
-                  type dirstream = Pointer.t
-
-                  val closedir =
-                     _import "Posix_FileSys_Dirstream_closedir": dirstream -> int;
-                  val opendir =
-                     _import "Posix_FileSys_Dirstream_opendir"
-                     : NullString.t -> dirstream;
-                  val readdir =
-                     _import "Posix_FileSys_Dirstream_readdir"
-                     : dirstream -> cstring;
-                  val rewinddir =
-                     _import "Posix_FileSys_Dirstream_rewinddir"
-                     : dirstream -> unit;
-               end
-
-            structure Stat =
-               struct
-                  val dev = _import "Posix_FileSys_Stat_dev": unit -> dev;
-                  val ino = _import "Posix_FileSys_Stat_ino": unit -> ino;
-                  val mode = _import "Posix_FileSys_Stat_mode": unit -> word;
-                  val nlink = _import "Posix_FileSys_Stat_nlink": unit -> int;
-                  val uid = _import "Posix_FileSys_Stat_uid": unit -> uid;
-                  val gid = _import "Posix_FileSys_Stat_gid": unit -> gid;
-                  val size =
-                     _import "Posix_FileSys_Stat_size": unit -> Position.int;
-                  val atime =
-                     _import "Posix_FileSys_Stat_atime": unit -> time;
-                  val mtime =
-                     _import "Posix_FileSys_Stat_mtime": unit -> time;
-                  val ctime =
-                     _import "Posix_FileSys_Stat_ctime": unit -> time;
-                  val fstat = _import "Posix_FileSys_Stat_fstat": fd -> int;
-                  val lstat =
-                     _import "Posix_FileSys_Stat_lstat": NullString.t -> int;
-                  val stat =
-                     _import "Posix_FileSys_Stat_stat": NullString.t -> int;
-               end
-
-            structure Utimbuf =
-               struct
-                  val setActime =
-                     _import "Posix_FileSys_Utimbuf_setActime": time -> unit;
-                  val setModtime =
-                     _import "Posix_FileSys_Utimbuf_setModTime": time -> unit;
-                  val utime =
-                     _import "Posix_FileSys_Utimbuf_utime": NullString.t -> int;
-               end
-
-            val access =
-               _import "Posix_FileSys_access": NullString.t * word -> int;
-            val chdir = _import "Posix_FileSys_chdir": NullString.t -> int;
-            val chmod =
-               _import "Posix_FileSys_chmod": NullString.t * mode -> int;
-            val chown =
-               _import "Posix_FileSys_chown": NullString.t * uid * gid -> int;
-            val fchmod =
-               _import "Posix_FileSys_fchmod": fd * mode -> int;
-            val fchown =
-               _import "Posix_FileSys_fchown": fd * uid * gid -> int;
-            val fpathconf =
-               _import "Posix_FileSys_fpathconf": fd * int -> int;
-            val ftruncate =
-               _import "Posix_FileSys_ftruncate": fd * Position.int -> int;
-            val getcwd =
-               _import "Posix_FileSys_getcwd": char array * size -> cstring;
-            val link =
-               _import "Posix_FileSys_link": NullString.t * NullString.t -> int;
-            val mkdir =
-               _import "Posix_FileSys_mkdir": NullString.t * word -> int;
-            val mkfifo =
-               _import "Posix_FileSys_mkfifo": NullString.t * word -> int;
-            val openn =
-               _import "Posix_FileSys_open": NullString.t * word * mode -> int;
-            val pathconf =
-               _import "Posix_FileSys_pathconf": NullString.t * int -> int;
-            val readlink =
-               _import "Posix_FileSys_readlink"
-               : NullString.t * Word8.word array * int -> int;
-            val rename =
-               _import "Posix_FileSys_rename": NullString.t * NullString.t -> int;
-            val rmdir = _import "Posix_FileSys_rmdir": NullString.t -> int;
-            val symlink =
-               _import "Posix_FileSys_symlink"
-               : NullString.t * NullString.t -> int;
-            val umask = _import "Posix_FileSys_umask": word -> word;
-            val unlink = _import "Posix_FileSys_unlink": NullString.t -> int;
-
-            structure ST =
-               struct
-                  val isDir = _import "Posix_FileSys_ST_isDir": word -> bool;
-                  val isChr = _import "Posix_FileSys_ST_isChr": word -> bool;
-                  val isBlk = _import "Posix_FileSys_ST_isBlk": word -> bool;
-                  val isReg = _import "Posix_FileSys_ST_isReg": word -> bool;
-                  val isFIFO =
-                     _import "Posix_FileSys_ST_isFIFO": word -> bool;
-                  val isLink =
-                     _import "Posix_FileSys_ST_isLink": word -> bool;
-                  val isSock =
-                     _import "Posix_FileSys_ST_isSock": word -> bool;
-               end
-         end
-
-      structure IO =
-         struct
-            val F_DUPFD = _const "Posix_IO_F_DUPFD": int;
-            val F_GETFD = _const "Posix_IO_F_GETFD": int;
-            val F_SETFD = _const "Posix_IO_F_SETFD": int;
-            val F_GETFL = _const "Posix_IO_F_GETFL": int;
-            val F_SETFL = _const "Posix_IO_F_SETFL": int;
-            val F_GETLK = _const "Posix_IO_F_GETLK": int;
-            val F_SETLK = _const "Posix_IO_F_SETLK": int;
-            val F_RDLCK = _const "Posix_IO_F_RDLCK": int;
-            val F_WRLCK = _const "Posix_IO_F_WRLCK": int;
-            val F_UNLCK = _const "Posix_IO_F_UNLCK": int;
-            val F_SETLKW = _const "Posix_IO_F_SETLKW": int;
-(*          val F_GETOWN = _const "Posix_IO_F_GETOWN": int; *)
-(*          val F_SETOWN = _const "Posix_IO_F_SETOWN": int; *)
-            val O_ACCMODE = _const "Posix_IO_O_ACCMODE": word;
-            val SEEK_SET = _const "Posix_IO_SEEK_SET": int;
-            val SEEK_CUR = _const "Posix_IO_SEEK_CUR": int;
-            val SEEK_END = _const "Posix_IO_SEEK_END": int;
-
-            structure FD =
-               struct
-                  type flags = word
-                  val cloexec = _const "Posix_IO_FD_cloexec": flags;
-               end
-            
-            type file_desc = file_desc
-
-            structure FLock =
-               struct
-                  val fcntl = _import "Posix_IO_FLock_fcntl": fd * int -> int;
-                  val typ = _import "Posix_IO_FLock_type": unit -> int;
-                  val whence = _import "Posix_IO_FLock_whence": unit -> int;
-                  val start =
-                     _import "Posix_IO_FLock_start": unit -> Position.int;
-                  val len =
-                     _import "Posix_IO_FLock_len": unit -> Position.int;
-                  val pid = _import "Posix_IO_FLock_pid": unit -> Pid.t;
-                  val setType = _import "Posix_IO_FLock_setType": int -> unit;
-                  val setWhence =
-                     _import "Posix_IO_FLock_setWhence": int -> unit;
-                  val setStart =
-                     _import "Posix_IO_FLock_setStart": Position.int -> unit;
-                  val setLen =
-                     _import "Posix_IO_FLock_setLen": Position.int -> unit;
-(*                val setPid = _import "Posix_IO_FLock_setPid": Pid.t -> unit; *)
-               end
-            
-            val close = _import "Posix_IO_close": fd -> int;
-            val dup = _import "Posix_IO_dup": fd -> int;
-            val dup2 = _import "Posix_IO_dup2": fd * fd -> int;
-            val fcntl2 = _import "Posix_IO_fcntl2": fd * int -> int;
-            val fcntl3 = _import "Posix_IO_fcntl3": fd * int * int -> int;
-            val fsync = _import "Posix_IO_fsync": fd -> int;
-            val lseek =
-               _import "Posix_IO_lseek": fd * Position.int * int -> Position.int;
-            val pipe = _import "Posix_IO_pipe": fd array -> int;
-            val readChar =
-               _import "Posix_IO_read": fd * char array * int * size -> ssize;
-            val setbin = 
-               if let
-                     open Primitive.MLton.Platform.OS
-                  in
-                     case host of
-                        MinGW => true
-                      | _ => false
-                  end
-                  then _import "Posix_IO_setbin": fd -> unit;
-               else fn _ => raise Fail "setbin not defined"
-            val settext = 
-               if let
-                     open Primitive.MLton.Platform.OS
-                  in
-                     case host of
-                        MinGW => true
-                      | _ => false
-                  end
-                  then _import "Posix_IO_settext": fd -> unit;
-               else fn _ => raise Fail "settext not defined"
-            val writeChar =
-               _import "Posix_IO_write": fd * char array * int * size -> ssize;
-            val writeCharVec =
-               _import "Posix_IO_write": fd * char vector * int * size -> ssize;
-            val readWord8 =
-               _import "Posix_IO_read": fd * Word8.word array * int * size -> ssize;
-            val writeWord8 =
-               _import "Posix_IO_write": fd * Word8.word array * int * size -> ssize;
-            val writeWord8Vec =
-               _import "Posix_IO_write": fd * Word8.word vector * int * size -> ssize;
-         end           
-
-      structure SysDB =
-         struct
-            type gid = gid
-            type uid = uid
-
-            structure Passwd =
-               struct
-                  val name = _import "Posix_SysDB_Passwd_name": unit -> cstring;
-                  val uid = _import "Posix_SysDB_Passwd_uid": unit -> uid;
-                  val gid = _import "Posix_SysDB_Passwd_gid": unit -> gid;
-                  val dir = _import "Posix_SysDB_Passwd_dir": unit -> cstring;
-                  val shell =
-                     _import "Posix_SysDB_Passwd_shell": unit -> cstring;
-               end
-
-            val getpwnam = _import "Posix_SysDB_getpwnam": NullString.t -> bool;
-            val getpwuid = _import "Posix_SysDB_getpwuid": uid -> bool;
-
-            structure Group =
-               struct
-                  val name = _import "Posix_SysDB_Group_name": unit -> cstring;
-                  val gid = _import "Posix_SysDB_Group_gid": unit -> gid;
-                  val mem =
-                     _import "Posix_SysDB_Group_mem": unit -> cstringArray;
-               end
-
-            val getgrgid = _import "Posix_SysDB_getgrgid": gid -> bool;
-            val getgrnam = _import "Posix_SysDB_getgrnam": NullString.t -> bool;
-         end
-
-      structure TTY =
-         struct
-            type speed = word
-            val b0 = _const "Posix_TTY_b0": speed;
-            val b110 = _const "Posix_TTY_b110": speed;
-            val b1200 = _const "Posix_TTY_b1200": speed;
-            val b134 = _const "Posix_TTY_b134": speed;
-            val b150 = _const "Posix_TTY_b150": speed;
-            val b1800 = _const "Posix_TTY_b1800": speed;
-            val b19200 = _const "Posix_TTY_b19200": speed;
-            val b200 = _const "Posix_TTY_b200": speed;
-            val b2400 = _const "Posix_TTY_b2400": speed;
-            val b300 = _const "Posix_TTY_b300": speed;
-            val b38400 = _const "Posix_TTY_b38400": speed;
-            val b4800 = _const "Posix_TTY_b4800": speed;
-            val b50 = _const "Posix_TTY_b50": speed;
-            val b600 = _const "Posix_TTY_b600": speed;
-            val b75 = _const "Posix_TTY_b75": speed;
-            val b9600 = _const "Posix_TTY_b9600": speed;
-               
-            type file_desc = file_desc
-
-            structure V =
-               struct
-                  val eof = _const "Posix_TTY_V_eof": int;
-                  val eol = _const "Posix_TTY_V_eol": int;
-                  val erase = _const "Posix_TTY_V_erase": int;
-                  val intr = _const "Posix_TTY_V_intr": int;
-                  val kill = _const "Posix_TTY_V_kill": int;
-                  val min = _const "Posix_TTY_V_min": int;
-                  val nccs = _const "Posix_TTY_V_nccs": int;
-                  val quit = _const "Posix_TTY_V_quit": int;
-                  val start = _const "Posix_TTY_V_start": int;
-                  val stop = _const "Posix_TTY_V_stop": int;
-                  val susp = _const "Posix_TTY_V_susp": int;
-                  val time = _const "Posix_TTY_V_time": int;
-               end
-
-            structure I =
-               struct
-                  type flags = word
-                  val brkint = _const "Posix_TTY_I_brkint": flags;
-                  val icrnl = _const "Posix_TTY_I_icrnl": flags;
-                  val ignbrk = _const "Posix_TTY_I_ignbrk": flags;
-                  val igncr = _const "Posix_TTY_I_igncr": flags;
-                  val ignpar = _const "Posix_TTY_I_ignpar": flags;
-                  val inlcr = _const "Posix_TTY_I_inlcr": flags;
-                  val inpck = _const "Posix_TTY_I_inpck": flags;
-                  val istrip = _const "Posix_TTY_I_istrip": flags;
-                  val ixoff = _const "Posix_TTY_I_ixoff": flags;
-                  val ixon = _const "Posix_TTY_I_ixon": flags;
-                  val parmrk = _const "Posix_TTY_I_parmrk": flags;
-               end
-
-            structure O =
-               struct
-                  type flags = word
-                  val opost = _const "Posix_TTY_O_opost": flags;
-               end
-
-            structure C =
-               struct
-                  type flags = word
-                  val clocal = _const "Posix_TTY_C_clocal": flags;
-                  val cread = _const "Posix_TTY_C_cread": flags;
-                  val cs5 = _const "Posix_TTY_C_cs5": flags;
-                  val cs6 = _const "Posix_TTY_C_cs6": flags;
-                  val cs7 = _const "Posix_TTY_C_cs7": flags;
-                  val cs8 = _const "Posix_TTY_C_cs8": flags;
-                  val csize = _const "Posix_TTY_C_csize": flags;
-                  val cstopb = _const "Posix_TTY_C_cstopb": flags;
-                  val hupcl = _const "Posix_TTY_C_hupcl": flags;
-                  val parenb = _const "Posix_TTY_C_parenb": flags;
-                  val parodd = _const "Posix_TTY_C_parodd": flags;
-               end
-
-            structure L =
-               struct
-                  type flags = word
-                  val echo = _const "Posix_TTY_L_echo": flags;
-                  val echoe = _const "Posix_TTY_L_echoe": flags;
-                  val echok = _const "Posix_TTY_L_echok": flags;
-                  val echonl = _const "Posix_TTY_L_echonl": flags;
-                  val icanon = _const "Posix_TTY_L_icanon": flags;
-                  val iexten = _const "Posix_TTY_L_iexten": flags;
-                  val isig = _const "Posix_TTY_L_isig": flags;
-                  val noflsh = _const "Posix_TTY_L_noflsh": flags;
-                  val tostop = _const "Posix_TTY_L_tostop": flags;
-               end
-
-            structure TC =
-               struct
-                  type set_action = int
-
-                  val sadrain = _const "Posix_TTY_TC_sadrain": set_action;
-                  val saflush = _const "Posix_TTY_TC_saflush": set_action;
-                  val sanow = _const "Posix_TTY_TC_sanow": set_action;
-
-                  type flow_action = int
-
-                  val ion = _const "Posix_TTY_TC_ion": flow_action;
-                  val ioff = _const "Posix_TTY_TC_ioff": flow_action;
-                  val ooff = _const "Posix_TTY_TC_ooff": flow_action;
-                  val oon = _const "Posix_TTY_TC_oon": flow_action;
-
-                  type queue_sel = int
-
-                  val iflush = _const "Posix_TTY_TC_iflush": queue_sel;
-                  val ioflush = _const "Posix_TTY_TC_ioflush": queue_sel;
-                  val oflush = _const "Posix_TTY_TC_oflush": queue_sel;
-               end                
-
-            structure Termios =
-               struct
-                  type flag = word
-
-                  val iflag = _import "Posix_TTY_Termios_iflag": unit -> flag;
-                  val oflag = _import "Posix_TTY_Termios_oflag": unit -> flag;
-                  val cflag = _import "Posix_TTY_Termios_cflag": unit -> flag;
-                  val lflag = _import "Posix_TTY_Termios_lflag": unit -> flag;
-                  val cc = _import "Posix_TTY_Termios_cc": unit -> cstring;
-                  val ospeed =
-                     _import "Posix_TTY_Termios_cfgetospeed": unit -> speed;
-                  val ispeed =
-                     _import "Posix_TTY_Termios_cfgetispeed": unit -> speed;
-                  val setiflag =
-                     _import "Posix_TTY_Termios_setiflag": flag -> unit;
-                  val setoflag =
-                     _import "Posix_TTY_Termios_setoflag": flag -> unit;
-                  val setcflag =
-                     _import "Posix_TTY_Termios_setcflag": flag -> unit;
-                  val setlflag =
-                     _import "Posix_TTY_Termios_setlflag": flag -> unit;
-                  val setospeed =
-                     _import "Posix_TTY_Termios_setospeed": speed -> int;
-                  val setispeed =
-                     _import "Posix_TTY_Termios_setispeed": speed -> int;
-               end
-
-            val drain = _import "Posix_TTY_drain": fd -> int;
-            val flow = _import "Posix_TTY_flow": fd * TC.flow_action -> int;
-            val flush = _import "Posix_TTY_flush": fd * TC.queue_sel -> int;
-            val getattr = _import "Posix_TTY_getattr": fd -> int;
-            val getpgrp = _import "Posix_TTY_getpgrp": fd -> Pid.t;
-            val sendbreak = _import "Posix_TTY_sendbreak": fd * int -> int;
-            val setattr = _import "Posix_TTY_setattr": fd * TC.set_action -> int;
-            val setpgrp = _import "Posix_TTY_setpgrp": fd * Pid.t -> int;
-         end
-   end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/primitive.mlb
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/primitive.mlb	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/primitive.mlb	2006-01-29 21:06:37 UTC (rev 4328)
@@ -21,7 +21,6 @@
       ../config/c/$(TARGET_ARCH)-$(TARGET_OS)/c-types.sml
    end
    primitive.sml
-   posix-primitive.sml
    ann "forceUsed" in
       basis-ffi.sml
    end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/system/io.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/system/io.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/system/io.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -22,13 +22,13 @@
 
     datatype iodesc_kind = K of string
 
-    type file_desc = PosixPrimitive.FileDesc.t
+    type file_desc = Primitive.FileDesc.t
 
     fun toFD (iod: iodesc): file_desc =
        valOf (Posix.FileSys.iodToFD iod)
 
-    val FD = PosixPrimitive.FileDesc.fromInt
-    val unFD = PosixPrimitive.FileDesc.toInt
+    val FD = Primitive.FileDesc.fromInt
+    val unFD = Primitive.FileDesc.toInt
        
     fun fromInt i = Posix.FileSys.fdToIOD (FD i)
        

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/system/pre-os.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/system/pre-os.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/system/pre-os.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -9,16 +9,16 @@
    struct
       structure Process =
          struct
-            type status = PosixPrimitive.Process.Status.t
+            type status = C.Status.t
          end
       structure IO :> sig
                          eqtype iodesc
 
-                         val fromFD: PosixPrimitive.IO.file_desc -> iodesc
-                         val toFD: iodesc -> PosixPrimitive.IO.file_desc
+                         val fromFD: C.Fd.t -> iodesc
+                         val toFD: iodesc -> C.Fd.t
                       end = 
                       struct
-                         type iodesc = PosixPrimitive.IO.file_desc
+                         type iodesc = C.Fd.t
 
                          val fromFD = fn z => z
                          val toFD = fn z => z

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/system/process.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/system/process.sml	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/system/process.sml	2006-01-29 21:06:37 UTC (rev 4328)
@@ -39,8 +39,8 @@
       fun isSuccess st = st = success
          
       fun system cmd =
-         PosixPrimitive.Process.system (NullString.fromString
-                                        (concat [cmd, "\000"]))
+         PrimitiveFFI.Posix.Process.system (NullString.fromString
+                                            (concat [cmd, "\000"]))
 
       val atExit = MLtonProcess.atExit
          

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/FLock-consts.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/FLock-consts.c	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/FLock-consts.c	2006-01-29 21:06:37 UTC (rev 4328)
@@ -3,3 +3,11 @@
 const C_Int_t Posix_IO_FLock_F_GETLK = F_GETLK;
 const C_Int_t Posix_IO_FLock_F_SETLK = F_SETLK;
 const C_Int_t Posix_IO_FLock_F_SETLKW = F_SETLKW;
+
+const C_Short_t Posix_IO_Flock_F_RDLCK = F_RDLCK;
+const C_Short_t Posix_IO_Flock_F_UNLCK = F_UNLCK;
+const C_Short_t Posix_IO_Flock_F_WRLCK = F_WRLCK;
+
+const C_Short_t Posix_IO_Flock_SEEK_CUR = SEEK_CUR;
+const C_Short_t Posix_IO_Flock_SEEK_END = SEEK_END;
+const C_Short_t Posix_IO_Flock_SEEK_SET = SEEK_SET;

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/fcntl-consts.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/fcntl-consts.c	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/fcntl-consts.c	2006-01-29 21:06:37 UTC (rev 4328)
@@ -2,10 +2,10 @@
 
 const C_Int_t Posix_IO_F_DUPFD = F_DUPFD;
 const C_Int_t Posix_IO_F_GETFD = F_GETFD;
+const C_Int_t Posix_IO_F_GETFL = F_GETFL;
+const C_Int_t Posix_IO_F_GETOWN = F_GETOWN;
 const C_Int_t Posix_IO_F_SETFD = F_SETFD;
-const C_Int_t Posix_IO_F_GETFL = F_GETFL;
 const C_Int_t Posix_IO_F_SETFL = F_SETFL;
-const C_Int_t Posix_IO_F_GETOWN = F_GETOWN;
 const C_Int_t Posix_IO_F_SETOWN = F_SETOWN;
 
 const C_Fd_t Posix_IO_FD_CLOEXEC = FD_CLOEXEC;

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/pipe.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/pipe.c	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/Posix/IO/pipe.c	2006-01-29 21:06:37 UTC (rev 4328)
@@ -1,5 +1,5 @@
 #include "platform.h"
 
-C_Errno_t(C_Int_t) Posix_IO_pipe (Vector(C_Fd_t) fds) {
+C_Errno_t(C_Int_t) Posix_IO_pipe (Array(C_Fd_t) fds) {
   return pipe ((int *) fds);
 }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/Posix/ProcEnv/getgroups.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/Posix/ProcEnv/getgroups.c	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/Posix/ProcEnv/getgroups.c	2006-01-29 21:06:37 UTC (rev 4328)
@@ -1,5 +1,9 @@
 #include "platform.h"
 
+C_Errno_t(C_Int_t) Posix_ProcEnv_getgroupsN (unit) {
+  return getgroups (0, (gid_t*)NULL);
+}
+
 C_Errno_t(C_Int_t) Posix_ProcEnv_getgroups (C_Int_t i, Array(C_GId_t) a) {
   return getgroups (i, (gid_t*)a);
 }

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/Posix/TTY.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/Posix/TTY.c	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/Posix/TTY.c	2006-01-29 21:06:37 UTC (rev 4328)
@@ -18,8 +18,9 @@
   return termios.c_lflag;
 }
 
-C_CC_t Posix_TTY_Termios_getCCN (C_Int_t n) {
-  return termios.c_cc[n];
+void Posix_TTY_Termios_getCC (Array(C_CC_t) a) {
+  for (int i = 0; i < NCCS; i++) 
+    ((cc_t*)a)[i] = termios.c_cc[n];
 }
 
 C_Speed_t Posix_TTY_Termios_cfGetOSpeed (void) {
@@ -46,8 +47,9 @@
   termios.c_lflag = f;
 }
 
-void Posix_TTY_Termios_setCCN (C_Int_t n, C_CC_t c) {
-  termios.c_cc[n] = c;
+void Posix_TTY_Termios_setCC (Array(C_CC_t) a) {
+  for (int i = 0; i < NCCS; i++) 
+    termios.c_cc[n] = ((cc_t*)a)[i];
 }
 
 C_Errno_t(C_Int_t) Posix_TTY_Termios_cfSetOSpeed (C_Speed_t s) {

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gen/basis-ffi.def	2006-01-29 21:06:37 UTC (rev 4328)
@@ -35,7 +35,7 @@
 MLton.Itimer.REAL = _const : C.Int.t
 MLton.Itimer.VIRTUAL = _const : C.Int.t
 MLton.Itimer.set = _import : C.Int.t * C.Time.t * C.SUSeconds.t * C.Time.t * C.SUSeconds.t -> C.Int.t C.Errno.t
-MLton.Process.cwait = _import : C.PId.t * C.Int.t ref -> C.PId.t C.Errno.t
+MLton.Process.cwait = _import : C.PId.t * C.Status.t ref -> C.PId.t C.Errno.t
 MLton.Process.spawne = _import : NullString8.t * NullString8Array.t * NullString8Array.t -> C.Int.t C.Errno.t
 MLton.Process.spawnp = _import : NullString8.t * NullString8Array.t -> C.Int.t C.Errno.t
 MLton.Rlimit.AS = _const : C.Int.t
@@ -327,10 +327,16 @@
 Posix.FileSys.truncate = _import : NullString8.t * C.Off.t -> C.Int.t C.Errno.t
 Posix.FileSys.umask = _import : C.Mode.t -> C.Mode.t
 Posix.FileSys.unlink = _import : NullString8.t -> C.Int.t C.Errno.t
-Posix.IO.FD_CLOEXEC = _const : C.Fd.t
+Posix.IO.FD.CLOEXEC = _const : C.Fd.t
 Posix.IO.FLock.F_GETLK = _const : C.Int.t
 Posix.IO.FLock.F_SETLK = _const : C.Int.t
 Posix.IO.FLock.F_SETLKW = _const : C.Int.t
+Posix.IO.FLock.F_RDLCK = _const : C.Short.t 
+Posix.IO.FLock.F_UNLCK = _const : C.Short.t 
+Posix.IO.FLock.F_WRLCK = _const : C.Short.t 
+Posix.IO.FLock.SEEK_CUR = _const : C.Short.t
+Posix.IO.FLock.SEEK_END= _const : C.Short.t
+Posix.IO.FLock.SEEK_SET = _const : C.Short.t
 Posix.IO.FLock.fcntl = _import : C.Fd.t * C.Int.t -> C.Int.t C.Errno.t
 Posix.IO.FLock.getLen = _import : unit -> C.Off.t
 Posix.IO.FLock.getPId = _import : unit -> C.PId.t
@@ -360,7 +366,7 @@
 Posix.IO.fcntl3 = _import : C.Fd.t * C.Int.t * C.Int.t -> C.Int.t C.Errno.t
 Posix.IO.fsync = _import : C.Fd.t -> C.Int.t C.Errno.t
 Posix.IO.lseek = _import : C.Fd.t * C.Off.t * C.Int.t -> C.Off.t C.Errno.t
-Posix.IO.pipe = _import : C.Fd.t vector -> C.Int.t C.Errno.t
+Posix.IO.pipe = _import : C.Fd.t array -> C.Int.t C.Errno.t
 Posix.IO.readChar8 = _import : C.Fd.t * Char8.t array * C.Int.t * C.Size.t -> C.SSize.t C.Errno.t
 Posix.IO.readWord8 = _import : C.Fd.t * Word8.t array * C.Int.t * C.Size.t -> C.SSize.t C.Errno.t
 Posix.IO.setbin = _import : C.Fd.t -> unit
@@ -508,6 +514,7 @@
 Posix.ProcEnv.geteuid = _import : unit -> C.UId.t
 Posix.ProcEnv.getgid = _import : unit -> C.GId.t
 Posix.ProcEnv.getgroups = _import : C.Int.t * C.GId.t array -> C.Int.t C.Errno.t
+Posix.ProcEnv.getgroupsN = _import : unit -> C.Int.t
 Posix.ProcEnv.getlogin = _import : unit -> C.String.t C.Errno.t
 Posix.ProcEnv.getpgrp = _import : unit -> C.PId.t
 Posix.ProcEnv.getpid = _import : unit -> C.PId.t
@@ -517,7 +524,7 @@
 Posix.ProcEnv.setenv = _import : NullString8.t * NullString8.t -> C.Int.t C.Errno.t
 Posix.ProcEnv.setgid = _import : C.GId.t -> C.Int.t C.Errno.t
 Posix.ProcEnv.setgroups = _import : C.Int.t * C.GId.t vector -> C.Int.t C.Errno.t
-Posix.ProcEnv.setpgid = _import : C.PId.t * C.GId.t -> C.Int.t C.Errno.t
+Posix.ProcEnv.setpgid = _import : C.PId.t * C.PId.t -> C.Int.t C.Errno.t
 Posix.ProcEnv.setsid = _import : unit -> C.PId.t C.Errno.t
 Posix.ProcEnv.setuid = _import : C.UId.t -> C.Int.t C.Errno.t
 Posix.ProcEnv.sysconf = _import : C.Int.t -> C.Long.t C.Errno.t
@@ -702,12 +709,12 @@
 Posix.TTY.Termios.cfGetOSpeed = _import : unit -> C.Speed.t
 Posix.TTY.Termios.cfSetISpeed = _import : C.Speed.t -> C.Int.t C.Errno.t
 Posix.TTY.Termios.cfSetOSpeed = _import : C.Speed.t -> C.Int.t C.Errno.t
-Posix.TTY.Termios.getCCN = _import : C.Int.t -> C.CC.t
+Posix.TTY.Termios.getCC = _import : C.CC.t array -> unit
 Posix.TTY.Termios.getCFlag = _import : unit -> C.TCFlag.t
 Posix.TTY.Termios.getIFlag = _import : unit -> C.TCFlag.t
 Posix.TTY.Termios.getLFlag = _import : unit -> C.TCFlag.t
 Posix.TTY.Termios.getOFlag = _import : unit -> C.TCFlag.t
-Posix.TTY.Termios.setCCN = _import : C.Int.t * C.CC.t -> unit
+Posix.TTY.Termios.setCC = _import : C.CC.t array -> unit
 Posix.TTY.Termios.setCFlag = _import : C.TCFlag.t -> unit
 Posix.TTY.Termios.setIFlag = _import : C.TCFlag.t -> unit
 Posix.TTY.Termios.setLFlag = _import : C.TCFlag.t -> unit

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/platform/linux.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/platform/linux.c	2006-01-28 21:30:43 UTC (rev 4327)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/platform/linux.c	2006-01-29 21:06:37 UTC (rev 4328)
@@ -84,6 +84,6 @@
 /* ------------------------------------------------- */
 
 C_Errno_t(C_PId_t) MLton_Process_cwait (__attribute__ ((unused)) C_PId_t pid, 
-                                        __attribute__ ((unused)) Ref(C_Int_t) status) {
+                                        __attribute__ ((unused)) Ref(C_status_t) status) {
         die("MLton_Process_cwait not implemented");
 }