Posix_unistdPOSIX unistd.h bindings with OCaml-friendly API
This module provides comprehensive bindings to POSIX unistd.h functions, with a user-friendly OCaml interface. Functions are wrapped to use standard OCaml types where appropriate and integrate with the Unix module.
Most functions return option types: Some value on success, None on error (with errno set appropriately via Errno_unix).
read fd buf ofs len reads up to len bytes from fd into buf starting at offset ofs. Returns Some n where n is the number of bytes read, or None on error.
write fd buf ofs len writes up to len bytes from buf starting at offset ofs to fd. Returns Some n where n is the number of bytes written, or None on error.
pread fd buf ofs len offset reads up to len bytes from fd at file offset offset into buf starting at ofs. Does not change the file offset. Returns Some n or None on error.
pwrite fd buf ofs len offset writes up to len bytes to fd at file offset offset from buf starting at ofs. Does not change the file offset. Returns Some n or None on error.
dup2 fd1 fd2 duplicates fd1 to fd2, closing fd2 first if necessary.
pipe () creates a pipe and returns (read_end, write_end).
fdatasync fd synchronizes file data (but not necessarily metadata) to disk.
symlink ~target ~link_name creates a symbolic link.
fchdir fd changes the current working directory to the directory referenced by fd.
val lseek : Unix.file_descr -> int -> seek_command -> intlseek fd offset whence repositions the file offset.
val access : string -> access_permission list -> boolaccess path perms checks whether the calling process can access the file path with the specified permissions.
fchown fd uid gid changes file ownership using a file descriptor.
lchown path uid gid changes ownership of a symbolic link itself.
ftruncate fd length truncates a file to specified length using a file descriptor.
val lockf : Unix.file_descr -> lock_command -> int -> unitlockf fd cmd size applies, tests, or removes a POSIX lock on a section of a file.
fork () creates a new process. Returns Some 0 in the child, Some pid in the parent where pid is the child's process ID.
pathconf path name gets path configuration value. Use pc_* constants.
fpathconf fd name gets path configuration value for an open file.
sleep seconds sleeps for specified number of seconds. Returns 0 on completion, or number of seconds remaining if interrupted.
alarm seconds sets an alarm clock. Returns seconds remaining from a previous alarm, or 0 if no previous alarm.
ttyname_r ?len fd thread-safe version of ttyname.
tcgetpgrp fd returns the process group ID of the foreground process group associated with the terminal.
tcsetpgrp fd pgrp sets the foreground process group ID associated with the terminal to pgrp.
execv path args executes a program with specified arguments. Only returns on error (by raising an exception).
execve path args env executes a program with specified arguments and environment. Only returns on error (by raising an exception).
execvp file args executes a program using PATH to find the executable. Only returns on error (by raising an exception).