Files
glibc/string/strerror.c
T

44 lines
1.4 KiB
C
Raw Normal View History

/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
1996-12-20 01:39:50 +00:00
This file is part of the GNU C Library.
1995-02-18 01:27:10 +00:00
1996-12-20 01:39:50 +00:00
The GNU C Library is free software; you can redistribute it and/or
2001-07-06 04:58:11 +00:00
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
1995-02-18 01:27:10 +00:00
1996-12-20 01:39:50 +00:00
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2001-07-06 04:58:11 +00:00
Lesser General Public License for more details.
1995-02-18 01:27:10 +00:00
2001-07-06 04:58:11 +00:00
You should have received a copy of the GNU Lesser General Public
2012-02-09 23:18:22 +00:00
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
1995-02-18 01:27:10 +00:00
#include <libintl.h>
1995-02-18 01:27:10 +00:00
#include <stdio.h>
#include <string.h>
#include <errno.h>
1995-02-18 01:27:10 +00:00
1996-12-20 01:39:50 +00:00
/* Return a string describing the errno code in ERRNUM.
1995-02-18 01:27:10 +00:00
The storage is good only until the next call to strerror.
Writing to the storage causes undefined behavior. */
libc_freeres_ptr (static char *buf);
1995-02-18 01:27:10 +00:00
char *
strerror (int errnum)
1995-02-18 01:27:10 +00:00
{
char *ret = __strerror_r (errnum, NULL, 0);
int saved_errno;
2014-02-10 14:45:42 +01:00
if (__glibc_likely (ret != NULL))
return ret;
saved_errno = errno;
if (buf == NULL)
buf = malloc (1024);
__set_errno (saved_errno);
if (buf == NULL)
return _("Unknown error");
return __strerror_r (errnum, buf, 1024);
1995-02-18 01:27:10 +00:00
}