clean up comment handling some more, keep shells straight
[unix-history] / usr / src / lib / libc / gen / getpwent.c
index 9610774..66ace45 100644 (file)
@@ -1,36 +1,58 @@
-/* @(#)getpwent.c      4.1 (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 <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;
 
+/*
+ * The following are shared with getpwnamuid.c
+ */
+char   *_pw_file = "/etc/passwd";
+DBM    *_pw_db;
+int    _pw_stayopen;
+
 setpwent()
 {
 setpwent()
 {
-       if( pwf == NULL )
-               pwf = fopen( PASSWD, "r" );
+       if (pwf == NULL)
+               pwf = fopen(_pw_file, "r");
        else
        else
-               rewind( pwf );
+               rewind(pwf);
 }
 
 endpwent()
 {
 }
 
 endpwent()
 {
-       if( pwf != NULL ){
-               fclose( pwf );
+       if (pwf != NULL) {
+               fclose(pwf);
                pwf = NULL;
        }
                pwf = NULL;
        }
+       if (_pw_db != (DBM *)0) {
+               dbm_close(_pw_db);
+               _pw_db = (DBM *)0;
+               _pw_stayopen = 0;
+       }
 }
 
 static char *
 pwskip(p)
 register char *p;
 {
 }
 
 static char *
 pwskip(p)
 register char *p;
 {
-       while( *p && *p != ':' )
+       while (*p && *p != ':' && *p != '\n')
                ++p;
                ++p;
-       if( *p ) *p++ = 0;
+       if (*p)
+               *p++ = 0;
        return(p);
 }
 
        return(p);
 }
 
@@ -40,11 +62,11 @@ 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);
-       if (p==NULL)
+       if (p == NULL)
                return(0);
        passwd.pw_name = p;
        p = pwskip(p);
                return(0);
        passwd.pw_name = p;
        p = pwskip(p);
@@ -61,7 +83,14 @@ getpwent()
        passwd.pw_dir = p;
        p = pwskip(p);
        passwd.pw_shell = p;
        passwd.pw_dir = p;
        p = pwskip(p);
        passwd.pw_shell = p;
-       while(*p && *p != '\n') p++;
+       while (*p && *p != '\n')
+               p++;
        *p = '\0';
        return(&passwd);
 }
        *p = '\0';
        return(&passwd);
 }
+
+setpwfile(file)
+       char *file;
+{
+       _pw_file = file;
+}