diff options
Diffstat (limited to 'string')
-rw-r--r-- | string/strerror.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/string/strerror.c b/string/strerror.c index 8a54a38ee0..5d829d0bf0 100644 --- a/string/strerror.c +++ b/string/strerror.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 93, 94, 95, 96, 98 Free Software Foundation, Inc. +/* Copyright (C) 1991, 93, 94, 95, 96, 98, 2002 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,16 +16,30 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <libintl.h> #include <stdio.h> #include <string.h> +#include <errno.h> /* Return a string describing the errno code in ERRNUM. The storage is good only until the next call to strerror. Writing to the storage causes undefined behavior. */ +libc_freeres_ptr (static char *buf); + char * strerror (errnum) int errnum; { - static char buf[1024]; - return __strerror_r (errnum, buf, sizeof buf); + char *ret = __strerror_r (errnum, NULL, 0); + int saved_errno; + + if (__builtin_expect (ret != NULL, 1)) + 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); } |