diff options
Diffstat (limited to 'posix')
-rw-r--r-- | posix/getconf.c | 9 | ||||
-rw-r--r-- | posix/glob.c | 45 |
2 files changed, 49 insertions, 5 deletions
diff --git a/posix/getconf.c b/posix/getconf.c index f4f47650b7..5b67a281df 100644 --- a/posix/getconf.c +++ b/posix/getconf.c @@ -231,7 +231,14 @@ main (int argc, char *argv[]) if (argc > 2) usage (); value = sysconf (c->call_name); - printf ("%ld\n", value); + if (value == -1l) + if (c->call_name == _SC_UINT_MAX + || c->call_name == _SC_ULONG_MAX) + printf ("%lu\n", value); + else + puts (_("undefined")); + else + printf ("%ld\n", value); exit (0); case CONFSTR: 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 <stddef.h> #endif -#ifdef HAVE_UNISTD_H +#if defined HAVE_UNISTD_H || defined _LIBC #include <unistd.h> #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 } |