about summary refs log tree commit diff
path: root/pwd/getpw.c
diff options
context:
space:
mode:
Diffstat (limited to 'pwd/getpw.c')
-rw-r--r--pwd/getpw.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/pwd/getpw.c b/pwd/getpw.c
index 402fafd7f0..9c2e4afd0a 100644
--- a/pwd/getpw.c
+++ b/pwd/getpw.c
@@ -1,23 +1,25 @@
 /* Copyright (C) 1991, 1992, 1996 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
+   This file is part of the GNU C Library.
 
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
 
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Library General Public License for more details.
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
 
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
 
+#include <alloca.h>
 #include <errno.h>
 #include <stdio.h>
+#include <unistd.h>
 #include <pwd.h>
 
 
@@ -30,9 +32,11 @@ int __getpw __P ((__uid_t uid, char *buf));
 int
 __getpw (uid, buf)
      __uid_t uid;
-     register char *buf;
+     char *buf;
 {
-  register struct passwd *p;
+  size_t buflen;
+  char *tmpbuf;
+  struct passwd resbuf, *p;
 
   if (buf == NULL)
     {
@@ -40,8 +44,10 @@ __getpw (uid, buf)
       return -1;
     }
 
-  p = getpwuid (uid);
-  if (p == NULL)
+  buflen = __sysconf (_SC_GETPW_R_SIZE_MAX);
+  tmpbuf = alloca (buflen);
+
+  if (getpwuid_r (uid, &resbuf, tmpbuf, buflen, &p) < 0)
     return -1;
 
   if (sprintf (buf, "%s:%s:%u:%u:%s:%s:%s", p->pw_name, p->pw_passwd,