On Tue, Sep 09, 2008 at 05:41:40PM +0200, Bernhard Reutner-Fischer wrote:
>On Tue, Sep 09, 2008 at 12:45:39PM +0200, Bernhard Reutner-Fischer wrote:
>>On Sun, Jun 08, 2008 at 02:18:03PM +0200, Bernd Schmidt wrote:
>>> Bernhard Fischer wrote:
>>>> Just to make sure i understand correctly:
>>>>
>>>> - If a reentrant function exists then you want the non-reentrant func to
>>>>   be optional (via a central knob).
>>>> - If non-reentrant funcs are off then they are aliased to their
>>>>   reentrant counterpart.
>>>
>>> No, they have different calling conventions, so they'd just not exist.


>What do people think about scandir(). Would you prefer to use readdir_r
>for it or should it use a not publically visible __libc_readdir(DIR*)?
>
>Is it worthwile to put the definition of TTYNAME_BUFLEN into a private
>ttyname.h or will everybody remember to keep the two in sync?
>Alternatively it could come from the buildsystem, i have no preference.
>
>An unrelated hunk in the patch* above begs the question as to whether or
>not __libc_sigaction() should use the rt_sigaction syscall internally
>if the user turned off (the external API) UCLIBC_HAS_REALTIME.
>rt_sigaction is currently used internally and back then i thought and
>still think this is ok.  Opinions?

Perhaps somebody has time to test the attached patch. The final version
will make sure not to add new relocations.
Index: extra/Configs/Config.in
===================================================================
--- extra/Configs/Config.in	(revision 23369)
+++ extra/Configs/Config.in	(working copy)
@@ -711,6 +711,20 @@ config UCLIBC_GRP_BUFFER_SIZE
 	  The value can be found using sysconf() with the _SC_GETGR_R_SIZE_MAX
 	  parameter.
 
+config UCLIBC_HAS_NONREENTRANT
+	bool "Non-reentrant functions"
+	default y
+	help
+	  Per default, both reentrant functions and non-reentrant
+	  functions are exported.
+
+	  If you disable this option, then the non-reentrant variant
+	  will not be exported, but only the reentrant one.
+	  E.e. strerror_r() will be provided, but strerror() not.
+
+	  Functions which do not in general provide both reentrant
+	  and non-reentrant variants are not affected by this option.
+
 comment "Support various families of functions"
 
 config UCLIBC_LINUX_MODULE_24
Index: libm/Makefile.in
===================================================================
--- libm/Makefile.in	(revision 23369)
+++ libm/Makefile.in	(working copy)
@@ -61,8 +61,8 @@ FL_MSRC := float_wrappers.c
 ifeq ($(DO_C99_MATH),y)
 libm_CSRC := \
 	e_acos.c e_acosh.c e_asin.c e_atan2.c e_atanh.c e_cosh.c \
-	e_exp.c e_fmod.c e_gamma.c e_gamma_r.c e_hypot.c e_j0.c \
-	e_j1.c e_jn.c e_lgamma.c e_lgamma_r.c e_log.c e_log10.c \
+	e_exp.c e_fmod.c e_hypot.c e_j0.c \
+	e_j1.c e_jn.c e_log.c e_log10.c \
 	e_pow.c e_remainder.c e_rem_pio2.c e_scalb.c e_sinh.c \
 	e_sqrt.c k_cos.c k_rem_pio2.c k_sin.c k_standard.c k_tan.c \
 	s_asinh.c s_atan.c s_cbrt.c s_ceil.c s_copysign.c s_cos.c \
@@ -71,8 +71,8 @@ libm_CSRC := \
 	s_log1p.c s_logb.c s_matherr.c s_modf.c s_nextafter.c s_round.c \
 	s_rint.c s_scalbn.c s_signgam.c s_significand.c s_sin.c s_tan.c \
 	s_tanh.c s_trunc.c w_acos.c w_acosh.c w_asin.c w_atan2.c w_atanh.c \
-	w_cabs.c w_cosh.c w_drem.c w_exp.c w_fmod.c w_gamma.c w_gamma_r.c \
-	w_hypot.c w_j0.c w_j1.c w_jn.c w_lgamma.c w_lgamma_r.c \
+	w_cabs.c w_cosh.c w_drem.c w_exp.c w_fmod.c \
+	w_hypot.c w_j0.c w_j1.c w_jn.c \
 	w_log.c w_log10.c w_pow.c w_remainder.c w_scalb.c w_sinh.c \
 	w_sqrt.c fpmacros.c nan.c carg.c s_llrint.c
 FL_MOBJ := \
@@ -84,6 +84,11 @@ FL_MOBJ := \
 	nextafterf.o powf.o remainderf.o remquof.o rintf.o roundf.o \
 	scalblnf.o scalbnf.o sinf.o sinhf.o sqrtf.o tanf.o tanhf.o \
 	tgammaf.o truncf.o cargf.o llrintf.o
+REENTRANT := e_gamma e_lgamma w_gamma w_lgamma
+libm_CSRC += $(REENTRANT:=_r.c)
+# TODO: ifeq ($(UCLIBC_HAS_NONREENTRANT),y)
+libm_CSRC += $(REENTRANT:=.c)
+# TODO: endif
 else
 # This list of math functions was taken from POSIX/IEEE 1003.1b-1993
 libm_CSRC := \
Index: libc/inet/Makefile.in
===================================================================
--- libc/inet/Makefile.in	(revision 23369)
+++ libc/inet/Makefile.in	(working copy)
@@ -1,6 +1,6 @@
 # Makefile for uClibc
 #
-# Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
+# Copyright (C) 2000-2008 Erik Andersen <[EMAIL PROTECTED]>
 #
 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 #
@@ -30,20 +30,31 @@ endif
 # multi source resolv.c
 resolv_CSRC +=	encodeh.c decodeh.c encoded.c decoded.c lengthd.c encodeq.c \
 	decodeq.c lengthq.c encodea.c decodea.c \
-	dnslookup.c resolveaddress.c opennameservers.c \
-	closenameservers.c resolvename.c gethostbyname.c res_init.c \
-	res_query.c gethostbyaddr.c read_etc_hosts_r.c get_hosts_byname_r.c \
-	get_hosts_byaddr_r.c gethostbyname2.c getnameinfo.c gethostent.c \
-	gethostbyname_r.c gethostbyname2_r.c gethostbyaddr_r.c \
-	res_comp.c ns_name.c ethers.c
+	dnslookup.c resolveaddress.c resolvename.c \
+	opennameservers.c closenameservers.c \
+	res_init.c res_query.c res_comp.c \
+	getnameinfo.c gethostent.c \
+	get_hosts_byname_r.c \
+	get_hosts_byaddr_r.c \
+	read_etc_hosts_r.c \
+	ns_name.c
+
+REENTRANT := \
+	gethostbyname \
+	gethostbyname2 \
+	gethostbyaddr
+
 ifneq ($(UCLIBC_HAS_IPV4)$(UCLIBC_HAS_IPV6),)
 CSRC += $(resolv_CSRC)
-
+CSRC += ethers.c
+CSRC += $(patsubst %,%_r.c,$(REENTRANT))
+ifeq ($(UCLIBC_HAS_NONREENTRANT),y)
+CSRC += $(patsubst %,%.c,$(REENTRANT))
+endif
 # unused ATM
 CSRC += encodep.c decodep.c formquery.c
 endif
 
-
 # multi source socketcalls.c
 socketcalls_CSRC +=	accept.c bind.c connect.c getpeername.c getsockname.c \
 	getsockopt.c listen.c recv.c recvfrom.c recvmsg.c send.c sendmsg.c \
Index: libc/inet/resolv.c
===================================================================
--- libc/inet/resolv.c	(revision 23369)
+++ libc/inet/resolv.c	(working copy)
@@ -183,7 +183,7 @@ libc_hidden_proto(socket)
 libc_hidden_proto(close)
 libc_hidden_proto(fopen)
 libc_hidden_proto(fclose)
-libc_hidden_proto(random)
+libc_hidden_proto(getpid)
 libc_hidden_proto(getservbyport)
 libc_hidden_proto(uname)
 libc_hidden_proto(inet_addr)
@@ -1197,7 +1197,7 @@ int res_init(void)
 	rp->retrans = RES_TIMEOUT;
 	rp->retry = 4;
 	rp->options = RES_INIT;
-	rp->id = (u_int) random();
+	rp->id = (u_int) 0xffff & getpid();
 	rp->nsaddr.sin_addr.s_addr = INADDR_ANY;
 	rp->nsaddr.sin_family = AF_INET;
 	rp->nsaddr.sin_port = htons(NAMESERVER_PORT);
