Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libcompat/4.4 Use getpwuid_r, KNF. From John Nemeth, man...



details:   https://anonhg.NetBSD.org/src/rev/d2830a8ff9aa
branches:  trunk
changeset: 579937:d2830a8ff9aa
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Apr 01 12:51:07 2005 +0000

description:
Use getpwuid_r, KNF. From John Nemeth, many thanks.

diffstat:

 lib/libcompat/4.4/cuserid.3 |  14 +-------------
 lib/libcompat/4.4/cuserid.c |  18 +++++++++---------
 2 files changed, 10 insertions(+), 22 deletions(-)

diffs (70 lines):

diff -r cfeabcf7e96c -r d2830a8ff9aa lib/libcompat/4.4/cuserid.3
--- a/lib/libcompat/4.4/cuserid.3       Fri Apr 01 12:37:27 2005 +0000
+++ b/lib/libcompat/4.4/cuserid.3       Fri Apr 01 12:51:07 2005 +0000
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     from: @(#)ctermid.3    5.2 (Berkeley) 4/19/91
-.\"    $NetBSD: cuserid.3,v 1.11 2003/08/07 16:44:17 agc Exp $
+.\"    $NetBSD: cuserid.3,v 1.12 2005/04/01 12:51:07 christos Exp $
 .\"
 .Dd November 28, 1993
 .Dt CUSERID 3
@@ -118,15 +118,3 @@
 .Nm getpwuid Ns Pq Fn getuid
 to return the user name associated with the calling process' real user ID.
 .El
-.Pp
-The
-.Fn cuserid
-function uses
-.Fn getpwuid ;
-thus the results of a user's call to
-.Fn getpwent ,
-.Fn getpwnam
-or
-.Fn getpwuid
-will be overwritten by subsequent calls to
-.Fn cuserid .
diff -r cfeabcf7e96c -r d2830a8ff9aa lib/libcompat/4.4/cuserid.c
--- a/lib/libcompat/4.4/cuserid.c       Fri Apr 01 12:37:27 2005 +0000
+++ b/lib/libcompat/4.4/cuserid.c       Fri Apr 01 12:51:07 2005 +0000
@@ -32,7 +32,7 @@
 #if 0
 static char sccsid[] = "@(#)cuserid.c  8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: cuserid.c,v 1.6 2003/08/07 16:44:17 agc Exp $");
+__RCSID("$NetBSD: cuserid.c,v 1.7 2005/04/01 12:51:07 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -42,21 +42,21 @@
 #include <unistd.h>
 
 char *
-cuserid(s)
-       char *s;
+cuserid(char *s)
 {
-       struct passwd *pw;
+       struct passwd *pw, pwres;
        static char buf[L_cuserid];
+       char pwbuf[1024];
 
        /* s may be NULL */
 
-       if ((pw = getpwuid(geteuid())) == NULL) {
-               if (s)
+       if (getpwuid_r(geteuid(), &pwres, pwbuf, sizeof(pwbuf), &pw) != 0) {
+               if (s != NULL)
                        *s = '\0';
-               return (s);
+               return s;
        }
-       if (!s)
+       if (s == NULL)
                s = buf;
        (void)strncpy(s, pw->pw_name, L_cuserid);
-       return (s);
+       return s;
 }



Home | Main Index | Thread Index | Old Index