Module Name:    src
Committed By:   joerg
Date:           Mon Aug 19 13:03:12 UTC 2013

Modified Files:
        src/include: string.h
        src/lib/libc/include: extern.h namespace.h
        src/lib/libc/string: strerror.c strerror_r.c

Log Message:
Add strerror_l.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/include/string.h
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/include/extern.h
cvs rdiff -u -r1.167 -r1.168 src/lib/libc/include/namespace.h
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/string/strerror.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/string/strerror_r.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/include/string.h
diff -u src/include/string.h:1.44 src/include/string.h:1.45
--- src/include/string.h:1.44	Mon Jun 24 04:21:20 2013
+++ src/include/string.h	Mon Aug 19 13:03:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: string.h,v 1.44 2013/06/24 04:21:20 riastradh Exp $	*/
+/*	$NetBSD: string.h,v 1.45 2013/08/19 13:03:12 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -122,6 +122,7 @@ typedef struct _locale		*locale_t;
 __BEGIN_DECLS
 int	 strcoll_l(const char *, const char *, locale_t);
 size_t	 strxfrm_l(char * __restrict, const char * __restrict, size_t, locale_t);
+__aconst char *strerror_l(int, locale_t);
 __END_DECLS
 #endif /* _POSIX_C_SOURCE || _NETBSD_SOURCE */
 

Index: src/lib/libc/include/extern.h
diff -u src/lib/libc/include/extern.h:1.22 src/lib/libc/include/extern.h:1.23
--- src/lib/libc/include/extern.h:1.22	Sat May  4 18:31:47 2013
+++ src/lib/libc/include/extern.h	Mon Aug 19 13:03:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.22 2013/05/04 18:31:47 christos Exp $	*/
+/*	$NetBSD: extern.h,v 1.23 2013/08/19 13:03:12 joerg Exp $	*/
 
 /*
  * Copyright (c) 1997 Christos Zoulas.  All rights reserved.
@@ -27,12 +27,18 @@
 #include <stdarg.h>
 #include <ucontext.h>
 
+#ifndef __LOCALE_T_DECLARED
+typedef struct _locale		*locale_t;
+#define __LOCALE_T_DECLARED
+#endif /* __LOCALE_T_DECLARED */
+
 __BEGIN_DECLS
 extern char *__minbrk;
 int __getcwd(char *, size_t);
 int __getlogin(char *, size_t);
 int __setlogin(const char *);
 void _resumecontext(void) __dead;
+__dso_hidden int	_strerror_lr(int, char *, size_t, locale_t);
 const char *__strerror(int , char *, size_t);
 const char *__strsignal(int , char *, size_t);
 char *__dtoa(double, int, int, int *, int *, char **);

Index: src/lib/libc/include/namespace.h
diff -u src/lib/libc/include/namespace.h:1.167 src/lib/libc/include/namespace.h:1.168
--- src/lib/libc/include/namespace.h:1.167	Mon Aug 19 08:03:33 2013
+++ src/lib/libc/include/namespace.h	Mon Aug 19 13:03:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: namespace.h,v 1.167 2013/08/19 08:03:33 joerg Exp $	*/
+/*	$NetBSD: namespace.h,v 1.168 2013/08/19 13:03:12 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -57,6 +57,7 @@
 #define inet_pton	_inet_pton
 #define pipe		_pipe
 #define sbrk		_sbrk
+#define strerror_l	_strerror_l
 #define strerror_r	_strerror_r
 #define strlcat		_strlcat
 #define strlcpy		_strlcpy

Index: src/lib/libc/string/strerror.c
diff -u src/lib/libc/string/strerror.c:1.14 src/lib/libc/string/strerror.c:1.15
--- src/lib/libc/string/strerror.c:1.14	Thu Jan 26 11:13:42 2006
+++ src/lib/libc/string/strerror.c	Mon Aug 19 13:03:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: strerror.c,v 1.14 2006/01/26 11:13:42 kleink Exp $	*/
+/*	$NetBSD: strerror.c,v 1.15 2013/08/19 13:03:12 joerg Exp $	*/
 
 /*
  * Copyright (c) 1988 Regents of the University of California.
@@ -30,30 +30,64 @@
  */
 
 #include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char *sccsid = "@(#)strerror.c	5.6 (Berkeley) 5/4/91";
