From e4cf5070694529a8779d5e1581567bcfb9307da0 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Mon, 2 Dec 1996 04:00:15 +0000 Subject: update from main archive 961201 Mon Dec 2 03:59:38 1996 Ulrich Drepper * grp/initgroups.c: Update and reformat copyright. Use __getgrent_r instead of getgrent. * inet/rcmd.c: Update and reformat copyright. Use __gethostbyname_r instead of gethostbyname. * inet/rexec.c: Likewise. * intl/finddomain.c: Correct comment about CEN sponsor and revision. * locale/findlocale.c: Likewise. * intl/l10nflist.c: Correct handling of CEN sponsor and revision. * locale/Makefile (CPPFLAGS): Add definition of LOCALEDIR. * locale/setlocale.c (setlocale): Correctly split value of LOCALE_PATH. * locale/programs/localedef.c: Use LOCALEDIR not LOCALE_PATH to find output directory. * nss/getXXbyYY.c [NEED_H_ERRNO]: Before enlarging buffer test h_errno_tmp variable. Save error value from being changed during `free' call. * nss/getXXent.c: Likewise. * nss/nss_files/files-XXX.c: Set h_errno variable to NETDB_INTERNAL before returning ERANGE error. * posix/glob.c: Use getlogin_r and getpwnam_r function when available or in GNU libc. * pwd/getpw.c: Use getpwuid_r instead of getpwuid. * sunrpc/clnt_gen.c: Use gethostbyname_r and getprotobyname_r. * sunrpc/clnt_simp.c: Likewise. * sunrpc/getrpcport.c: Likewise. * sysdeps/unix/sysv/linux/gethostid.c: Likewise. * posix/getconf.c: Treat _SC_UNIT_MAX and _SC_ULONG_MAX separately since the value might be outsode the range of the `long int'. Print string `undefined' when a value is undefined. * stdlib/l64a.c: Return correct pointer. Patch by NIIBE Yutaka . * string/Makefile (routines): Add argz-addsep. * string/argz-addsep.c: New file. * string/argz.h: Add prototypes for argz_add_sep. * string/argz-ctsep.c: Prevent memory leak. * string/strcoll.c: Correct typo in comment. Sat Nov 30 02:53:59 1996 Ulrich Drepper * sysdeps/unix/sysv/linux/sys/serial.h: Removed again. The file is not general enough to be part of the libc. * sysdeps/unix/sysv/linux/Dist: Remove sys/serial.h. * sysdeps/unix/sysv/linux/Makefile: Don't install sys/serial.h. Thu Nov 28 20:04:41 1996 Andreas Schwab * login/Makefile: Fix typo. * nss/Makefile (generated): Filter out db-alias.c. Thu Nov 28 14:44:01 1996 Andreas Schwab * time/Makefile (echo-zonenames): Don't depend on non-existing target `zonenames'. Thu Nov 28 12:34:05 1996 Andreas Schwab * link.h: New file. * nss/nsswitch.c: Use it. * printf.h: Fix file name. * stdlib/strfmon.c: Use it. --- posix/glob.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'posix/glob.c') diff --git a/posix/glob.c b/posix/glob.c index b8820cee94..0fa15611bd 100644 --- a/posix/glob.c +++ b/posix/glob.c @@ -56,7 +56,7 @@ Cambridge, MA 02139, USA. */ #include #endif -#ifdef HAVE_UNISTD_H +#if defined HAVE_UNISTD_H || defined _LIBC #include #ifndef POSIX #ifdef _POSIX_VERSION @@ -467,11 +467,40 @@ glob (pattern, flags, errfunc, pglob) if (dirname == NULL || dirname[0] == '\0') { extern char *getlogin __P ((void)); - char *name = getlogin (); - if (name != NULL) + extern int getlogin_r __P ((char *, size_t)); + int success; + +#if defined HAVE_GETLOGIN_R || defined _LIBC + size_t buflen = sysconf (_SC_LOGIN_NAME_MAX) + 1; + char *name; + + if (buflen == 0) + /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try + a moderate value. */ + buflen = 16; + name = __alloca (buflen); + + success = getlogin_r (name, buflen) >= 0; +#else + char *name; + success = (name = getlogin ()) != NULL; +#endif + if (success) { +#if defined HAVE_GETPWNAM_R || defined _LIBC + size_t pwbuflen = sysconf (_SC_GETPW_R_SIZE_MAX); + char *pwtmpbuf; + struct passwd pwbuf, *p; + + pwtmpbuf = __alloca (pwbuflen); + + success = (__getpwnam_r (name, &pwbuf, pwtmpbuf, + pwbuflen, &p) >= 0); +#else struct passwd *p = getpwnam (name); - if (p != NULL) + success = p != NULL; +#endif + if (success) dirname = p->pw_dir; } } @@ -491,9 +520,17 @@ glob (pattern, flags, errfunc, pglob) dirname = "c:/users/default"; /* poor default */ #else /* Look up specific user's home directory. */ +#if defined HAVE_GETPWNAM_R || defined _LIBC + size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX); + char *pwtmpbuf = __alloca (buflen); + struct passwd pwbuf, *p; + if (__getpwnam_r (dirname + 1, &pwbuf, pwtmpbuf, buflen, &p) >= 0) + dirname = p->pw_dir; +#else struct passwd *p = getpwnam (dirname + 1); if (p != NULL) dirname = p->pw_dir; +#endif #endif /* WIN32 */ #endif } -- cgit v1.2.3