@@ -1871,20 +1871,44 @@ BAD_FAM:
 		case AF_INET6:
 #endif /* __UCLIBC_HAS_IPV6__ */
 			if (!(flags & NI_NUMERICHOST)) {
+#if defined __UCLIBC_HAS_IPV6__ || defined __UCLIBC_HAS_IPV4__
+
+				struct hostent tmphe;
+				int herrno;
+#if 1
+				int buflen = 512;
+				char *buf = malloc(buflen);
+#else
+				int buflen = 0;
+				char *buf = NULL;
+ retry_with_bigger_buffer:
+				buflen += 512;
+				buf = realloc(buf, buflen);
+#endif
+#endif
 #ifdef __UCLIBC_HAS_IPV6__
 				if (sa->sa_family == AF_INET6)
-					h = gethostbyaddr ((const void *)
+					gethostbyaddr_r ((const void *)
 						&(((const struct sockaddr_in6 *) sa)->sin6_addr),
-						sizeof(struct in6_addr), AF_INET6);
+						sizeof(struct in6_addr), AF_INET6,
+						&tmphe, buf, buflen, &h, &herrno);
 #endif /* __UCLIBC_HAS_IPV6__ */
 #if defined __UCLIBC_HAS_IPV6__ && defined __UCLIBC_HAS_IPV4__
 				else
 #endif
 #ifdef __UCLIBC_HAS_IPV4__
-					h = gethostbyaddr ((const void *) &(((const struct sockaddr_in *)sa)->sin_addr),
-					  sizeof(struct in_addr), AF_INET);
+					gethostbyaddr_r ((const void *)
+						&(((const struct sockaddr_in *)sa)->sin_addr),
+						sizeof(struct in_addr), AF_INET,
+						&tmphe, buf, buflen, &h, &herrno);
 #endif /* __UCLIBC_HAS_IPV4__ */
-
+#if 0 // defined __UCLIBC_HAS_IPV6__ || defined __UCLIBC_HAS_IPV4__
+				if (herrno == NETDB_INTERNAL && errno == ERANGE)
+					goto retry_with_bigger_buffer;
+#endif
+#if defined __UCLIBC_HAS_IPV6__ || defined __UCLIBC_HAS_IPV4__
+				free(buf);
+#endif
 				if (h) {
 					char *c;
 					if ((flags & NI_NOFQDN)
Index: libc/stdlib/Makefile.in
===================================================================
--- libc/stdlib/Makefile.in	(revision 23369)
+++ libc/stdlib/Makefile.in	(working copy)
@@ -1,6 +1,6 @@
 # Makefile for uClibc
 #
-# Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
+# Copyright (C) 2000-2008 Erik Andersen <[EMAIL PROTECTED]>
 #
 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 #
@@ -11,11 +11,24 @@ include $(top_srcdir)libc/stdlib/malloc-
 
 CSRC := \
 	abort.c getenv.c mkdtemp.c mktemp.c realpath.c mkstemp.c \
-	rand.c random.c random_r.c setenv.c system.c div.c ldiv.c lldiv.c \
-	getpt.c drand48-iter.c jrand48.c \
-	jrand48_r.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c nrand48.c \
-	nrand48_r.c rand_r.c srand48.c srand48_r.c seed48.c seed48_r.c \
+	setenv.c system.c div.c ldiv.c lldiv.c \
+	getpt.c drand48-iter.c \
 	valloc.c a64l.c l64a.c __uc_malloc.c
+
+REENTRANT := \
+	random \
+	rand \
+	jrand48 \
+	lrand48 \
+	mrand48 \
+	nrand48 \
+	srand48 \
+	seed48
+
+CSRC += $(patsubst %,%_r.c,$(REENTRANT))
+ifeq ($(UCLIBC_HAS_NONREENTRANT),y)
+CSRC += $(patsubst %,%.c,$(REENTRANT))
+endif
 ifeq ($(UCLIBC_HAS_ADVANCED_REALTIME),y)
 CSRC += posix_memalign.c
 endif
Index: libc/pwd_grp/Makefile.in
===================================================================
--- libc/pwd_grp/Makefile.in	(revision 23369)
+++ libc/pwd_grp/Makefile.in	(working copy)
@@ -1,6 +1,6 @@
 # Makefile for uClibc
 #
-# Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
+# Copyright (C) 2000-2008 Erik Andersen <[EMAIL PROTECTED]>
 #
 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 #
@@ -8,18 +8,44 @@
 PWDGRP_DIR := $(top_srcdir)libc/pwd_grp
 PWDGRP_OUT := $(top_builddir)libc/pwd_grp
 
-CSRC := $(notdir $(wildcard $(PWDGRP_DIR)/*.c))
-CSRC := $(filter-out pwd_grp.c pwd_grp_internal.c,$(CSRC))
+CSRC := \
+	getpw.c \
+	initgroups.c \
+	__parsegrent.c \
+	__parsepwent.c \
+	__pgsreader.c \
+	putgrent.c \
+	putpwent.c
+
+REENTRANT := \
+	fgetgrent \
+	fgetpwent \
+	getgrent \
+	getgrgid \
+	getgrnam \
+	getpwent \
+	getpwnam \
+	getpwuid
+
+ifeq ($(UCLIBC_HAS_SHADOW),y)
+CSRC += lckpwdf.c \
+	__parsespent.c \
+	putspent.c
+
+REENTRANT += \
+	fgetspent \
+	getspent \
+	getspnam \
+	sgetspent
+# getspuid
+endif
 
-ifneq ($(UCLIBC_HAS_SHADOW),y)
-SHADOW_CSRC := \
-	fgetspent_r.c fgetspent.c getspent_r.c getspent.c \
-	getspnam_r.c getspnam.c lckpwdf.c putspent.c \
-	sgetspent_r.c sgetspent.c __parsespent.c
-# getspuid_r.c getspuid.c
-CSRC := $(filter-out $(SHADOW_CSRC),$(CSRC))
+CSRC += $(patsubst %,%_r.c,$(REENTRANT))
+ifeq ($(UCLIBC_HAS_NONREENTRANT),y)
+CSRC += $(patsubst %,%.c,$(REENTRANT))
 endif
 
+
 PWDGRP_SRC := $(patsubst %.c,$(PWDGRP_DIR)/%.c,$(CSRC))
 PWDGRP_OBJ := $(patsubst %.c,$(PWDGRP_OUT)/%.o,$(CSRC))
 
Index: libc/stdio/Makefile.in
===================================================================
--- libc/stdio/Makefile.in	(revision 23369)
+++ libc/stdio/Makefile.in	(working copy)
@@ -1,7 +1,7 @@
 # Makefile for uClibc
 #
 # Copyright (C) 2004 Manuel Novoa III <[EMAIL PROTECTED]>
-# Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
+# Copyright (C) 2000-2008 Erik Andersen <[EMAIL PROTECTED]>
 #
 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 #
@@ -16,7 +16,13 @@ CSRC := \
 	setlinebuf.c setvbuf.c ungetc.c \
 	printf.c vprintf.c vsprintf.c fprintf.c snprintf.c dprintf.c \
 	asprintf.c sprintf.c vasprintf.c vdprintf.c vsnprintf.c \
-	tmpfile.c tmpnam.c tmpnam_r.c popen.c tempnam.c ctermid.c
+	tmpfile.c popen.c tempnam.c ctermid.c
+
+REENTRANT := tmpnam
+CSRC += $(patsubst %,%_r.c,$(REENTRANT))
+ifeq ($(UCLIBC_HAS_NONREENTRANT),y)
+CSRC += $(patsubst %,%.c,$(REENTRANT))
+endif
 
 ifeq ($(UCLIBC_HAS_LFS),y)
 CSRC += fgetpos64.c fopen64.c freopen64.c fseeko64.c fsetpos64.c ftello64.c
Index: libc/termios/Makefile.in
===================================================================
--- libc/termios/Makefile.in	(revision 23369)
+++ libc/termios/Makefile.in	(working copy)
@@ -1,6 +1,6 @@
 # Makefile for uClibc
 #
-# Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
+# Copyright (C) 2000-2008 Erik Andersen <[EMAIL PROTECTED]>
 #
 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 #
@@ -8,8 +8,14 @@
 TERMIOS_DIR := $(top_srcdir)libc/termios
 TERMIOS_OUT := $(top_builddir)libc/termios
 
-TERMIOS_SRC := $(wildcard $(TERMIOS_DIR)/*.c)
-TERMIOS_OBJ := $(patsubst $(TERMIOS_DIR)/%.c,$(TERMIOS_OUT)/%.o,$(TERMIOS_SRC))
+CSRC := $(notdir $(wildcard $(TERMIOS_DIR)/*.c))
+
+ifneq ($(UCLIBC_HAS_NONREENTRANT),y)
+CSRC := $(filter-out ttyname.c,$(CSRC))
+endif
+
+TERMIOS_SRC := $(patsubst %.c,$(TERMIOS_DIR)/%.c,$(CSRC))
+TERMIOS_OBJ := $(patsubst %.c,$(TERMIOS_OUT)/%.o,$(CSRC))
 
 libc-y += $(TERMIOS_OBJ)
 
Index: libc/termios/ttyname_r.c
===================================================================
--- libc/termios/ttyname_r.c	(revision 23369)
+++ libc/termios/ttyname_r.c	(working copy)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * Copyright (C) Jan 1, 2004    Manuel Novoa III
  * Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
@@ -38,10 +39,11 @@ libc_hidden_proto(lstat)
 /* Experimentally off - libc_hidden_proto(strlen) */
 libc_hidden_proto(opendir)
 libc_hidden_proto(closedir)
-libc_hidden_proto(readdir)
+extern __typeof(readdir) __libc_readdir;
+libc_hidden_proto(__libc_readdir)
 libc_hidden_proto(isatty)
 
-#define TTYNAME_BUFLEN		32
+#define TTYNAME_BUFLEN	32
 
 static const char dirlist[] =
 /*   12345670123 */
@@ -86,7 +88,7 @@ int ttyname_r(int fd, char *ubuf, size_t
 			continue;
 		}
 
-		while ((d = readdir(fp)) != NULL) {
+		while ((d = __libc_readdir(fp)) != NULL) {
 			/* This should never trigger for standard names, but we
 			 * check it to be safe.  */
 			if (strlen(d->d_name) > len) { /* Too big? */
@@ -127,10 +129,3 @@ int ttyname_r(int fd, char *ubuf, size_t
 	return rv;
 }
 libc_hidden_def(ttyname_r)
-
-char *ttyname(int fd)
-{
-	static char name[TTYNAME_BUFLEN];
-
-	return ttyname_r(fd, name, TTYNAME_BUFLEN) ? NULL : name;
-}

Property changes on: libc/termios/ttyname_r.c
___________________________________________________________________
Added: svn:mergeinfo

Index: libc/termios/ttyname.c
===================================================================
--- libc/termios/ttyname.c	(revision 23369)
+++ libc/termios/ttyname.c	(working copy)
@@ -1,133 +1,15 @@
+/* vi: set sw=4 ts=4: */
 /*
  * Copyright (C) Jan 1, 2004    Manuel Novoa III
  * Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
  *
  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  */
-
-/*
- * Kept the same approach, but rewrote the code for the most part.
- * Fixed some minor issues plus (as I recall) one SUSv3 errno case.
- */
-
-/* This is a fairly slow approach.  We do a linear search through some
- * directories looking for a match.  Yes this is lame.  But it should
- * work, should be small, and will return names that match what is on
- * disk.  Another approach we could use would be to use the info in
- * /proc/self/fd, but that is even more lame since it requires /proc */
-
-/* SUSv3 mandates TTY_NAME_MAX as 9.  This is obviously insufficient.
- * However, there is no need to waste space and support non-standard
- * tty names either.  So we compromise and use the following buffer
- * length.  (Erik and Manuel agreed that 32 was more than reasonable.)
- *
- * If you change this, also change _SC_TTY_NAME_MAX in libc/unistd/sysconf.c
- */
-
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
 #include <unistd.h>
-#include <dirent.h>
-#include <sys/stat.h>
-
-libc_hidden_proto(ttyname_r)
-libc_hidden_proto(fstat)
-libc_hidden_proto(lstat)
-/* Experimentally off - libc_hidden_proto(strcpy) */
-/* Experimentally off - libc_hidden_proto(strlen) */
-libc_hidden_proto(opendir)
-libc_hidden_proto(closedir)
-libc_hidden_proto(readdir)
-libc_hidden_proto(isatty)
-
-#define TTYNAME_BUFLEN		32
-
-static const char dirlist[] =
-/*   12345670123 */
-"\010/dev/vc/\0"	/* Try /dev/vc first (be devfs compatible) */
-"\011/dev/tts/\0"	/* and /dev/tts next (be devfs compatible) */
-"\011/dev/pty/\0"	/* and /dev/pty next (be devfs compatible) */
-"\011/dev/pts/\0"	/* and try /dev/pts next */
-"\005/dev/\0";		/* and try walking through /dev last */
-
-int ttyname_r(int fd, char *ubuf, size_t ubuflen)
-{
-	struct dirent *d;
-	struct stat st;
-	struct stat dst;
-	const char *p;
-	char *s;
-	DIR *fp;
-	int rv;
-	size_t len;
-	char buf[TTYNAME_BUFLEN];
-
-	if (fstat(fd, &st) < 0) {
-		return errno;
-	}
 
-	rv = ENOTTY;				/* Set up the default return value. */
-
-	if (!isatty(fd)) {
-		goto DONE;
-	}
-
-	for (p = dirlist ; *p ; p += 1 + p[-1]) {
-		len = *p++;
-
-		assert(len + 2 <= TTYNAME_BUFLEN); /* dirname + 1 char + nul */
-
-		strcpy(buf, p);
-		s = buf + len;
-		len =  (TTYNAME_BUFLEN-2) - len; /* Available non-nul space. */
-
-		if (!(fp = opendir(p))) {
-			continue;
-		}
-
-		while ((d = readdir(fp)) != NULL) {
-			/* This should never trigger for standard names, but we
-			 * check it to be safe.  */
-			if (strlen(d->d_name) > len) { /* Too big? */
-				continue;
-			}
-
-			strcpy(s, d->d_name);
-
-			if ((lstat(buf, &dst) == 0)
-#if 0
-				/* Stupid filesystems like cramfs fail to guarantee that
-				 * st_ino and st_dev uniquely identify a file, contrary to
-				 * SuSv3, so we cannot be quite so precise as to require an
-				 * exact match.  Settle for something less...  Grumble... */
-				&& (st.st_dev == dst.st_dev) && (st.st_ino == dst.st_ino)
-#else
-				&& S_ISCHR(dst.st_mode) && (st.st_rdev == dst.st_rdev)
-#endif
-				) {				/* Found it! */
-				closedir(fp);
-
-				/* We treat NULL buf as ERANGE rather than EINVAL. */
-				rv = ERANGE;
-				if (ubuf && (strlen(buf) <= ubuflen)) {
-					strcpy(ubuf, buf);
-					rv = 0;
-				}
-				goto DONE;
-			}
-		}
-
-		closedir(fp);
-	}
-
- DONE:
-	__set_errno(rv);
-
-	return rv;
-}
-libc_hidden_def(ttyname_r)
+#define TTYNAME_BUFLEN	32
 
+libc_hidden_proto(ttyname_r)
 char *ttyname(int fd)
 {
 	static char name[TTYNAME_BUFLEN];
Index: libc/string/Makefile.in
===================================================================
--- libc/string/Makefile.in	(revision 23369)
+++ libc/string/Makefile.in	(working copy)
@@ -1,6 +1,6 @@
 # Makefile for uClibc
 #
-# Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
+# Copyright (C) 2000-2008 Erik Andersen <[EMAIL PROTECTED]>
 #
 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 #
@@ -12,6 +12,10 @@ STRING_ARCH_DIR := $(top_srcdir)libc/str
 STRING_ARCH_OUT := $(top_builddir)libc/string/$(TARGET_ARCH)
 
 STRING_ARCH_SRC := $(wildcard $(STRING_ARCH_DIR)/*.c)
+ARCH_REENTRANT := $(wildcard $(STRING_ARCH_DIR)/*_r.c)
+ifneq ($(UCLIBC_HAS_NONREENTRANT),y)
+STRING_ARCH_SRC := $(filter-out $(ARCH_REENTRANT:_r.c=.c),$(STRING_ARCH_SRC))
+endif
 STRING_ARCH_OBJ := $(patsubst $(STRING_ARCH_DIR)/%.c,$(STRING_ARCH_OUT)/%.o,$(STRING_ARCH_SRC))
 
 STRING_ARCH_SSRC := $(wildcard $(STRING_ARCH_DIR)/*.S)
@@ -30,6 +34,10 @@ STRING_GENERIC_DIR := $(top_srcdir)libc/
 STRING_GENERIC_OUT := $(top_builddir)libc/string/generic
 
 STRING_GENERIC_SRC := $(wildcard $(STRING_GENERIC_DIR)/*.c)
+GENERIC_REENTRANT := $(wildcard $(STRING_GENERIC_DIR)/*_r.c)
+ifneq ($(UCLIBC_HAS_NONREENTRANT),y)
+STRING_GENERIC_SRC := $(filter-out $(GENERIC_REENTRANT:_r.c=.c),$(STRING_GENERIC_SRC))
+endif
 
 ifeq ($(UCLIBC_HAS_STRING_ARCH_OPT),y)
 ifneq ($(strip $(STRING_ARCH_OBJS)),)
@@ -48,6 +56,7 @@ STRING_DIR := $(top_srcdir)libc/string
 STRING_OUT := $(top_builddir)libc/string
 
 STRING_ALL_WXSRC := $(wildcard $(STRING_DIR)/w*_l.c)
+REENTRANT := $(wildcard $(STRING_DIR)/*_r.c)
 ifeq ($(UCLIBC_HAS_LOCALE),y)
 STRING_WXSRC := $(STRING_ALL_WXSRC)
 else
@@ -79,6 +88,10 @@ else
 STRING_CSRC := $(filter-out $(STRING_DIR)/strxfrm.c,$(STRING_ALL_CSRC))
 endif
 
+ifneq ($(UCLIBC_HAS_NONREENTRANT),y)
+STRING_CSRC := $(filter-out $(patsubst %_r.c,%.c,$(REENTRANT)),$(STRING_CSRC))
+endif
+
 ifeq ($(UCLIBC_HAS_WCHAR),y)
 STRING_CSRC += $(STRING_WSRC)
 endif
@@ -107,7 +120,6 @@ libc-y += $(STRING_COBJ)
 
 libc-nomulti-$(UCLIBC_HAS_XLOCALE) += $(STRING_OUT)/wcsxfrm_l.o
 libc-nomulti-y += $(STRING_OUT)/__xpg_strerror_r.o
-
 objclean-y += string_objclean
 
 string_objclean:
Index: libc/unistd/Makefile.in
===================================================================
--- libc/unistd/Makefile.in	(revision 23369)
+++ libc/unistd/Makefile.in	(working copy)
@@ -9,9 +9,14 @@ UNISTD_DIR := $(top_srcdir)libc/unistd
 UNISTD_OUT := $(top_builddir)libc/unistd
 
 CSRC := $(notdir $(wildcard $(UNISTD_DIR)/*.c))
+REENTRANT := $(notdir $(wildcard $(UNISTD_DIR)/*_r.c))
 # multi source
 CSRC := $(filter-out exec.c,$(CSRC))
 
+ifneq ($(UCLIBC_HAS_NONREENTRANT),y)
+CSRC := $(filter-out $(patsubst %_r.c,%.c,$(REENTRANT)),$(CSRC))
+endif
+
 ifeq ($(ARCH_USE_MMU),y)
 CSRC := $(filter-out __exec_alloc.c,$(CSRC))
 else
Index: libc/unistd/getlogin.c
===================================================================
--- libc/unistd/getlogin.c	(revision 23369)
+++ libc/unistd/getlogin.c	(working copy)
@@ -27,18 +27,6 @@ char * getlogin(void)
 }
 libc_hidden_def(getlogin)
 
-int getlogin_r(char *name, size_t len)
-{
-	char * foo = getenv("LOGNAME");
-
-	if (! foo)
-		return -1;
-
-	strncpy(name, foo, len);
-	name[len-1] = '\0';
-	return 0;
-}
-
 char *cuserid(char *s)
 {
 	char *name = getlogin();
Index: libc/unistd/getlogin_r.c
===================================================================
--- libc/unistd/getlogin_r.c	(revision 23369)
+++ libc/unistd/getlogin_r.c	(working copy)
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * getlogin for uClibc
+ * getlogin_r for uClibc
  * Copyright (C) 2000-2006 by Erik Andersen <[EMAIL PROTECTED]>
  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  */
@@ -20,13 +20,7 @@ libc_hidden_proto(getenv)
  * the user specify whatever they want via the LOGNAME environment
  * variable, or we return NULL if getenv() fails to find anything */
 
-libc_hidden_proto(getlogin)
-char * getlogin(void)
-{
-	return (getenv("LOGNAME"));
-}
-libc_hidden_def(getlogin)
-
+libc_hidden_proto(getlogin_r)
 int getlogin_r(char *name, size_t len)
 {
 	char * foo = getenv("LOGNAME");
@@ -38,12 +32,4 @@ int getlogin_r(char *name, size_t len)
 	name[len-1] = '\0';
 	return 0;
 }
-
-char *cuserid(char *s)
-{
-	char *name = getlogin();
-	if (s) {
-		return(strcpy(s, name ? name : ""));
-	}
-	return name;
-}
+libc_hidden_def(getlogin_r)

Property changes on: libc/unistd/getlogin_r.c
___________________________________________________________________
Added: svn:mergeinfo

Index: libc/misc/syslog/syslog.c
===================================================================
--- libc/misc/syslog/syslog.c	(revision 23369)
+++ libc/misc/syslog/syslog.c	(working copy)
@@ -96,7 +96,7 @@ libc_hidden_proto(socket)
 libc_hidden_proto(close)
 libc_hidden_proto(write)
 libc_hidden_proto(getpid)
-libc_hidden_proto(ctime)
+libc_hidden_proto(ctime_r)
 libc_hidden_proto(sigaction)
 libc_hidden_proto(sigemptyset)
 libc_hidden_proto(connect)
@@ -232,7 +232,8 @@ vsyslog(int pri, const char *fmt, va_lis
 	 * safe to test only LogTag and use normal sprintf everywhere else.
 	 */
 	(void)time(&now);
-	stdp = p = tbuf + sprintf(tbuf, "<%d>%.15s ", pri, ctime(&now) + 4);
+	stdp = p = tbuf + sprintf(tbuf, "<%d>%.15s ", pri,
+				  ctime_r(&now, tbuf) + 4);
 	if (LogTag) {
 		if (strlen(LogTag) < sizeof(tbuf) - 64)
 			p += sprintf(p, "%s", LogTag);
Index: libc/misc/dirent/readdir.c
===================================================================
--- libc/misc/dirent/readdir.c	(revision 23369)
+++ libc/misc/dirent/readdir.c	(working copy)
@@ -13,9 +13,9 @@
 #include <dirent.h>
 #include "dirstream.h"
 
-libc_hidden_proto(readdir)
-
-struct dirent *readdir(DIR * dir)
+extern __typeof(readdir) __libc_readdir;
+libc_hidden_proto(__libc_readdir)
+struct dirent *__libc_readdir(DIR * dir)
 {
 	ssize_t bytes;
 	struct dirent *de;
@@ -54,4 +54,7 @@ all_done:
 	__UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
 	return de;
 }
-libc_hidden_def(readdir)
+libc_hidden_def(__libc_readdir)
+#ifdef __UCLIBC_HAS_NONREENTRANT__
+libc_hidden_weak(readdir)
+#endif
Index: libc/misc/dirent/scandir.c
===================================================================
--- libc/misc/dirent/scandir.c	(revision 23369)
+++ libc/misc/dirent/scandir.c	(working copy)
@@ -13,11 +13,13 @@
 #include "dirstream.h"
 
 /* Experimentally off - libc_hidden_proto(memcpy) */
-libc_hidden_proto(readdir)
 libc_hidden_proto(opendir)
 libc_hidden_proto(closedir)
 libc_hidden_proto(qsort)
 
+extern __typeof(readdir) __libc_readdir;
+//libc_hidden_proto(__libc_readdir)
+
 int scandir(const char *dir, struct dirent ***namelist,
 	int (*selector) (const struct dirent *),
 	int (*compar) (const void *, const void *))
@@ -35,13 +37,13 @@ int scandir(const char *dir, struct dire
     __set_errno (0);
 
     pos = 0;
-    while ((current = readdir (dp)) != NULL)
+    while ((current = __libc_readdir (dp)) != NULL)
 	if (selector == NULL || (*selector) (current))
 	{
 	    struct dirent *vnew;
 	    size_t dsize;
 
-	    /* Ignore errors from selector or readdir */
+	    /* Ignore errors from selector or __libc_readdir */
 	    __set_errno (0);
 
 	    if (unlikely(pos == names_size))
Index: libc/misc/dirent/readdir64.c
===================================================================
--- libc/misc/dirent/readdir64.c	(revision 23369)
+++ libc/misc/dirent/readdir64.c	(working copy)
@@ -13,8 +13,9 @@
 #include <dirent.h>
 #include "dirstream.h"
 
-libc_hidden_proto(readdir64)
-struct dirent64 *readdir64(DIR * dir)
+extern __typeof(readdir64) __libc_readdir64;
+libc_hidden_proto(__libc_readdir64)
+struct dirent64 *__libc_readdir64(DIR * dir)
 {
 	ssize_t bytes;
 	struct dirent64 *de;
@@ -54,4 +55,7 @@ all_done:
 
 	return de;
 }
-libc_hidden_def(readdir64)
+libc_hidden_def(__libc_readdir64)
+#ifdef __UCLIBC_HAS_NONREENTRANT__
+libc_hidden_weak(readdir64)
+#endif
Index: libc/misc/dirent/scandir64.c
===================================================================
--- libc/misc/dirent/scandir64.c	(revision 23369)
+++ libc/misc/dirent/scandir64.c	(working copy)
@@ -34,7 +34,8 @@
 libc_hidden_proto(opendir)
 libc_hidden_proto(closedir)
 libc_hidden_proto(qsort)
-libc_hidden_proto(readdir64)
+extern __typeof(readdir64) __libc_readdir64;
+//libc_hidden_proto(__libc_readdir64)
 
 int scandir64(const char *dir, struct dirent64 ***namelist,
 	int (*selector) (const struct dirent64 *),
@@ -53,13 +54,13 @@ int scandir64(const char *dir, struct di
     __set_errno (0);
 
     pos = 0;
-    while ((current = readdir64 (dp)) != NULL)
+    while ((current = __libc_readdir64 (dp)) != NULL)
 	if (selector == NULL || (*selector) (current))
 	{
 	    struct dirent64 *vnew;
 	    size_t dsize;
 
-	    /* Ignore errors from selector or readdir64 */
+	    /* Ignore errors from selector or __libc_readdir64 */
 	    __set_errno (0);
 
 	    if (unlikely(pos == names_size))
Index: libc/misc/time/Makefile.in
===================================================================
--- libc/misc/time/Makefile.in	(revision 23369)
+++ libc/misc/time/Makefile.in	(working copy)
@@ -1,6 +1,6 @@
 # Makefile for uClibc
 #
-# Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
+# Copyright (C) 2000-2008 Erik Andersen <[EMAIL PROTECTED]>
 #
 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 #
@@ -10,10 +10,16 @@ ifeq ($(UCLIBC_SUSV3_LEGACY),y)
 CSRC += ftime.c
 endif
 # multi source time.c
-CSRC +=	asctime.c asctime_r.c clock.c ctime.c ctime_r.c gmtime.c gmtime_r.c \
-	localtime.c localtime_r.c mktime.c strftime.c strptime.c tzset.c \
+CSRC += clock.c mktime.c strftime.c strptime.c tzset.c \
 	_time_t2tm.c __time_tm.c _time_mktime.c dysize.c timegm.c \
 	_time_mktime_tzi.c _time_localtime_tzi.c
+
+REENTRANT := asctime ctime gmtime localtime
+CSRC += $(patsubst %,%_r.c,$(REENTRANT))
+ifeq ($(UCLIBC_HAS_NONREENTRANT),y)
+CSRC += $(patsubst %,%.c,$(REENTRANT))
+endif
+
 ifeq ($(UCLIBC_HAS_FLOATS),y)
 CSRC += difftime.c
 endif
Index: libc/misc/time/time.c
===================================================================
--- libc/misc/time/time.c	(revision 23369)
+++ libc/misc/time/time.c	(working copy)
@@ -156,7 +156,7 @@
 
 libc_hidden_proto(asctime)
 libc_hidden_proto(asctime_r)
-libc_hidden_proto(ctime)
+libc_hidden_proto(ctime_r)
 libc_hidden_proto(localtime)
 libc_hidden_proto(localtime_r)
 
@@ -504,7 +504,6 @@ char *ctime(const time_t *t)
 	/* ANSI/ISO/SUSv3 say that ctime is equivalent to the following. */
 	return asctime(localtime(t));
 }
-libc_hidden_def(ctime)
 #endif
 /**********************************************************************/
 #ifdef L_ctime_r
@@ -515,6 +514,7 @@ char *ctime_r(const time_t *t, char *buf
 
 	return asctime_r(localtime_r(t, &xtm), buf);
 }
+libc_hidden_def(ctime_r)
 
 #endif
 /**********************************************************************/
Index: libc/misc/ftw/ftw.c
===================================================================
--- libc/misc/ftw/ftw.c	(revision 23369)
+++ libc/misc/ftw/ftw.c	(working copy)
@@ -96,9 +96,13 @@ libc_hidden_proto(fchdir)
 /* Experimentally off - libc_hidden_proto(mempcpy) */
 libc_hidden_proto(opendir)
 #ifdef __UCLIBC_HAS_LFS__
-libc_hidden_proto(readdir64)
+extern __typeof(readdir64) __libc_readdir64;
+libc_hidden_proto(__libc_readdir64)
 libc_hidden_proto(lstat64)
 libc_hidden_proto(stat64)
+#else
+extern __typeof(readdir) __libc_readdir;
+libc_hidden_proto(__libc_readdir)
 #endif
 libc_hidden_proto(closedir)
 /* Experimentally off - libc_hidden_proto(stpcpy) */
@@ -137,9 +141,9 @@ extern char *xgetcwd (void);
 # define __opendir opendir
 # undef __readdir64
 # ifndef __UCLIBC_HAS_LFS__
-# define __readdir64 readdir
+# define __readdir64 __libc_readdir
 # else
-# define __readdir64 readdir64
+# define __readdir64 __libc_readdir64
 # endif
 # undef __stpcpy
 # define __stpcpy stpcpy
Index: libc/misc/mntent/Makefile.in
===================================================================
--- libc/misc/mntent/Makefile.in	(revision 23369)
+++ libc/misc/mntent/Makefile.in	(working copy)
@@ -6,12 +6,15 @@
 #
 
 CSRC := mntent.c
+ifeq ($(UCLIBC_HAS_NONREENTRANT),y)
+CSRC += getmntent.c
+endif
 
 MISC_MNTENT_DIR := $(top_srcdir)libc/misc/mntent
 MISC_MNTENT_OUT := $(top_builddir)libc/misc/mntent
 
-MISC_MNTENT_SRC := $(MISC_MNTENT_DIR)/mntent.c
-MISC_MNTENT_OBJ := $(MISC_MNTENT_OUT)/mntent.o
+MISC_MNTENT_SRC := $(patsubst %.c,$(MISC_MNTENT_DIR)/%.c,$(CSRC))
+MISC_MNTENT_OBJ := $(patsubst %.c,$(MISC_MNTENT_OUT)/%.o,$(CSRC))
 
 libc-y += $(MISC_MNTENT_OBJ)
 
Index: libc/misc/mntent/mntent.c
===================================================================
--- libc/misc/mntent/mntent.c	(revision 23369)
+++ libc/misc/mntent/mntent.c	(working copy)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
  *
@@ -10,8 +11,6 @@
 #include <mntent.h>
 #include <bits/uClibc_mutex.h>
 
-__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
-
 libc_hidden_proto(getmntent_r)
 libc_hidden_proto(setmntent)
 libc_hidden_proto(endmntent)
@@ -26,6 +25,29 @@ libc_hidden_proto(fgets)
 libc_hidden_proto(abort)
 libc_hidden_proto(fprintf)
 
+#ifdef L_getmntent
+
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
+
+struct mntent *getmntent(FILE * filep)
+{
+    struct mntent *tmp;
+    static char *buff = NULL;
+    static struct mntent mnt;
+    __UCLIBC_MUTEX_LOCK(mylock);
+
+    if (!buff) {
+            buff = malloc(BUFSIZ);
+		if (!buff)
+		    abort();
+    }
+
+    tmp = getmntent_r(filep, &mnt, buff, BUFSIZ);
+    __UCLIBC_MUTEX_UNLOCK(mylock);
+    return(tmp);
+}
+#else
+
 /* Reentrant version of getmntent.  */
 struct mntent *getmntent_r (FILE *filep,
 	struct mntent *mnt, char *buff, int bufsize)
@@ -76,24 +98,6 @@ struct mntent *getmntent_r (FILE *filep,
 }
 libc_hidden_def(getmntent_r)
 
-struct mntent *getmntent(FILE * filep)
-{
-    struct mntent *tmp;
-    static char *buff = NULL;
-    static struct mntent mnt;
-    __UCLIBC_MUTEX_LOCK(mylock);
-
-    if (!buff) {
-            buff = malloc(BUFSIZ);
-		if (!buff)
-		    abort();
-    }
-
-    tmp = getmntent_r(filep, &mnt, buff, BUFSIZ);
-    __UCLIBC_MUTEX_UNLOCK(mylock);
-    return(tmp);
-}
-
 int addmntent(FILE * filep, const struct mntent *mnt)
 {
 	if (fseek(filep, 0, SEEK_END) < 0)
@@ -121,3 +125,4 @@ int endmntent(FILE * filep)
 	return 1;
 }
 libc_hidden_def(endmntent)
+#endif
Index: libc/misc/search/Makefile.in
===================================================================
--- libc/misc/search/Makefile.in	(revision 23369)
+++ libc/misc/search/Makefile.in	(working copy)
@@ -1,11 +1,14 @@
 # Makefile for uClibc
 #
-# Copyright (C) 2000-2006 Erik Andersen <[EMAIL PROTECTED]>
+# Copyright (C) 2000-2008 Erik Andersen <[EMAIL PROTECTED]>
 #
 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 #
 
-CSRC := hsearch.c
+CSRC :=
+ifeq ($(UCLIBC_HAS_NONREENTRANT),y)
+CSRC += hsearch.c
+endif
 
 # multi source _tsearch.c
 CSRC += tsearch.c tfind.c tdelete.c twalk.c tdestroy.c
_______________________________________________
uClibc mailing list
uClibc@uclibc.org
http://busybox.net/cgi-bin/mailman/listinfo/uclibc

Reply via email to