-#else
-__RCSID("$NetBSD: strerror.c,v 1.14 2006/01/26 11:13:42 kleink Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
+__RCSID("$NetBSD: strerror.c,v 1.15 2013/08/19 13:03:12 joerg Exp $");
+
+#define __SETLOCALE_SOURCE__
 
 #include "namespace.h"
-#include <string.h>
-#include <limits.h>
 #include <errno.h>
-#include "extern.h"
+#include <limits.h>
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
 
-/*
- * Since perror() is not allowed to change the contents of strerror()'s
- * static buffer, both functions supply their own buffers to strerror_r()
- */
+#include "extern.h"
+#ifdef _REENTRANT
+#include "reentrant.h"
+#endif
+#include "setlocale_local.h"
 
 __aconst char *
 strerror(int num)
 {
+
+	return strerror_l(num, _current_locale());
+}
+
+#ifdef _REENTRANT
+static thread_key_t strerror_key;
+static once_t strerror_once = ONCE_INITIALIZER;
+
+static void
+strerror_setup(void)
+{
+
+	thr_keycreate(&strerror_key, free);
+}
+#endif
+
+__aconst char *
+strerror_l(int num, locale_t loc)
+{
+#ifdef _REENTRANT
+	int error;
+	char *buf;
+
+	thr_once(&strerror_once, strerror_setup);
+	buf = thr_getspecific(strerror_key);
+	if (buf == NULL) {
+		buf = malloc(NL_TEXTMAX);
+		if (buf == NULL) {
+			static char fallback_buf[NL_TEXTMAX];
+			buf = fallback_buf;
+		}
+		thr_setspecific(strerror_key, buf);
+	}
+#else
 	static char buf[NL_TEXTMAX];
-	int error = strerror_r(num, buf, sizeof(buf));
+#endif
+
+	error = _strerror_lr(num, buf, NL_TEXTMAX, loc);
 	if (error)
 		errno = error;
 	return buf;

Index: src/lib/libc/string/strerror_r.c
diff -u src/lib/libc/string/strerror_r.c:1.2 src/lib/libc/string/strerror_r.c:1.3
--- src/lib/libc/string/strerror_r.c:1.2	Sat Jul 30 15:21:21 2005
+++ src/lib/libc/string/strerror_r.c	Mon Aug 19 13:03:12 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: strerror_r.c,v 1.2 2005/07/30 15:21:21 christos Exp $	*/
+/*	$NetBSD: strerror_r.c,v 1.3 2013/08/19 13:03:12 joerg Exp $	*/
 
 /*
  * Copyright (c) 1988 Regents of the University of California.
@@ -30,38 +30,27 @@
  */
 
 #include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char *sccsid = "@(#)strerror.c	5.6 (Berkeley) 5/4/91";
-#else
-__RCSID("$NetBSD: strerror_r.c,v 1.2 2005/07/30 15:21:21 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
+__RCSID("$NetBSD: strerror_r.c,v 1.3 2013/08/19 13:03:12 joerg Exp $");
 
 #include "namespace.h"
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
 #ifdef NLS
 #include <limits.h>
 #include <nl_types.h>
+#define __SETLOCALE_SOURCE__
+#include <locale.h>
+#include "setlocale_local.h"
 #endif
 
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
 #include "extern.h"
 
-#ifdef _LIBC
-# ifdef __weak_alias
 __weak_alias(strerror_r, _strerror_r)
-# endif
-#endif
 
 int
-#ifdef _LIBC
-_strerror_r(int num, char *buf, size_t buflen)
-#else
-strerror_r(int num, char *buf, size_t buflen)
-#endif
+_strerror_lr(int num, char *buf, size_t buflen, locale_t loc)
 {
 #define	UPREFIX	"Unknown error: %u"
 	unsigned int errnum = num;
@@ -70,7 +59,7 @@ strerror_r(int num, char *buf, size_t bu
 #ifdef NLS
 	int saved_errno = errno;
 	nl_catd catd;
-	catd = catopen("libc", NL_CAT_LOCALE);
+	catd = catopen_l("libc", NL_CAT_LOCALE, loc);
 #endif
 	_DIAGASSERT(buf != NULL);
 
@@ -83,7 +72,7 @@ strerror_r(int num, char *buf, size_t bu
 #endif
 	} else {
 #ifdef NLS
-		slen = snprintf(buf, buflen, 
+		slen = snprintf_l(buf, buflen, loc,
 		    catgets(catd, 1, 0xffff, UPREFIX), errnum);
 #else
 		slen = snprintf(buf, buflen, UPREFIX, errnum);
@@ -101,3 +90,13 @@ strerror_r(int num, char *buf, size_t bu
 
 	return retval;
 }
+
+int
+strerror_r(int num, char *buf, size_t buflen)
+{
+#ifdef NLS
+	return _strerror_lr(num, buf, buflen, _current_locale());
+#else
+	return _strerror_lr(num, buf, buflen, NULL);
+#endif
+}

Reply via email to