STRERROR_R(3)

NAME
strerror_r - convert error number to string and copy to buffer

SYNOPSIS

#include <string.h>

#ifdef _GNU_SOURCE

char *strerror_r(int errnum, char *buffer, size_t n);

#else

int strerror_r(int errnum, char *buffer, size_t n);

#endif

DESCRIPTION

strerror_r converts the error number errnum into a string and copies the result into the supplied buffer for a length up to n, including the NUL terminator. The value of errnum is usually a copy of errno. If errnum is not a known error number, the result is the empty string.

See strerror for how strings are mapped to errnum.

RETURNS

There are two variants: the GNU version always returns a NUL-terminated string, which is buffer if all went well, but which is another pointer if n was too small (leaving buffer untouched). If the return is not buffer, your application must not modify that string. The POSIX version returns 0 on success, EINVAL if errnum was not recognized, and ERANGE if n was too small. The variant chosen depends on macros that you define before inclusion of string.h.

PORTABILITY

strerror_r with a char * result is a GNU extension. strerror_r with an int result is required by POSIX 2001. This function is compliant only if _user_strerror is not provided, or if it is thread-safe and uses separate storage according to whether the second argument of that function is non-zero. For more details on _user_strerror, see the strerror documentation.

POSIX states that the contents of buf are unspecified on error, although this implementation guarantees a NUL-terminated string for all except n of 0.

POSIX recommends that unknown errnum result in a message including that value, however it is not a requirement and this implementation provides only an empty string (unless you provide _user_strerror). POSIX also recommends that unknown errnum fail with EINVAL even when providing such a message, however it is not a requirement and this implementation will return success if _user_strerror provided a non-empty alternate string without assigning into its third argument.

strerror_r requires no supporting OS subroutines.

AUTHORS

Steve Chamberlain
    Author.

Roland Pesch
    Author.

Red Hat Support

Jeff Johnston
    Author.

COPYRIGHT

This file documents the ANSI C library.

Copyright (C) 1992, 1993, 1994-2014 Red Hat, Inc.

libc includes software developed by the University of California, Berkeley and its contributors.

libc includes software developed by Martin Jackson, Graham Haley and Steve Chamberlain of Tadpole Technology and released to Cygnus.

libc uses floating-point conversion software developed at AT&T, which includes this copyright information:

The author of this software is David M. Gay.

Copyright (c) 1991 by AT&T.

Permission to use, copy, modify, and distribute this software for any purpose without fee is hereby granted, provided that this entire notice is included in all copies of any software which is or includes a copy or modification of this software and in all copies of the supporting documentation for such software.

THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.

Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.

Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, subject to the terms of the GNU General Public License, which includes the provision that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.