put reasonable header on it
[unix-history] / usr / src / lib / libc / gen / getpwent.c
index 8d2ec3a..66ace45 100644 (file)
@@ -1,20 +1,33 @@
-/* @(#)getpwent.c      4.2 (Berkeley) %G% */
+/*
+ * Copyright (c) 1984 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getpwent.c 5.2 (Berkeley) %G%";
+#endif LIBC_SCCS and not lint
+
 #include <stdio.h>
 #include <pwd.h>
 #include <ndbm.h>
 
 #include <stdio.h>
 #include <pwd.h>
 #include <ndbm.h>
 
-static char PASSWD[]   = "/etc/passwd";
 static char EMPTY[] = "";
 static FILE *pwf = NULL;
 static char line[BUFSIZ+1];
 static struct passwd passwd;
 static char EMPTY[] = "";
 static FILE *pwf = NULL;
 static char line[BUFSIZ+1];
 static struct passwd passwd;
-extern DBM *_pw_db;
-extern int _pw_stayopen;
+
+/*
+ * The following are shared with getpwnamuid.c
+ */
+char   *_pw_file = "/etc/passwd";
+DBM    *_pw_db;
+int    _pw_stayopen;
 
 setpwent()
 {
        if (pwf == NULL)
 
 setpwent()
 {
        if (pwf == NULL)
-               pwf = fopen(PASSWD, "r");
+               pwf = fopen(_pw_file, "r");
        else
                rewind(pwf);
 }
        else
                rewind(pwf);
 }
@@ -26,7 +39,7 @@ endpwent()
                pwf = NULL;
        }
        if (_pw_db != (DBM *)0) {
                pwf = NULL;
        }
        if (_pw_db != (DBM *)0) {
-               ndbmclose(_pw_db);
+               dbm_close(_pw_db);
                _pw_db = (DBM *)0;
                _pw_stayopen = 0;
        }
                _pw_db = (DBM *)0;
                _pw_stayopen = 0;
        }
@@ -36,7 +49,7 @@ static char *
 pwskip(p)
 register char *p;
 {
 pwskip(p)
 register char *p;
 {
-       while (*p && *p != ':')
+       while (*p && *p != ':' && *p != '\n')
                ++p;
        if (*p)
                *p++ = 0;
                ++p;
        if (*p)
                *p++ = 0;
@@ -49,7 +62,7 @@ getpwent()
        register char *p;
 
        if (pwf == NULL) {
        register char *p;
 
        if (pwf == NULL) {
-               if ((pwf = fopen( PASSWD, "r" )) == NULL)
+               if ((pwf = fopen( _pw_file, "r" )) == NULL)
                        return(0);
        }
        p = fgets(line, BUFSIZ, pwf);
                        return(0);
        }
        p = fgets(line, BUFSIZ, pwf);
@@ -75,3 +88,9 @@ getpwent()
        *p = '\0';
        return(&passwd);
 }
        *p = '\0';
        return(&passwd);
 }
+
+setpwfile(file)
+       char *file;
+{
+       _pw_file = file;
+}