Loading...
string/FreeBSD/strerror.c Libc-1158.30.7 Libc-825.26
--- Libc/Libc-1158.30.7/string/FreeBSD/strerror.c
+++ Libc/Libc-825.26/string/FreeBSD/strerror.c
@@ -41,7 +41,6 @@
 #include <errno.h>
 #include <string.h>
 #include <stdio.h>
-#include <stdlib.h>
 
 #define	UPREFIX		"Unknown error"
 
@@ -116,32 +115,20 @@
 
 	return (retval);
 }
-
-__private_extern__ char *__strerror_ebuf = NULL;
 #else /* BUILDING_VARIANT */
 __private_extern__ void __errstr(int, char *, size_t);
-
-extern char *__strerror_ebuf;
 #endif /* !BUILDING_VARIANT */
 
 char *
 strerror(int num)
 {
-	// Dynamically allocate a big buffer to receive the text then shrink it
-	// down to the actual size needed.
-	size_t ebufsiz = NL_TEXTMAX;
+	static char ebuf[NL_TEXTMAX];
 
-	if (__strerror_ebuf == NULL) {
-		__strerror_ebuf = calloc(1, ebufsiz);
-		if (__strerror_ebuf == NULL) {
-			return NULL;
-		}
-	}
-	
-	if (strerror_r(num, __strerror_ebuf, ebufsiz) != 0) {
 #if !__DARWIN_UNIX03
-		errno = EINVAL;
+	if (strerror_r(num, ebuf, sizeof(ebuf)) != 0)
+	errno = EINVAL;
+#else
+	(void)strerror_r(num, ebuf, sizeof(ebuf));
 #endif
-	}
-	return __strerror_ebuf;
+	return (ebuf);
 }