Home
Developer Resources

errno

PDF Documents
Caution: This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.

errno

Global error variable

Synopsis:

#include <errno.h>

extern int errno;

char * const sys_errlist[];
int sys_nerr;

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The errno variable is set to certain error values by many functions whenever an error has occurred.


Note: You can't assume that the value of errno is valid unless the function that you've called indicates that an error has occurred. The runtime library never resets errno to 0.

The documentation for a function might list special meanings for certain values of errno, but this doesn't mean that these are the only values that the function might set.


The errno variable may be implemented as a macro, but you can always examine or set it as if it were a simple integer variable.


Note: Each thread in a multi-threaded program has its own error value in its thread local storage. No matter which thread you're in, you can simply refer to errno — it's defined in such a way that it refers to the correct variable for the thread. For more information, see Local storage for private data in the documentation for ThreadCreate().

The following variables are also defined in <errno.h>:

sys_errlist
An array of error messages corresponding to errno.
sys_nerr
The number of entries in the sys_errlist array.

The values for errno 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 (see Changes to EALREADY,” below)
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
EOWNERDEAD The owner of a lock died while holding it
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 Server mount 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

Changes to EALREADY

POSIX requires that the error numbers in <errno.h> have unique values. In order to satisfy this requirement, we're changing EALREADY so that it no longer has the same value as EBUSY.

This change could cause incompatibility problems because code that currently uses EALREADY has been compiled to use the old value. In order to allow applications to safely make the transition to the new value, we've modified <errno.h> to define a number of new symbolic values:

EALREADY_OLD
The old value (16).
EALREADY_NEW
The new value (237).
EALREADY_DYNAMIC
A value that you can configure at runtime. This is a variable in libc that's set to either the old or new value, based on a system-wide configuration parameter.

In QNX Neutrino 6.4.0, EALREADY is defined as EALREADY_OLD, so that programs by default are compatible with existing binaries. EALREADY will be changed in a future release to EALREADY_NEW. In order to support a safe transition to the new value, you should modify your code as follows:

You can use the -e option to procnto to specify the value of EALREADY_DYNAMIC:

-eo
Use the old value, which is the same as that of EBUSY.
-en
Use the POSIX-compliant value.

Examples:

/*
 *  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 ) );
}

Classification:

ANSI, POSIX 1003.1

See also:

h_errno, perror(), stderr, strerror()