Global error variable
#include <errno.h> extern int errno;
libc
The errno variable is set to certain error values by many functions whenever an error has occurred.
It may be implemented as a macro, but errno can always be examined or set as if it were a simple integer variable. Values for errno are defined in the file <errno.h>, and include at least the following values:
| Value | Meaning |
|---|---|
| E2BIG | Argument list is too long |
| EACCES | Permission denied |
| EADDRINUSE | Address is already in use |
| EADDRNOTAVAIL | Can't assign requested address |
| EADV | Advertise error |
| EAFNOSUPPORT | Address family isn't supported by protocol family |
| EAGAIN | Resource is temporarily unavailable; try again |
| EALREADY | Operation is already in progress |
| EBADE | Invalid exchange |
| EBADF | Bad file descriptor |
| EBADFD | FD is invalid for this operation |
| EBADFSYS | Corrupted filesystem detected |
| EBADMSG | Bad message (1003.1b-1993) |
| EBADR | Invalid request descriptor |
| EBADRPC | RPC struct is bad |
| EBADRQC | Invalid request code |
| EBADSLT | Invalid slot |
| EBFONT | Bad font-file format |
| EBUSY | Device or resource is busy |
| ECANCELED | Operation canceled (1003.1b-1993) |
| ECHILD | No child processes |
| ECHRNG | Channel number is out of range |
| ECOMM | Communication error occurred on send |
| ECONNABORTED | Software caused connection to abort |
| ECONNREFUSED | Connection refused |
| ECONNRESET | Connection reset by peer |
| ECTRLTERM | Remap to the controlling terminal |
| EDEADLK | Resource deadlock avoided |
| EDEADLOCK | File locking deadlock |
| EDESTADDRREQ | Destination address is required |
| EDOM | Math argument is out of domain for the function |
| EDQUOT | Disk quota exceeded |
| EEXIST | File exists |
| EFAULT | Bad address |
| EFBIG | File is too large |
| EHOSTDOWN | Host is down |
| EHOSTUNREACH | Unable to communicate with remote node |
| EIDRM | Identifier removed |
| EILSEQ | Illegal byte sequence |
| EINPROGRESS | Operation now in progress |
| EINTR | Interrupted function call |
| EINVAL | Invalid argument |
| EIO | I/O error |
| EISCONN | Socket is already connected |
| EISDIR | Is a directory |
| EL2HLT | Level 2 halted |
| EL2NSYNC | Level 2 not synchronized |
| EL3HLT | Level 3 halted |
| EL3RST | Level 3 reset |
| ELIBACC | Can't access shared library |
| ELIBBAD | Accessing a corrupted shared library |
| ELIBEXEC | Attempting to exec a shared library |
| ELIBMAX | Attempting to link in too many libraries |
| ELIBSCN | The .lib section in a.out is corrupted |
| ELNRNG | Link number is out of range |
| ELOOP | Too many levels of symbolic links or prefixes |
| EMFILE | Too many open files |
| EMLINK | Too many links |
| EMORE | More to do, send message again |
| EMSGSIZE | Inappropriate message buffer length |
| EMULTIHOP | Multihop attempted |
| ENAMETOOLONG | Filename is too long |
| ENETDOWN | Network is down |
| ENETRESET | Network dropped connection on reset |
| ENETUNREACH | Network is unreachable |
| ENFILE | Too many open files in the system |
| ENOANO | No anode |
| ENOBUFS | No buffer space available |
| ENOCSI | No CSI structure available |
| ENODATA | No data (for no-delay I/O) |
| ENODEV | No such device |
| ENOENT | No such file or directory |
| ENOEXEC | Exec format error |
| ENOLCK | No locks available |
| ENOLIC | No license available |
| ENOLINK | The link has been severed |
| ENOMEM | Not enough memory |
| ENOMSG | No message of desired type |
| ENONDP | Need an NDP (8087...) to run |
| ENONET | Machine isn't on the network |
| ENOPKG | Package isn't installed |
| ENOPROTOOPT | Protocol isn't available |
| ENOREMOTE | Must be done on local machine |
| ENOSPC | No space left on device |
| ENOSR | Out of streams resources |
| ENOSTR | Device isn't a stream |
| ENOSYS | Function isn't implemented |
| ENOTBLK | Block device is required |
| ENOTCONN | Socket isn't connected |
| ENOTDIR | Not a directory |
| ENOTEMPTY | Directory isn't empty |
| ENOTSOCK | Socket operation on nonsocket |
| ENOTSUP | Not supported (1003.1b-1993) |
| ENOTTY | Inappropriate I/O control operation |
| ENOTUNIQ | Given name isn't unique |
| ENXIO | No such device or address |
| EOK | No error |
| EOPNOTSUPP | Operation isn't supported |
| EOVERFLOW | Value too large to be stored in data type |
| EPERM | Operation isn't permitted |
| EPFNOSUPPORT | Protocol family isn't supported |
| EPIPE | Broken pipe |
| EPROCUNAVAIL | Bad procedure for program |
| EPROGMISMATCH | Program version wrong |
| EPROGUNAVAIL | RPC program isn't available |
| EPROTO | Protocol error |
| EPROTONOSUPPORT | Protocol isn't supported |
| EPROTOTYPE | Protocol is wrong type for socket |
| ERANGE | Result is too large |
| EREMCHG | Remote address changed |
| EREMOTE | The object is remote |
| ERESTART | Restartable system call |
| EROFS | Read-only filesystem |
| ERPCMISMATCH | RPC version is wrong |
| ESHUTDOWN | Can't send after socket shutdown |
| ESOCKTNOSUPPORT | Socket type isn't supported |
| ESPIPE | Illegal seek |
| ESRCH | No such process |
| ESRMNT | Srmount error |
| ESRVRFAULT | The receive side of a message transfer encountered a memory fault accessing the receive/reply buffer. |
| ESTALE | Potentially recoverable I/O error |
| ESTRPIPE | If pipe/FIFO, don't sleep in stream head |
| ETIME | Timer expired |
| ETIMEDOUT | Connection timed out |
| ETOOMANYREFS | Too many references: can't splice |
| ETXTBSY | Text file is busy |
| EUNATCH | Protocol driver isn't attached |
| EUSERS | Too many users (for UFS) |
| EWOULDBLOCK | Operation would block |
| EXDEV | Cross-device link |
| EXFULL | Exchange full |
/*
* The following program makes an illegal call
* to the write() function, then prints the
* value held in errno.
*/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
int main( void )
{
int errvalue;
errno = EOK;
write( -1, "hello, world\n",
strlen( "hello, world\n" ) );
errvalue = errno;
printf( "The error generated was %d\n", errvalue );
printf( "That means: %s\n", strerror( errvalue ) );
}
POSIX 1003.1