A system function can fail for a variety of reasons. For example, a
file operation may fail because lack of disk space, or the process
does not have permission to perform the operation. Such functions
will return -1 and set the variable errno to an error
code describing the reason for failure.
Particular values of errno may be specified by the following
symbolic constants (read-only variables) and the corresponding
errno_string value:
EPERM "Not owner"
ENOENT "No such file or directory"
ESRCH "No such process"
ENXIO "No such device or address"
ENOEXEC "Exec format error"
EBADF "Bad file number"
ECHILD "No children"
ENOMEM "Not enough core"
EACCES "Permission denied"
EFAULT "Bad address"
ENOTBLK "Block device required"
EBUSY "Mount device busy"
EEXIST "File exists"
EXDEV "Cross-device link"
ENODEV "No such device"
ENOTDIR "Not a directory"
EISDIR "Is a directory"
EINVAL "Invalid argument"
ENFILE "File table overflow"
EMFILE "Too many open files"
ENOTTY "Not a typewriter"
ETXTBSY "Text file busy"
EFBIG "File too large"
ENOSPC "No space left on device"
ESPIPE "Illegal seek"
EROFS "Read-only file system"
EMLINK "Too many links"
EPIPE "Broken pipe"
ELOOP "Too many levels of symbolic links"
ENAMETOOLONG "File name too long"
Example
The mkdir function will attempt to create a directory. If
that directory already exists, the function will fail and set
errno to EEXIST.
The errno_string function returns a string describing the
integer error code err. The variable err usually
corresponds to the errno intrinsic function. See the
description for errno for more information.
Example
The errno_string function may be used as follows:
define sizeof_file (file)
{
variable st = stat (file);
if (st == NULL)
verror ("%s: %s", file, errno_string (errno);
return st.st_size;
}
This function may be used to send a signal given by the integer sig
to the process specified by pid. The function returns zero upon
sucess and -1 upon failure setting errno accordingly.
Example
The kill function may be used to determine whether or not
a specific process exists:
define process_exists (pid)
{
if (-1 == kill (pid, 0))
return 0; % Process does not exist
return 1;
}
The mkfifo attempts to create a named pipe with the specified
name and mode (modified by the process's umask). The function
returns 0 upon success, or -1 and sets errno upon failure.
Notes
Not all systems support the mkfifo function and even on
systems that do implement the mkfifo system call, the
underlying file system may not support the concept of a named pipe,
e.g, an NFS filesystem.
The setpgid function sets the group-id gid of the
process whose process-id is pid. If pid is 0, then the
current process-id will be used. If pgid is 0, then the pid
of the affected process will be used.
If successful zero will be returned, otherwise the function will
return -1 and set errno accordingly.
The system function may be used to execute the string
expression cmd in an inferior shell. This function is an
interface to the C system function which returns an
implementation-defined result. On Linux, it returns 127 if the
inferior shell could not be invoked, -1 if there was some other
error, otherwise it returns the return code for cmd.
Example
define dir ()
{
() = system ("DIR");
}
displays a directory listing of the current directory under MSDOS or
VMS.
The uname function returns a structure containing information
about the operating system. The structure contains the following
fields:
sysname (Name of the operating system)
nodename (Name of the node within the network)
release (Release level of the OS)
version (Current version of the release)
machine (Name of the hardware)