Home

strerror

Strerror is a C library function that converts an error number into a human-readable string. It is declared in the standard library headers and is commonly used in conjunction with errno to report system or library errors.

The function signature is typically char *strerror(int errnum). It returns a pointer to a string describing

Thread safety and portable variants vary by platform. In POSIX, strerror_r provides a thread-safe alternative by

Locale and portability considerations apply: the language of the message may depend on the current locale,

In practice, strerror is suitable for quick debugging and logging when portability is not a concern, but

the
error
associated
with
the
provided
error
number.
The
returned
string
is
usually
stored
in
a
static
internal
buffer,
and
subsequent
calls
may
overwrite
it.
The
caller
should
not
attempt
to
free
the
pointer.
writing
the
message
into
a
user-supplied
buffer;
however,
there
are
two
main
versions
with
different
return
conventions
depending
on
the
implementation.
Some
environments
also
offer
strerror_l
to
select
a
specific
locale.
Windows
environments
provide
strerror_s
as
part
of
the
secure
CRT,
with
different
semantics
than
POSIX
variants.
Because
of
these
differences,
exact
behavior
can
differ
between
compilers
and
operating
systems.
and
not
all
implementations
internationalize
messages.
For
robust,
portable
error
reporting,
developers
may
prefer
strerror_r
or
strerror_s,
or
use
higher-level
facilities
like
perror
for
simple
demonstrations,
which
formats
a
message
based
on
errno
and
an
optional
prefix.
care
should
be
taken
about
thread
safety
and
buffer
ownership
in
multi-threaded
or
cross-platform
code.