Basic unix functionality

The BaseUnix unit was implemented by Marco Van de Voort. It contains basic unix functionality. It supersedes the Linux unit of version 1.0.X of the compiler, but does not implement all functionality of the linux unit.

People that have code which heavily uses the old Linux unit, can simply change linux by oldlinux in the uses clause of their projects, but they should really consider moving to the Unix and BaseUnix units.

For porting FPC to new unix-like platforms, it should be sufficient to implement the functionality in this unit for the new platform.

Basic unix types.
C type: 8 bits sized, signed integer.
C type: 8 bits sized, unsigned integer.
C type: 16 bits sized, unsigned integer.
C type: 16 bits sized, signed integer.
C type: 32 bits sized, signed integer.
C type: 32 bits sized, unsigned integer.
C type: 64 bits sized, signed integer.
C type: 64 bits sized, unsigned integer.
C type: unsigned character
C type: integer (natural size)
C type: unsigned integer (natural size)
C type: long signed integer (double sized)
C type: long unsigned integer (double sized)
C type: short signed integer (half sized)
C type: short unsigned integer (half sized)
Pointer to type.
Pointer to type.
Pointer to type.
Pointer to type.
Pointer to type.
Pointer to type.
Device descriptor type.
Alias for type.
Pointer to type.
Group ID type.
Alias for type.
Pointer to type.
Inode type.
Alias for type.
Pointer to type.
Inode mode type.
Alias for type.
Pointer to type.
Number of links type.
Alias for type.
Pointer to type.
Offset type.
Alias for type.
Pointer to type.
Process ID type.
Alias for type.
Pointer to type.
Size specification type.
Alias for type
Pointer to type.
Small size type.
Alias for type
Pointer to type
User ID type
Alias for type.
Pointer to type.
Clock ticks type
Alias for type.
Pointer to type.
Time span type
Alias for type.
Pointer to type.
Pointer to type.
Socket address length type.
Alias for type.
Pointer to type.
Time specification type.
Pointer to type.
Alias for type.
Short time specification type.
Pointer to type.
Alias for type.
Thread mutex type.
Thread conditional variable type.
Posix thread type.
Maximum number of arguments to a program.
Maximum filename length.
Maximum pathname length.
Max system name length.
Maximum system signal number.
System error: Operation not permitted.
System error: No such file or directory
System error: No such process
System error: Interrupted system call
System error: I/O error
System error: No such device or address
System error: Argument list too long
System error: Exec format error
System error: Bad file number
System error: No child processes
System error: Try again
System error: Out of memory
System error: Permission denied
System error: Bad address
System error: Block device required
System error: Device or resource busy
System error: File exists
System error: Cross-device link
System error: No such device
System error: Not a directory
System error: Is a directory
System error: Invalid argument
System error: File table overflow
System error: Too many open files
System error: Not a typewriter
System error: Text (code segment) file busy
System error: File too large
System error: No space left on device
System error: Illegal seek
System error: Read-only file system
System error: Too many links
System error: Broken pipe
System error: Math argument out of domain of func
System error: Math result not representable
System error: Resource deadlock would occur
System error: File name too long
System error: No record locks available
System error: Function not implemented
System error: Directory not empty
System error: Too many symbolic links encountered
System error: Operation would block
System error: No message of desired type
System error: Identifier removed
System error: Channel number out of range
System error: Level 2 not synchronized
System error: Level 3 halted
System error: Level 3 reset
System error: Link number out of range
System error: Protocol driver not attached
System error: No CSI structure available
System error: Level 2 halted
System error: Invalid exchange
System error: Invalid request descriptor
System error: Exchange full
System error: No anode
System error: Invalid request code
System error: Invalid slot
System error: File locking deadlock error
System error: Bad font file format
System error: Device not a stream
System error: No data available
System error: Timer expired
System error: Out of streams resources
System error: Machine is not on the network
System error: Package not installed
System error: Object is remote
System error: Link has been severed
System error: Advertise error
System error: Srmount error
System error: Communication error on send
System error: Protocol error
System error: Multihop attempted
System error: RFS specific error
System error: Not a data message
System error: Value too large for defined data type
System error: Name not unique on network
System error: File descriptor in bad state
System error: Remote address changed
System error: Can not access a needed shared library
System error: Accessing a corrupted shared library
System error: .lib section in a.out corrupted
System error: Attempting to link in too many shared libraries
System error: Cannot exec a shared library directly
System error: Illegal byte sequence
System error: Interrupted system call should be restarted
System error: Streams pipe error
System error: Too many users
System error: Socket operation on non-socket
System error: Destination address required
System error: Message too long
System error: Protocol wrong type for socket
System error: Protocol not available
System error: Protocol not supported
System error: Socket type not supported
System error: Operation not supported on transport endpoint
System error: Protocol family not supported
System error: Address family not supported by protocol
System error: Address already in use
System error: Cannot assign requested address
System error: Network is down
System error: Network is unreachable
System error: Network dropped connection because of reset
System error: Software caused connection abort
System error: Connection reset by peer
System error: No buffer space available
System error: Transport endpoint is already connected
System error: Transport endpoint is not connected
System error: Cannot send after transport endpoint shutdown
System error: Too many references: cannot splice
System error: Connection timed out
System error: Connection refused
System error: Host is down
System error: No route to host
System error: Operation already in progress
System error: Operation now in progress
System error: Stale NFS file handle
System error: Structure needs cleaning
System error: Not a XENIX named type file
System error: No XENIX semaphores available
System error: Is a named type file
System error: Remote I/O error
System error: Quota exceeded
Max length of system name, release, version, machine.
Max length of node name.
Max length of domain name.
Maximum elements in a array.
Number of bits in a word.
Number of words in a signal set.
Number of words in a array
Power of 2 number of bits in word.
Last bit in word.
Block size type.
Block count type.
64-bit inode type.
64-bit offset type.
Alias for type.
Pointer to type.
Alias for type.
pointer to type.
Alias for type.
Pointer to type.
Alias for type.
Pointer to type.
Record used to return kernel information in function.
The elements of this record are null-terminated C style strings, you cannot access them directly.
System name
Computer name
Release number
Version number
Machine type
Domain name
Alias for type.
Pointer to type.
Record describing an inode (file) in the call.
Device number
Pad byte. Do not use
Inode number of file
File mode
Number of links to file.
File owner UID
File owner GID
Pad byte. Do not use
File size
Block size
Number of blocks used
Last access time
Pad byte. Do not use
Last modification time.
Pad byte. Do not use
Creation time
Pad byte. Do not use
Pad byte. Do not use
Pad byte. Do not use
Alias for type.
Pointer to type.
Pointer to record.
Record used in the function to return files in a directory.
Inode number of file
Offset in directory.
Record length
Name of file
Alias for type.
Pointer to record
Record used in and calls
File descriptor. Do not use.
Location in directory listing
File size
Pointer to records
?
?
?
Alias for type.
Record used in to set file access and modificaton times.
Access time
Modification time
Alias for type.
Pointer to type.
Lock description type for lock call.
Type of lock.
Where to measure start of lock from
Start of lock
Length of locked area
Process ID of process holding the lock
Record containing timings for call.
User time.
System time.
Children's user time.
Children's system time.
Alias for record type.
Pointer to type.
File descriptor set for call.
Pointer to type.
call test: read allowed
call test: write allowed
call test: execute allowed
call test: file exists.
option: Set absolute position.
option: Set position relative to current position.
option: Set position relative to end of file.
file open mode: Read only
file open mode: Write only
file open mode: Read/Write
file open mode: Create if file does not yet exist.
file open mode: Open exclusively
file open mode: No TTY control.
file open mode: Truncate file to length 0
file open mode: Append to file
file open mode: Open in non-blocking mode
file open mode: Alias for
file open mode: Write to disc at once
file open mode: Minimize caching effects
file open mode: Open for 64-bit I/O
file open mode: File must be directory.
file open mode: Fail if file is symbolic link.
Mode flag: Set user ID on execution.
Mode flag: Set Group ID on execution.
Mode flag: Set sticky bit.
Mode flag: Read by owner.
Mode flag: Write by owner.
Mode flag: Execute by owner.
Mode flag: Read by group.
Mode flag: Write by group.
Mode flag: Execute by group.
Mode flag: Read by others.
Mode flag: Write by others.
Mode flag: Execute by others.
Mode flag: Read, write, execute by others.
Mode flag: Read, write, execute by groups.
Mode flag: Read, write, execute by user.
option: Do not wait for processes to terminate.
option: Also report children wich were stopped but not yet reported
command: Get close-on-exec flag
command: Set close-on-exec flag
command: Get filedescriptor flags
command: Set filedescriptor flags
command: Get lock
command: Set lock
command: Test lock
command: get owner of filedescriptor events
command: Set owner of filedescriptor events
Sigaction options: Do not receive notification when child processes stop
Sigaction options: ?
Sigaction options: The signal handler takes 3 arguments, not one.
Sigaction options: ?
Sigaction options: Call the signal handler on an alternate signal stack.
Sigaction options: Provide behaviour compatible with BSD signal semantics
Sigaction options: ?
Sigaction options: Do not prevent the signal from being received when it is handled.
Sigaction options: Restore the signal action to the default state.
Sigprocmask flags: Add signals to the set of blocked signals.
Sigprocmask flags: Remove signals from the set set of blocked signals.
Sigprocmask flags: Set of blocked signals is given.
Signal handler: Default signal handler
Signal handler: Ignore signal
Signal handler: error
Signal: HUP (Hangup)
Signal: INT (Interrupt)
Signal: QUIT
Signal: ILL (Illegal instruction)
Signal: TRAP (Trace trap)
Signal: ABRT (Abort)
Signal: IOT (IOT trap)
Signal: BUS (bus error)
Signal: FPE (Floating point error)
Signal: KILL (unblockable)
Signal: USR1 (User-defined signal 1)
Signal: SEGV (Segmentation violation)
Signal: USR2 (User-defined signal 2)
Signal: PIPE (Broken pipe
Signal: ALRM (Alarm clock)
Signal: TERM (Terminate)
Signal: STKFLT (Stack Fault)
Signal: CHLD (child status changed)
Signal: CONT (Continue)
Signal: STOP (Stop, unblockable)
Signal: TSTP (keyboard stop)
Signal: TTIN (Terminal input, background)
Signal: TTOU (Terminal output, background)
Signal: URG (Socket urgent condition)
Signal: XCPU (CPU limit exceeded)
Signal: XFSZ (File size limit exceeded)
Signal: VTALRM (Virtual alarm clock)
Signal: PROF (Profiling alarm)
Signal: WINCH (Window/Terminal size change)
Signal: IO (I/O operation possible)
Signal: POLL (Pollable event)
Signal: PWR (power failure restart)
Signal: Unused
Signal information pad size.
Record describing floating point register in signal handler.
Decimal part of floating point value
Exponent of floating point value
Pointer to record.
Record describing floating point unit in signal handler.
Signal set type
Signal set type
Pointer to type.
Pointer to type.
Alias for type.
Pointer to record type.
Record containing signal information.
Signal number.
?
?
Simple signal handler prototype
Pointer to type.
Signal restorer function prototype
Pointer to type
Extended signal handler prototype.
Record used in call.
Funcion called when signal is triggered.
Signal mask.
Flags for SigAction
Obsolete, don't use
Alias for record type.
Pointer to record type.
Array of IDs
Pointer to array.
Array of file descriptors as used in call.
Pointer to type.
Set list of blocked signals

Changes the list of currently blocked signals. The behaviour of the call depends on How :

SIG_BLOCK
  The set of blocked signals is the union of the current set and the nset argument.
SIG_UNBLOCK
  The signals in nset are removed from the set of currently blocked signals.
SIG_SETMASK
  The list of blocked signals is set so nset.

If oset is non-nil, then the old set is stored in it.

Errno is used to report errors.

sys_efault
  oset
  or nset point to an adress outside the range of the process.
sys_eintr
  System call was interrupted.

Return set of currently pending signals
fpSigpending
allows the examination of pending signals (which have been raised while blocked.) The signal mask of pending signals is returned.
None
Set signal mask and suspend process till signal is received
fpSigSuspend
temporarily replaces the signal mask for the process with the one given in SigMask, and then suspends the process until a signal is received.
None
Set file creation mask.
fpUmask
changes the file creation mask for the current user to cmask. The current mask is returned.
Create a hard link to a file
fpLink
makes NewOne point to the same file als Existing. The two files then have the same inode number. This is known as a 'hard' link. The function returns zero if the call was succesfull, and returns a non-zero value if the call failed.

The following error codes are returned:

sys_exdev
  Existing
  and NewOne are not on the same filesystem.
sys_eperm
  The filesystem containing Existing and NewOne doesn't support linking files.
sys_eaccess
  Write access for the directory containing NewOne is disallowed, or one of the directories in Existing or NewOne has no search (=execute) permission.
sys_enoent
  A directory entry in Existing or NewOne does not exist or is a symbolic link pointing to a non-existent directory.
sys_enotdir
  A directory entry in Existing or NewOne is nor a directory.
sys_enomem
  Insufficient kernel memory.
sys_erofs
  The files are on a read-only filesystem.
sys_eexist
  NewOne
  already exists.
sys_emlink
  Existing
  has reached maximal link count.
sys_eloop
  existing
  or NewOne has a reference to a circular symbolic link, i.e. a symbolic link, whose expansion points to itself.
sys_enospc
  The device containing NewOne has no room for another entry.
sys_eperm
  Existing
  points to . or .. of a directory.

Create FIFO (named pipe) in file system

fpMkFifo creates named a named pipe in the filesystem, with name Path and mode Mode.

The function returns zero if the command was succesful, and nonzero if it failed.

The error codes include:

sys_emfile
  Too many file descriptors for this process.
sys_enfile
  The system file table is full.

Change file permission bits

fpChmod sets the Mode bits of the file in Path to Mode. Mode can be specified by 'or'-ing the following values:

S_ISUID
  Set user ID on execution.
S_ISGID
  Set Group ID on execution.
S_ISVTX
  Set sticky bit.
S_IRUSR
  Read by owner.
S_IWUSR
  Write by owner.
S_IXUSR
  Execute by owner.
S_IRGRP
  Read by group.
S_IWGRP
  Write by group.
S_IXGRP
  Execute by group.
S_IROTH
  Read by others.
S_IWOTH
  Write by others.
S_IXOTH
  Execute by others.
S_IRWXO
  Read, write, execute by others.
S_IRWXG
  Read, write, execute by groups.
S_IRWXU
  Read, write, execute by user.

If the function is successful, zero is returned. A nonzero return value indicates an error.

The following error codes are returned:

sys_eperm
  The effective UID doesn't match the ownership of the file, and is not zero. Owner or group were not specified correctly.
sys_eaccess
  One of the directories in Path has no search (=execute) permission.
sys_enoent
  A directory entry in Path does not exist or is a symbolic link pointing to a non-existent directory.
sys_enomem
  Insufficient kernel memory.
sys_erofs
  The file is on a read-only filesystem.
sys_eloop
  Path
  has a reference to a circular symbolic link, i.e. a symbolic link, whose expansion points to itself.

Change owner of file

fpChown sets the User ID and Group ID of the file in Path to Owner,Group.

The function returns zero if the call was succesfull, a nonzero return value indicates an error.

The following error codes are returned:

sys_eperm
  The effective UID doesn't match the ownership of the file, and is not zero. Owner or group were not specified correctly.
sys_eaccess
  One of the directories in Path has no search (=execute) permission.
sys_enoent
  A directory entry in Path does not exist or is a symbolic link pointing to a non-existent directory.
sys_enomem
  Insufficient kernel memory.
sys_erofs
  The file is on a read-only filesystem.
sys_eloop
  Path
  has a reference to a circular symbolic link, i.e. a symbolic link, whose expansion points to itself.

Set access and modification times of a file (touch).
FpUtime
sets the access and modification times of a file. the times record contains 2 fields, actime, and modtime, both of type Longint. They should be filled with an epoch-like time, specifying, respectively, the last access time, and the last modification time. For some filesystem (most notably, FAT), these times are the same.

Errors are returned in LinuxError.

sys_eaccess
  One of the directories in Path has no search (=execute) permission.
sys_enoent
  A directory entry in Path does not exist or is a symbolic link pointing to a non-existent directory.

Other errors may occur, but aren't documented.

Create a set of pipe file handlers

FpPipe creates a pipe, i.e. two file objects, one for input, one for output. The filehandles are returned in the array fildes. The input handle is in the 0-th element of the array, the output handle is in the 1-st element.

The function returns zero if everything went succesfully, a nonzero return value indicates an error.

In case the function fails, the following return values are possible:

sys_emfile
  Too many file descriptors for this process.
sys_enfile
  The system file table is full.

Duplicate a file handle

FpDup returns a file descriptor that is a duplicate of the file descriptor fildes.

The second and third forms make NewFile an exact copy of OldFile, after having flushed the buffer of OldFile in case it is a Text file or untyped file. Due to the buffering mechanism of Pascal, these calls do not have the same functionality as the dup call in C. The internal Pascal buffers are not the same after this call, but when the buffers are flushed (e.g. after output), the output is sent to the same file. Doing an lseek will, however, work as in C, i.e. doing a lseek will change the fileposition in both files.

The function returns a negative value in case of an error, a positive value is a file handle, and indicates succes.

A negative value can be one of the following error codes:

sys_ebadf
  OldFile
  hasn't been assigned.
sys_emfile
  Maximum number of open files for the process is reached.

Duplicate one filehandle to another

Makes fildes2 or NewFile an exact copy of fildes or OldFile, after having flushed the buffer of OldFile in the case of text or untyped files.

NewFile can be an assigned file. If newfile was open, it is closed first. Due to the buffering mechanism of Pascal, this has not the same functionality as the dup2 call in C. The internal Pascal buffers are not the same after this call, but when the buffers are flushed (e.g. after output), the output is sent to the same file. Doing an lseek will, however, work as in C, i.e. doing a lseek will change the fileposition in both files.

The function returns zero if succesful, a nonzero return value means the call failed.

In case of error, the following error codes can be reported:

sys_ebadf
  OldFile
  (or fildes) hasn't been assigned.
sys_emfile
  Maximum number of open files for the process is reached.

Return execution times for the current process

fpTimes stores the execution time of the current process and child processes in buffer.

The return value (on linux) is the number of clock ticks since boot time. On error, -1 is returned, and extended error information can be retrieved with .

Schedule an alarm signal to be delivered

FpAlarm schedules an alarm signal to be delivered to your process in Seconds seconds. When Seconds seconds have elapsed, the system will send a SIGALRM signal to the current process. If Seconds is zero, then no new alarm will be set. Whatever the value of Seconds, any previous alarm is cancelled.

The function returns the number of seconds till the previously scheduled alarm was due to be delivered, or zero if there was none. A negative value indicates an error.

Wait for a signal to arrive

FpPause puts the process to sleep and waits until the application receives a signal. If a signal handler is installed for the received sigal, the handler will be called and after that pause will return control to the process.

For an example, see .

Suspend process for several seconds

FpSleep suspends the process till a time period as specified in seconds has passed, then the function returns. If the call was interrupted (e.g. by some signal) then the function may return earlier, and the return value is the remaining time till the end of the intended period.

If the function returns without error, the return value is zero.

Return current process ID
FpGetpid
returns the Process ID of the currently running process.
None.
Return parent process ID
FpGetppid
returns the Process ID of the parent process.
None.
Return current user ID
FpGetuid
returns the real user ID of the currently running process.
None.
Return effective user ID
FpGeteuid
returns the effective user ID of the currently running process.
None.
Return real group ID
FpGetgid
returns the real group ID of the currently running process.
None.
Return effective group ID
FpGetegid
returns the effective group ID of the currently running process.
None.
Set the current user ID

fpSetUID sets the user ID of the current process. This call will only work if it is executed as root, or the program is setuid root.

On success, zero is returned, on error -1 is returned.

Extended error information can be retrieved with .
Set the current group ID

fpSetUID sets the group ID of the current process. This call will only work if it is executed as root, or the program is setgid root.

On success, zero is returned, on error -1 is returned.

Extended error information can be retrieved with .
Get the list of supplementary groups.

FpGetgroups returns up to gidsetsize groups in GroupList

If the function is successful, then number of groups that were stored is returned. On error, -1 is returned.

On error, -1 is returned. Extended error information can be retrieved with
Get process group ID
FpGetpgrp
returns the process group ID of the current process.
None.
Create a new session.
FpSetsid
creates a new session (process group). It returns the new process group id (as returned by . This call will fail if the current process is already the process group leader.
On error, -1 is returned. Extended error information can be retrieved with
File control operations.

Read/set a file's attributes. Fildes a valid file descriptor. Cmd speciefies what to do, and is one of the following:

F_GetFd
  Read the close_on_exec flag. If the low-order bit is 0, then the file will remain open across execve calls.
F_GetFl
  Read the descriptor's flags.
F_GetOwn
  Get the Process ID of the owner of a socket.
F_SetFd
  Set the close_on_exec flag of fildes. (only the least siginificant bit is used).
F_GetLk
  Return the flock record that prevents this process from obtaining the lock, or set the l_type field of the lock of there is no obstruction. Arg is the flock record.
F_SetLk
  Set the lock or clear it (depending on l_type in the flock structure). if the lock is held by another process, an error occurs.
F_GetLkw
  Same as for F_Setlk, but wait until the lock is released.
F_SetOwn
  Set the Process or process group that owns a socket.

The function returns 0 if successful, -1 otherwise.

On error, -1 is returned. Use for extended error information.

sys_ebadf
  Fd
  has a bad file descriptor.
sys_eagain or sys_eaccess
  For \textbf{F_SetLk}, if the lock is held by another process.

Retrieve the current working directory.

fpgetCWD returns the current working directory of the running process. It is returned in Path, which points to a memory location of at least siz bytes.

If the function is succesful, a pointer to Path is returned, or a string with the result. On error Nil or an empty string are returned.

On error Nil or an empty string are returned.
Create child process
FpFork
creates a child process which is a copy of the parent process. FpFork returns the process ID in the parent process, and zero in the child's process. (you can get the parent's PID with ).

On error, -1 is returned to the parent, and no child is created.

sys_eagain
  Not enough memory to create child process.

Execute process using environment
Replaces the currently running program with the program, specified in path. It gives the program the options in argv, and the environment in envp. They are pointers to an array of pointers to null-terminated strings. The last pointer in this array should be nil. On success, execve does not return.

Extended error information can be retrieved with , and includes the following:

sys_eacces
  File is not a regular file, or has no execute permission. A compononent of the path has no search permission.
sys_eperm
  The file system is mounted \textit{noexec}.
sys_e2big
  Argument list too big.
sys_enoexec
  The magic number in the file is incorrect.
sys_enoent
  The file does not exist.
sys_enomem
  Not enough memory for kernel.
sys_enotdir
  A component of the path is not a directory.
sys_eloop
  The path contains a circular reference (via symlinks).

Execute process
Replaces the currently running program with the program, specified in path. It gives the program the options in argvp. This is a pointer to an array of pointers to null-terminated strings. The last pointer in this array should be nil. The current environment is passed to the program. On success, execv does not return.

Errors are reported in LinuxError:

sys_eacces
  File is not a regular file, or has no execute permission. A compononent of the path has no search permission.
sys_eperm
  The file system is mounted \textit{noexec}.
sys_e2big
  Argument list too big.
sys_enoexec
  The magic number in the file is incorrect.
sys_enoent
  The file does not exist.
sys_enomem
  Not enough memory for kernel.
sys_enotdir
  A component of the path is not a directory.
sys_eloop
  The path contains a circular reference (via symlinks).

Wait for a process to terminate

fpWaitPid waits for a child process with process ID Pid to exit. The value of Pid can be one of the following:

Pid < -1
  Causes fpWaitPid to wait for any child process whose process group ID equals the absolute value of pid.
Pid = -1
  Causes fpWaitPid to wait for any child process.
Pid = 0
  Causes fpWaitPid to wait for any child process whose process group ID equals the one of the calling process.
Pid > 0
  Causes fpWaitPid to wait for the child whose process ID equals the value of Pid.

The Options parameter can be used to specify further how fpWaitPid behaves:

WNOHANG
  Causes fpWaitpid to return immediately if no child hasexited.
WUNTRACED
  Causes fpWaitPid to return also for children which are stopped, but whose status has not yet been reported.
__WCLONE
  Causes fpWaitPid also to wait for threads created by the call.

The exit status of the process that caused fpWaitPID is reported in stat_loc or Status.

Upon return, it returns the process id of the process that exited, 0 if no process exited, or -1 in case of failure.

For an example, see .

Extended error information can be retrieved using .
Wait for a child to exit.

fpWait suspends the current process and waits for any child to exit or stop due to a signal. It reports the exit status of the exited child in stat_loc.

The return value of the function is the process ID of the child that exited, or -1 on error.

Extended error information can be retrieved using .
Exit the current process

FpExit exits the currently running process, and report Status as the exit status.

If this call is executed, the normal unit finalization code will not be executed. This may lead to unexpected errors and stray files on your system. It is therefore recommended to use the Halt call instead.
None.
Send a signal to a process

fpKill sends a signal Sig to a process or process group. If Pid>0 then the signal is sent to Pid, if it equals -1, then the signal is sent to all processes except process 1. If Pid<-1 then the signal is sent to process group -Pid.

The return value is zero, except in case three, where the return value is the number of processes to which the signal was sent.

Extended error information can be retrieved using :

sys_einval
  An invalid signal is sent.
sys_esrch
  The Pid or process group don't exist.
sys_eperm
  The effective userid of the current process doesn't math the one of process Pid.

Return system name.

Uname gets the name and configuration of the current linux kernel, and returns it in the name record.

On success, 0 is returned, on error, -1 is returned.

Extended error information can be retrieved using .
Open a directory for reading
FpOpenDir
opens the directory DirName, and returns a pdir pointer to a record, which can be used to read the directory structure. If the directory cannot be opened, nil is returned.
Extended error information can be retrieved using .
Read entry from directory

FpReadDir reads the next entry in the directory pointed to by dirp. It returns a pdirent pointer to a record describing the entry. If the next entry can't be read, Nil is returned.

For an example, see .

Extended error information can be retrieved using .
Close directory file descriptor

FpCloseDir closes the directory pointed to by dirp. It returns zero if the directory was closed succesfully, -1 otherwise.

For an example, see .

Extended error information can be retrieved using .
Change current working directory.

fpChDir sets the current working directory to Path.

It returns zero if the call was succesful, -1 on error.

Extended error information can be retrieved using .
Open file and return file descriptor

FpOpen opens a file in Path with flags flags and mode Mode One of the following:

O_RdOnly
  File is opened Read-only
O_WrOnly
  File is opened Write-only
O_RdWr
  File is opened Read-Write

The flags may beOR-ed with one of the following constants:

O_Creat
  File is created if it doesn't exist.
O_Excl
  If the file is opened with O_Creat and it already exists, the call wil fail.
O_NoCtty
  If the file is a terminal device, it will NOT become the process' controlling terminal.
O_Trunc
  If the file exists, it will be truncated.
O_Append
  the file is opened in append mode. Before each write, the file pointer is positioned at the end of the file.
O_NonBlock
  The file is opened in non-blocking mode. No operation on the file descriptor will cause the calling process to wait till.
O_NDelay
  Idem as O_NonBlock
O_Sync
  The file is opened for synchronous IO. Any write operation on the file will not return untill the data is physically written to disk.
O_NoFollow
  if the file is a symbolic link, the open fails. (linux 2.1.126 and higher only)
O_Directory
  if the file is not a directory, the open fails. (linux 2.1.126 and higher only)

Path can be of type PChar or String. The optional mode argument specifies the permissions to set when opening the file. This is modified by the umask setting. The real permissions are Mode and not umask. The return value of the function is the filedescriptor, or a negative value if there was an error.

Extended error information can be retrieved using .
Create a new directory

FpMkDir creates a new directory Path, and sets the new directory's mode to Mode. Path can be an absolute path or a relative path. Note that only the last element of the directory will be created, higher level directories must already exist, and must be writeable by the current user.

On succes, 0 is returned. if the function fails, -1 is returned.

Extended error information can be retrieved using .
Unlink (i.e. remove) a file.

FpUnLink decreases the link count on file Path. Path can be of type AnsiString or PChar. If the link count is zero, the file is removed from the disk.

The function returns zero if the call was succesfull, a nonzero value indicates failure.

For an example, see .

Extended error information can be retrieved using .

sys_eaccess
  You have no write access right in the directory containing Path, or you have no search permission in one of the directory components of Path.
sys_eperm
  The directory containing pathname has the sticky-bit set and the process's effective uid is neither the uid of the file to be deleted nor that of the directory containing it.
sys_enoent
  A component of the path doesn't exist.
sys_enotdir
  A directory component of the path is not a directory.
sys_eisdir
  Path
  refers to a directory.
sys_enomem
  Insufficient kernel memory.
sys_erofs
  Path
  is on a read-only filesystem.

Remove a directory.

FpRmdir removes the directory Path from the system. The directory must be empty for this call to succeed, and the user must have the necessary permissions in the parent directory. Only the last component of the directory is removed, i.e. higher-lying directories are not removed.

On success, zero is returned. A nonzero return value indicates failure.

Extended error information can be retrieved using .
Rename file

FpRename renames the file Old to NewPath. NewPath can be in a different directory than Old, but it cannot be on another partition (device). Any existing file on the new location will be replaced.

If the operation fails, then the Old file will be preserved.

The function returns zero on succes, a nonzero value indicates failure.

Extended error information can be retrieved using .

sys_eisdir
  NewPath
  exists and is a directory, but Old is not a directory.
sys_exdev
  NewPath
  and Old are on different devices.
sys_enotempty or sys_eexist
  NewPath
  is an existing, non-empty directory.
sys_ebusy
  Old
  or NewPath is a directory and is in use by another process.
sys_einval
  NewPath
  is part of Old.
sys_emlink
  OldPath
  or NewPath already have tha maximum amount of links pointing to them.
sys_enotdir
  part of Old or NewPath is not directory.
sys_efault
  For the pchar case: One of the pointers points to an invalid address.
sys_eaccess
  access is denied when attempting to move the file.
sys_enametoolong
  Either Old or NewPath is too long.
sys_enoent
  a directory component in Old or NewPath didn't exist.
sys_enomem
  not enough kernel memory.
sys_erofs
  NewPath
  or Old is on a read-only file system.
sys_eloop
  too many symbolic links were encountered trying to expand Old or NewPath
sys_enospc
  the filesystem has no room for the new directory entry.

Retrieve file information about a file descriptor.

FpFStat gets information about the file specified in one of the following:

Fd
  a valid file descriptor.
F
  an opened text file or untyped file.

and stores it in Info, which is of type . The function returns zero if the call was succesfull, a nonzero return value indicates failure.

Extended error information can be retrieved using .

sys_enoent
  Path
  does not exist.

Retrieve file information about a file descriptor.

FpFStat gets information about the file specified in Path, and stores it in Info, which is of type . The function returns zero if the call was succesfull, a nonzero return value indicates failure.

Extended error information can be retrieved using .

sys_enoent
  Path
  does not exist.

Check file access

FpAccess tests user's access rights on the specified file. Mode is a mask existing of one or more of the following:

R_OK
  User has read rights.
W_OK
  User has write rights.
X_OK
  User has execute rights.
F_OK
  File exists.

The test is done with the real user ID, instead of the effective user ID. If the user has the requested rights, zero is returned. If access is denied, or an error occurred, a nonzero value is returned.

Extended error information can be retrieved using .

sys_eaccess
  The requested access is denied, either to the file or one of the directories in its path.
sys_einval
  Mode
  was incorrect.
sys_enoent
  A directory component in Path doesn't exist or is a dangling symbolic link.
sys_enotdir
  A directory component in Path is not a directory.
sys_enomem
  Insufficient kernel memory.
sys_eloop
  Path
  has a circular symbolic link.

Close file descriptor

FpClose closes a file with file descriptor Fd. The function returns zero if the file was closed successfully, a nonzero return value indicates an error.

For an example, see .

Extended error information can be retrieved using .
Read data from file descriptor

FpdRead reads at most nbytes bytes from the file descriptor fd, and stores them in buf.

The function returns the number of bytes actually read, or -1 if an error occurred. No checking on the length of buf is done.

Extended error information can be retrieved using .
Write data to file descriptor

FpWrite writes at most nbytes bytes from buf to file descriptor fd.

The function returns the number of bytes actually written, or -1 if an error occurred.

Extended error information can be retrieved using .
Set file pointer position.

FpLSeek sets the current fileposition of file fd to Offset, starting from Whence, which can be one of the following:

Seek_Set
  Offset
  is the absolute position in the file.
Seek_Cur
  Offset
  is relative to the current position.
Seek_end
  Offset
  is relative to the end of the file.

The function returns the new fileposition, or -1 of an error occurred.

For an example, see .

Extended error information can be retrieved using .
Return the current unix time

FpTime returns the number of seconds since 00:00:00 GMT, january 1, 1970. it is adjusted to the local time zone, but not to DST. The result is also stored in tloc, if it is specified.

On error, -1 is returned. Extended error information can be retrieved using .
Truncate file on certain size.

FpFTruncate sets the length of a file in fd on flength bytes, where flength must be less than or equal to the current length of the file in fd.

The function returns zero if the call was successful, a nonzero return value indicates that an error occurred.

Extended error information can be retrieved using .
Install signal handler

FPSigaction changes the action to take upon receipt of a signal. Act and Oact are pointers to a record. Sig specifies the signal, and can be any signal except SIGKILL or SIGSTOP.

If Act is non-nil, then the new action for signal Sig is taken from it. If OAct is non-nil, the old action is stored there. Sa_Handler may be SIG_DFL for the default action or SIG_IGN to ignore the signal. Sa_Mask Specifies which signals should be ignord during the execution of the signal handler. Sa_Flags Speciefies a series of flags which modify the behaviour of the signal handler. You can 'or' none or more of the following :

SA_NOCLDSTOP
  If sig is SIGCHLD do not receive notification when child processes stop.
SA_ONESHOT or SA_RESETHAND
  Restore the signal action to the default state once the signal handler has been called.
SA_RESTART
  For compatibility with BSD signals.
SA_NOMASK or SA_NODEFER
  Do not prevent the signal from being received from within its own signal handler.

Extended error information can be retrieved using .

sys_einval
  an invalid signal was specified, or it was SIGKILL or SIGSTOP.
sys_efault
  Act,OldAct
  point outside this process address space
sys_eintr
  System call was interrupted.

Wait for events on file descriptors

FpSelect checks one of the file descriptors in the FDSets to see if its status changed.

readfds, writefds and exceptfds are pointers to arrays of 256 bits. If you want a file descriptor to be checked, you set the corresponding element in the array to 1. The other elements in the array must be set to zero. Three arrays are passed : The entries in readfds are checked to see if characters become available for reading. The entries in writefds are checked to see if it is OK to write to them, while entries in exceptfds are cheked to see if an exception occorred on them.

You can use the functions , , or to manipulate the individual elements of a set.

The pointers can be Nil.

N is the largest index of a nonzero entry plus 1. (= the largest file-descriptor + 1).

TimeOut can be used to set a time limit. If TimeOut can be two types :

1. TimeOut
   is of type ptimeval and contains a zero time, the call returns immediately. If TimeOut is Nil, the kernel will wait forever, or until a status changed.
2. TimeOut
   is of type cint. If it is -1, this has the same effect as a Timeout of type PTime which is Nil. Otherwise, TimeOut contains a time in milliseconds.

When the TimeOut is reached, or one of the file descriptors has changed, the Select call returns. On return, it will have modified the entries in the array which have actually changed, and it returns the number of entries that have been changed. If the timout was reached, and no decsriptor changed, zero is returned; The arrays of indexes are undefined after that. On error, -1 is returned.

The variant with the text file will execute the FpSelect call on the file descriptor associated with the text file T

On error, the function returns -1. Extended error information can be retrieved using .

SYS_EBADF
  An invalid descriptor was specified in one of the sets.
SYS_EINTR
  A non blocked signal was caught.
SYS_EINVAL
  N
  is negative or too big.
SYS_ENOMEM
  Select
  was unable to allocate memory for its internal tables.

General kernel IOCTL call.
This is a general interface to the Unix/ linux ioctl call. It performs various operations on the filedescriptor Handle. Ndx describes the operation to perform. Data points to data needed for the Ndx function. The structure of this data is function-dependent, so we don't elaborate on this here. For more information on this, see various manual pages under linux.
Extended error information can be retrieved using .
Suspend process for a short time

FpNanoSleep suspends the process till a time period as specified in req has passed. Then the function returns. If the call was interrupted (e.g. by some signal) then the function may return earlier, and rem will contain the remaining time till the end of the intended period. In this case the return value will be -1, and LinuxError will be set to EINTR

If the function returns without error, the return value is zero.

If an error occurred or the call was interrupted, -1 is returned. Extended error information can be retrieved using .
Return value of environment variable.

FPGetEnv returns the value of the environment variable in Name. If the variable is not defined, nil is returned. The value of the environment variable may be the empty string. A PChar is returned to accomodate for strings longer than 255 bytes, TERMCAP and LS_COLORS, for instance.

None.
Set access and modification times of a file (touch).

FpUtime sets the access and modification times of the file specified in Path. the times record contains 2 fields, actime, and modtime, both of type time_t (commonly a longint). They should be filled with an epoch-like time, specifying, respectively, the last access time, and the last modification time. For some filesystem (most notably, FAT), these times are the same.

The function returns zero on success, a nonzero return value indicates failure.

Extended error information can be retrieved using .

sys_eaccess
  One of the directories in Path has no search (=execute) permission.
sys_enoent
  A directory entry in Path does not exist or is a symbolic link pointing to a non-existent directory.

Other errors may occur, but aren't documented.

Install signal handler (deprecated)

FPSignal installs a new signal handler (specified by Handler) for signal SigNum.

This call has a subset of the functionality provided by the call. The return value for FpSignal is the old signal handler, or nil on error.

Extended error information can be retrieved using .

SIG_ERR
  An error occurred.

Set a filedescriptor in a set

FpFD_Set sets file descriptor fdno in filedescriptor set nset.

For an example, see .

None.
Clears a filedescriptor in a set

FpFD_Clr clears file descriptor fdno in filedescriptor set nset.

For an example, see .

None.
,
Clear all file descriptors in set

FpFD_ZERO clears all the filedescriptors in the file descriptor set nset.

For an example, see .

None.
Check whether a filedescriptor is set

FpFD_Set Checks whether file descriptor fdNo in filedescriptor set fds is set. It returns zero if the descriptor is not set, 1 if it is set. If the number of the filedescriptor it wrong, -1 is returned.

For an example, see .

If an invald file descriptor number is passed, -1 is returned.
Set all filedescriptors in the set.
fpfdfillset
sets all filedescriptors in nset.
Clear all signals from signal set.
FpSigEmptySet
clears all signals from the signal set nset.
None. This function always returns zero.
Set all signals in signal set.
FpSigFillSet
sets all signals in the signal set nset.
None. This function always returns zero.
Set a signal in a signal set.
FpSigAddSet
adds signal Signo to the signal set nset. The function returns 0 on success.
If an invalid signal number is given, -1 is returned.
Remove a signal from a signal set.
FpSigDelSet
removes signal Signo to the signal set nset. The function returns 0 on success.
If an invalid signal number is given, -1 is returned.
Check whether a signal appears in a signal set.
FpSigIsMember
checks whether SigNo appears in the set nset. If it is a member, then 1 is returned. If not, zero is returned.
If an invalid signal number is given, -1 is returned.
Is file a directory
fpS_ISDIR
checks the file mode m to see whether the file is a directory. If so, it returns True
Is file a character device
FpS_ISCHR
checks the file mode m to see whether the file is a character device file. If so it returns True.
Is file a block device
FpS_ISBLK
checks the file mode m to see whether the file is a block device file. If so it returns True.
Is file a regular file
FpS_ISREG
checks the file mode m to see whether the file is a regular file. If so it returns True
Is file a FIFO
FpS_ISFIFO
checks the file mode m to see whether the file is a fifo (a named pipe). If so it returns True.
Is file a symbolic link
FpS_ISLNK
checks the file mode m to see whether the file is a symbolic link. If so it returns True
Is file a unix socket
FpS_ISSOCK
checks the file mode m to see whether the file is a socket. If so it returns True.
Extract the exit status from the fpWaitPID result.
WEXITSTATUS
can be used to extract the exit status from Status, the result of the call.
Return the signal that caused a process to exit.
WTERMSIG
extracts from Status the signal number which caused the process to exit.
Return the exit code from the process.
WSTOPSIG
is an alias for .
Check whether the process exited normally
WIFEXITED
checks Status and returns True if the status indicates that the process terminated normally, i.e. was not stopped by a signal.
Check whether the process was exited by a signal.
WIFSIGNALED
returns True if Status indicates that the process exited because it received a signal.
Retrieve extended error information.
fpgeterrno
returns extended information on the latest error. It is set by all functions that communicate with the kernel or C library.
None.
Set extended error information.

fpseterrno sets the extended information on the latest error. It is called by all functions that communicate with the kernel or C library.

Unless a direct kernel call is performed, there should never be any need to call this function.