C Programming/string.h/strerror

From Wikibooks, open books for an open world
Jump to navigation Jump to search

The string-error function, strerror, is a C/C++ function which translates an error code, usually stored in the global variable errno, to a human-readable error message.

History

[edit | edit source]

The strerror function is defined in IEEE Std 1003.1, also known as POSIX 1.

Reentrancy

[edit | edit source]

The strerror function is not reentrant. For a reentrant version of the function, see strerror r.

Usage

[edit | edit source]

Inclusion

[edit | edit source]
#include <string.h>

Declaration

[edit | edit source]
char* strerror(int errnum);

Semantics

[edit | edit source]

The function generates and reports a C-style string, containing an error message derived from the error code passed in with errnum.

See also

[edit | edit source]
  • strerror r
  • perror

References

[edit | edit source]
  1. strerror by OpenGroup
[edit | edit source]