Loading...
string/FreeBSD/strerror.c Libc-1725.40.4 Libc-763.13
--- Libc/Libc-1725.40.4/string/FreeBSD/strerror.c
+++ Libc/Libc-763.13/string/FreeBSD/strerror.c
@@ -41,7 +41,6 @@
 #include <errno.h>
 #include <string.h>
 #include <stdio.h>
-#include <stdlib.h>
 
 #define	UPREFIX		"Unknown error"
 
@@ -57,8 +56,8 @@
  * Doing this by hand instead of linking with stdio(3) avoids bloat for
  * statically linked binaries.
  */
-__private_extern__ void
-__errstr(int num, char *uprefix, char *buf, size_t len)
+static void
+errstr(int num, char *uprefix, char *buf, size_t len)
 {
 	char *t;
 	unsigned int uerr;
@@ -88,8 +87,8 @@
 	catd = catopen("libc", NL_CAT_LOCALE);
 #endif
 
-	if (errnum < 0 || errnum >= sys_nerr) {
-		__errstr(errnum,
+	if (errnum < 1 || errnum >= sys_nerr) {
+		errstr(errnum,
 #if defined(NLS)
 			catgets(catd, 1, 0xffff, UPREFIX),
 #else
@@ -116,26 +115,12 @@
 	return (retval);
 }
 
-static char *__strerror_ebuf = NULL;
-
 char *
 strerror(int num)
 {
-#if !defined(NLS)
-	if (num >= 0 && num < sys_nerr) {
-		return (char*)sys_errlist[num];
-	}
-#endif
+	static char ebuf[NL_TEXTMAX];
 
-	if (__strerror_ebuf == NULL) {
-		__strerror_ebuf = calloc(1, NL_TEXTMAX);
-		if (__strerror_ebuf == NULL) {
-			return NULL;
-		}
-	}
-
-	if (strerror_r(num, __strerror_ebuf, NL_TEXTMAX) != 0) {
-		errno = EINVAL;
-	}
-	return __strerror_ebuf;
+	if (strerror_r(num, ebuf, sizeof(ebuf)) != 0)
+	errno = EINVAL;
+	return (ebuf);
 }