Error C Library
Contents |
of a library call. The functions strerror and perror give you the standard error message for a given error code; the variable program_invocation_short_name gives you c error function convenient access to the name of the program that encountered the error. c error codes Function: char * strerror (int errnum) Preliminary: | MT-Unsafe race:strerror | AS-Unsafe heap i18n | AC-Unsafe mem | See c print error message errno POSIX Safety Concepts. The strerror function maps the error code (see Checking for Errors) specified by the errnum argument to a descriptive error message string. The return value is a pointer
C Programming Error Codes
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 behind your back.) The function strerror is declared in string.h. Function: char * strerror_r (int errnum, char *buf, c error handling best practices 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) Preliminary: | MT-Safe race:stderr | AS-Unsafe corrupt i18n heap lock | AC-Unsafe corrupt lock mem fd | See POSIX Safety Concepts. This function prints an error message to the stream stderr; see Standard Streams. The orientation
control Signals Alternative tokens Miscellaneous headers
Strerror Example
library POSIX specification, which is a superset of it.[2][3] Since ANSI C was adopted by the International Organization
Error C-82e10193
for Standardization,[4] the C standard library is also called the ISO C library. The C standard library provides macros, type definitions and functions for tasks such as string handling, http://www.gnu.org/s/libc/manual/html_node/Error-Messages.html mathematical computations, input/output processing, memory management, and several other operating system services. Contents 1 Application programming interface 1.1 Header files 1.2 Documentation 2 Implementations 2.1 Compiler built-in functions 2.2 Linking, libm 2.3 Detection 3 Concepts, problems and workarounds 3.1 Buffer overflow vulnerabilities 3.2 Threading problems, vulnerability to race conditions 3.3 Error handling 4 Standardization 4.1 POSIX standard library 4.2 BSD https://en.wikipedia.org/wiki/C_standard_library libc 5 The C standard library in other languages 6 Comparison to standard libraries of other languages 7 See also 8 References 9 Further reading 10 External links Application programming interface[edit] Header files[edit] The application programming interface (API) of the C standard library is declared in a number of header files. Each header file contains one or more function declarations, data type definitions, and macros. After a long period of stability, three new header files (iso646.h, wchar.h, and wctype.h) were added with Normative Addendum 1 (NA1), an addition to the C Standard ratified in 1995. Six more header files (complex.h, fenv.h, inttypes.h, stdbool.h, stdint.h, and tgmath.h) were added with C99, a revision to the C Standard published in 1999, and five more files (stdalign.h, stdatomic.h, stdnoreturn.h, threads.h, and uchar.h) with C11 in 2011. In total, there are now 29 header files: Name From Description
Signals Alternative tokens Miscellaneous headers