Error code set by system functions.
Integer_Type errno
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"
The mkdir
function will attempt to create a directory. If
that directory already exists, the function will fail and set
errno
to EEXIST
.
define create_dir (dir)
{
if (0 == mkdir (dir)) return;
if (errno != EEXIST)
error ("mkdir %s failied: %s", dir, errno_string);
}
errno_string, error, mkdir
Return a string describing an errno.
String_Type errno_string (Integer_Type err)
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.
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;
}
errno, stat, verror
Get the effective group id
Int_Type getegid ()
The getegid
function returns the effective group ID of the
current process.
This function is not supported by all systems.
getgid, geteuid, setgid
Get the effective user-id of the current process
Int_Type geteuid ()
The geteuid
function returns the effective user-id of the
current process.
This function is not supported by all systems.
getuid, setuid, setgid
Get the group id
Integer_Type getgid ()
The getgid
function returns the real group id of the current
process.
This function is not supported by all systems.
getpid, getppid
Get the current process id
Integer_Type getpid ()
The getpid
function returns the current process identification
number.
getppid, getgid
Get the parent process id
Integer_Type getppid ()
The getpid
function returns the process identification
number of the parent process.
This function is not supported by all systems.
getpid, getgid
Get the user-id of the current process
Int_Type getuid ()
The getuid
function returns the user-id of the current
process.
This function is not supported by all systems.
getuid, getegid
Send a signal to a process
Integer_Type kill (Integer_Type pid, Integer_Type sig)
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.
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;
}
This function is not supported by all systems.
getpid
Create a named pipe
Int_Type mkfifo (String_Type name, Int_Type mode)
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.
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.
stat_file
Set the group-id of the current process
Int_Type setgid (Int_Type gid)
The setgid
function sets the effective group-id of the current
process. It returns zero upon success, or -1
upon error and sets
errno
appropriately.
This function is not supported by all systems.
getgid, setuid
Set the process group-id
Int_Type setpgid (Int_Type pid, Int_Type gid)
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.
This function is not supported by all systems.
setgid, setuid
Set the user-id of the current process
Int_Type setuid (Int_Type id)
The setuid
function sets the effective user-id of the current
process. It returns zero upon success, or -1
upon error and sets
errno
appropriately.
This function is not supported by all systems.
setgid, setpgid, getuid, geteuid
Pause for a specified number of seconds
sleep (Double_Type n)
The sleep
function delays the current process for the
specified number of seconds. If it is interrupted by a signal, it
will return prematurely.
Not all system support sleeping for a fractional part of a second.
Execute a shell command
Integer_Type system (String_Type cmd)
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
.
define dir ()
{
() = system ("DIR");
}
displays a directory listing of the current directory under MSDOS or
VMS.
popen, listdir
Set the file creation mask
Int_Type umask (Int_Type m)
The umask
function sets the file creation mask to m
and
returns the previous mask.
stat_file
Get the system name
Struct_Tye uname ()
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)
Not all systems support this function.
getenv, pack, unpack