Gnu Error Number
Contents |
of a library call. The functions strerror and perror give you the standard error message for a given error code; linux kernel error codes the variable program_invocation_short_name gives you convenient access to the name
C Error Function
of the program that encountered the error. Function: char * strerror (int errnum) Preliminary: | MT-Unsafe race:strerror
C Programming Error Codes
| AS-Unsafe heap i18n | AC-Unsafe mem | See POSIX Safety Concepts. The strerror function maps the error code (see Checking for Errors) specified by the errnum argument
Eintr Errno
to a descriptive error message string. The return value is a pointer to this string. The value errnum normally comes from the variable errno. You should not modify the string returned by strerror. Also, if you make subsequent calls to strerror, the string might be overwritten. (But it’s guaranteed that no library function ever calls strerror enosys error behind your back.) The function strerror is declared in string.h. Function: char * strerror_r (int errnum, char *buf, size_t n) Preliminary: | MT-Safe | AS-Unsafe i18n | AC-Unsafe | See POSIX Safety Concepts. The strerror_r function works like strerror but instead of returning the error message in a statically allocated buffer shared by all threads in the process, it returns a private copy for the thread. This might be either some permanent global data or a message string in the user supplied buffer starting at buf with the length of n bytes. At most n characters are written (including the NUL byte) so it is up to the user to select a buffer large enough. This function should always be used in multi-threaded programs since there is no way to guarantee the string returned by strerror really belongs to the last call of the current thread. The function strerror_r is a GNU extension and it is declared in string.h. Function: void perror (const char *message) Prelimi
EOF that is defined for that purpose. But this return value tells you only that an error has occurred. eintr signal To find out what kind of error it was, you need to strerror example look at the error code stored in the variable errno. This variable is declared in the header eio error in c file errno.h. Variable: volatile int errno The variable errno contains the system error number. You can change the value of errno. Since errno is declared volatile, it might be http://www.gnu.org/s/libc/manual/html_node/Error-Messages.html changed asynchronously by a signal handler; see Defining Handlers. However, a properly written signal handler saves and restores the value of errno, so you generally do not need to worry about this possibility except when writing signal handlers. The initial value of errno at program startup is zero. Many library functions are guaranteed to set it to http://www.gnu.org/s/libc/manual/html_node/Checking-for-Errors.html certain nonzero values when they encounter certain kinds of errors. These error conditions are listed for each function. These functions do not change errno when they succeed; thus, the value of errno after a successful call is not necessarily zero, and you should not use errno to determine whether a call failed. The proper way to do that is documented for each function. If the call failed, you can examine errno. Many library functions can set errno to a nonzero value as a result of calling other library functions which might fail. You should assume that any library function might alter errno when the function returns an error. Portability Note: ISOC specifies errno as a “modifiable lvalue” rather than as a variable, permitting it to be implemented as a macro. For example, its expansion might involve a function call, like *__errno_location(). In fact, that is what it is on GNU/Linux and GNU/Hurd systems. The GNU C Library, on each system, does whatever is right for the particular system. There
errnum, char *buf, size_t buflen); /* GNU-specific */Feature Test Macro Requirements for glibc (see feature_test_macros(7)): The XSI-compliant version of strerror_r() is provided if: (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE Otherwise, the GNU-specific version is https://linux.die.net/man/3/strerror provided. Description The strerror() function returns a pointer to a string that describes the error code passed in the argument errnum, possibly using the LC_MESSAGES part of the current locale to select the appropriate language. (For example, if errnum is EINVAL, the returned description will "Invalid argument".) This string must not be modified by the application, but may be modified by a subsequent call to strerror(). No library function, error codes including perror(3), will modify this string. The strerror_r() function is similar to strerror(), but is thread safe. This function is available in two versions: an XSI-compliant version specified in POSIX.1-2001 (available since glibc 2.3.4, but not POSIX-compliant until glibc 2.13), and a GNU-specific version (available since glibc 2.0). The XSI-compliant version is provided with the feature test macros settings shown in the SYNOPSIS; otherwise the GNU-specific version is provided. gnu error number If no feature test macros are explicitly defined, then (since glibc 2.4) _POSIX_SOURCE is defined by default with the value 200112L, so that the XSI-compliant version of strerror_r() is provided by default. The XSI-compliant strerror_r() is preferred for portable applications. It returns the error string in the user-supplied buffer buf of length buflen. The GNU-specific strerror_r() returns a pointer to a string containing the error message. This may be either a pointer to a string that the function stores in buf, or a pointer to some (immutable) static string (in which case buf is unused). If the function stores a string in buf, then at most buflen bytes are stored (the string may be truncated if buflen is too small and errnum is unknown). The string always includes a terminating null byte. Return Value The strerror() and the GNU-specific strerror_r() functions return the appropriate error description string, or an "Unknown error nnn" message if the error number is unknown. POSIX.1-2001 and POSIX.1-2008 require that a successful call to strerror() shall leave errno unchanged, and note that, since no function return value is reserved to indicate an error, an application that wishes to check for errors should initialize errno to zero before the call, and the