Error Functions
Header file
errno.h
contains the definition of the errno
variable
stdio.h
contains the function prototype for
the perror
function
string.h
contains the function prototype for
the strerror
function
Error Condition - errno
extern int errno
or
#define errno definition
is used to hold implementation-defined error codes from standard library
routines
- All error codes are positive integers and are traditionally
defined in
<errno.h>
errno
contains the last error condition which occurred;
library functions should never clear errno
, so if
errno
is to be checked after a library call, it is the
programmer's responsibility to set it to 0 before calling the
library routine
Error String - strerror
char *strerror(int errnum)
strerror
returns a pointer to the error message string
associated with errnum
Print Error String - perror
void perror(const char *str)
perror
finds the error message string
associated with the global errno
variable and prints
it, prepended by the text in str
and a colon if
str
is non-null, and followed by a newline, to the
standard error file descriptor.
List of Common Error Constants
EPERM
- Operation not permitted
ENOENT
- No such file or directory
ESRCH
- No such process
EINTR
- Interrupted system call
EIO
- I/O error
ENXIO
- No such device or address
E2BIG
- Argument list too long
ENOEXEC
- Exec format error
EBADF
- Bad file descriptor
ECHILD
- No child processes
ENOMEM
- Not enough core
EACCES
- Permission denied
EFAULT
- Bad address
ENOTBLK
- Block device required
EBUSY
- Resource busy
EEXIST
- File exists
EXDEV
- Cross-device link
ENODEV
- No such device
ENOTDIR
- Not a directory
EISDIR
- Is a directory
EINVAL
- Invalid argument
ENFILE
- Too many open files in system
EMFILE
- Too many open files
ENOTTY
- Inappropriate I/O control operation
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
EDOM
- Numerical argument out of domain
ERANGE
- Result too large
ENOMSG
- No message of desired type
EIDRM
- Identifier removed
ECHRNG
- Channel number out of range
ELNRNG
- Link number out of range
EUNATCH
- Protocol driver not attached
Previous,
Next,
Index