Posix.IO
structureThe structure Posix.IO specifies functions that provide the primitive POSIX input/output operations, as described in Section 6 of the POSIX standard [CITE]1003.1,1996/.
signature POSIX_IO
structure IO
: POSIX_IO
eqtype file_desc
eqtype pid
val pipe : unit -> {infd : file_desc, outfd : file_desc}
val dup : file_desc -> file_desc
val dup2 : {old : file_desc, new : file_desc} -> unit
val close : file_desc -> unit
val readVec : (file_desc * int) -> Word8Vector.vector
val readArr : (file_desc * {buf : Word8Array.array, i : int, sz : int option}) -> int
val writeVec : (file_desc * {buf : Word8Vector.vector, i : int, sz : int option}) -> int
val writeArr : (file_desc * {buf : Word8Array.array, i : int, sz : int option}) -> int
datatype whence
= SEEK_SET
| SEEK_CUR
| SEEK_END
structure FD : sig
include POSIX_FLAGS
val cloexec : flags
end
structure O : sig
include POSIX_FLAGS
val append : flags
val nonblock : flags
val sync : flags
end
datatype open_mode
= O_RDONLY
| O_WRONLY
| O_RDWR
val dupfd : {old : file_desc, base : file_desc} -> file_desc
val getfd : file_desc -> FD.flags
val setfd : (file_desc * FD.flags) -> unit
val getfl : file_desc -> (O.flags * open_mode)
val setfl : (file_desc * O.flags) -> unit
val lseek : (file_desc * Position.int * whence) -> Position.int
val fsync : file_desc -> unit
datatype lock_type
= F_RDLCK
| F_WRLCK
| F_UNLCK
structure FLock : sig
type flock
val flock : {ltype : lock_type, whence : whence, start : Position.int, len : Position.int, pid : pid option} -> flock
val ltype : flock -> lock_type
val whence : flock -> whence
val start : flock -> Position.int
val len : flock -> Position.int
val pid : flock -> pid option
end
val getlk : (file_desc * FLock.flock) -> FLock.flock
val setlk : (file_desc * FLock.flock) -> FLock.flock
val setlkw : (file_desc * FLock.flock) -> FLock.flock
eqtype file_desc
eqtype pid
pipe ()
dup fd
dupfd {old=fd, base=Posix.FileSys.wordToFD 0w0}
.
dup2 {old, new}
close fd
readVec (fd, n)
readArr (fd, {buf, i, sz})
SOME(sz)
bytes from file fd into buffer buf starting at buffer position i. Returns the number of bytes actually read. If sz is NONE, reads as many bytes as are available up to the number of bytes that can be placed in buffer starting at buffer position i. Raises Subscript if buffer bounds are violated.
writeVec (fd, {buf, i, sz})
SOME(sz)
bytes from the vector buf, starting from position i, to the open file fd. If sz is NONE, writes the bytes from position i to the end of the buffer. Returns the number of bytes actually written. Raises Subscript if buffer bounds are violated.
writeArr (fd, {buf, i, sz})
SOME(sz)
bytes from the array buf, starting from position i, to the open file fd. If sz is NONE, writes the bytes from position i to the end of the buffer. Returns the number of bytes actually written. Raises Subscript if buffer bounds are violated.
datatype whence
structure FD
cloexec
fd
, will close fd
should the opening process replace itself (through exec
, etc.). If cloexec is not set, the file associated with fd
will remain open in the new process.
structure O
append
nonblock
sync
datatype open_mode
dupfd {old, base}
fcntl
function with the F_DUPFD
command.
getfd fd
fcntl
function with the F_GETFD
command.
setfd (fd, fl)
fcntl
function with the F_SETFD
command.
getfl fd
fcntl
function with the F_GETFL
command.
setfl (fd, fl)
fcntl
function with the F_SETFL
command.
lseek (fd, off, wh)
fsync fd
datatype lock_type
structure FLock
type flock
flock {ltype, whence, start, len, pid}
ltype fl
ltype
field for flock fl.
whence fl
whence
field for flock fl.
start fl
start
field for flock fl.
len fl
len
field for flock fl.
pid fl
pid
field for flock fl.
getlk (fd, fl)
fcntl
function with the F_GETLK
command.
setlk (fd, fl)
fcntl
function with the F_SETLK
command.
setlkw (fd, fl)
fcntl
function with the F_SETLKW
command.
Many POSIX I/O functions can raise OS.SysErr. The above descriptions do not describe the particular system errors a function may raise; for now, consult more detailed POSIX documentation.
POSIX_FLAGS, Posix, Posix.IO, Posix.FileSys, Posix.Error, OS
Last Modified April 17, 1996
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies