Browse Source

Silence warnings, clean things up.
-Erik

Eric Andersen 23 years ago
parent
commit
c617db9065

+ 0 - 1
libc/pwd_grp/__getgrent.c

@@ -21,7 +21,6 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
-#include <grp.h>
 #include "config.h"
 
 /*

+ 1 - 1
libc/pwd_grp/__getpwent_r.c

@@ -24,7 +24,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <fcntl.h>
-#include <pwd.h>
+#include "config.h"
 
 
 /* This isn't as flash as my previous version -- it doesn't dynamically

+ 1 - 1
libc/pwd_grp/__getspent_r.c

@@ -20,7 +20,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <fcntl.h>
-#include <shadow.h>
+#include "config.h"
 
 
 int __getspent_r(struct spwd * spwd, char * line_buff, size_t buflen, int spwd_fd)

+ 1 - 1
libc/pwd_grp/__sgetspent_r.c

@@ -19,7 +19,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
-#include <shadow.h>
+#include "config.h"
 
 
 int __sgetspent_r(const char * string, struct spwd * spwd, char * line_buff, size_t buflen)

+ 9 - 0
libc/pwd_grp/config.h

@@ -24,12 +24,21 @@
 
 #include <pwd.h>
 #include <grp.h>
+#include <shadow.h>
 
 /* These are used internally to uClibc */
 extern struct group * __getgrent __P ((int grp_fd));
 
 extern int __getpwent_r(struct passwd * passwd, char * line_buff, 
 	size_t buflen, int pwd_fd);
+extern int __getspent_r(struct spwd * spwd, char * line_buff, 
+	size_t buflen, int spwd_fd);
+extern int __sgetspent_r(const char * string, struct spwd * spwd, 
+	char * line_buff, size_t buflen);
+
+
+#define PWD_BUFFER_SIZE 256
+
   
 /*
  * Define GR_SCALE_DYNAMIC if you want grp to dynamically scale its read buffer

+ 0 - 1
libc/pwd_grp/fgetgrent.c

@@ -20,7 +20,6 @@
 
 #include <stdio.h>
 #include <errno.h>
-#include <grp.h>
 #include "config.h"
 
 struct group *fgetgrent(FILE * file)

+ 9 - 13
libc/pwd_grp/fgetpwent.c

@@ -20,28 +20,24 @@
 
 #include <errno.h>
 #include <stdio.h>
-#include <pwd.h>
 #include "config.h"
 
-#define PWD_BUFFER_SIZE 256
-
-/* file descriptor for the password file currently open */
-static char line_buff[PWD_BUFFER_SIZE];
-static struct passwd pwd;
-
 int fgetpwent_r (FILE *file, struct passwd *password,
 	char *buff, size_t buflen, struct passwd **crap)
 {
-	if (file == NULL) {
-		__set_errno(EINTR);
-		return -1;
-	}
-	return(__getpwent_r(password, buff, buflen, fileno(file)));
+    if (file == NULL) {
+	__set_errno(EINTR);
+	return -1;
+    }
+    return(__getpwent_r(password, buff, buflen, fileno(file)));
 }
 
 struct passwd *fgetpwent(FILE * file)
 {
-    if (fgetpwent_r(file, &pwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) {
+    static char line_buff[PWD_BUFFER_SIZE];
+    static struct passwd pwd;
+
+    if (fgetpwent_r(file, &pwd, line_buff, sizeof(line_buff), NULL) != -1) {
 	return &pwd;
     }
     return NULL;

+ 2 - 4
libc/pwd_grp/fgetspent.c

@@ -19,9 +19,7 @@
 
 #include <errno.h>
 #include <stdio.h>
-#include <shadow.h>
-
-#define PWD_BUFFER_SIZE 256
+#include "config.h"
 
 int fgetspent_r (FILE *file, struct spwd *spwd,
 	char *buff, size_t buflen, struct spwd **crap)
@@ -38,7 +36,7 @@ struct spwd *fgetspent(FILE * file)
 	static char line_buff[PWD_BUFFER_SIZE];
 	static struct spwd spwd;
 
-	if (fgetspent_r(file, &spwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) {
+	if (fgetspent_r(file, &spwd, line_buff, sizeof(line_buff), NULL) != -1) {
 		return &spwd;
 	}
 	return NULL;

+ 0 - 1
libc/pwd_grp/getgrgid.c

@@ -21,7 +21,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <grp.h>
 #include <paths.h>
 #include "config.h"
 

+ 0 - 1
libc/pwd_grp/getgrnam.c

@@ -22,7 +22,6 @@
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <grp.h>
 #include <paths.h>
 #include "config.h"
 

+ 1 - 1
libc/pwd_grp/getpw.c

@@ -21,7 +21,7 @@
 #include <sys/types.h>
 #include <errno.h>
 #include <stdio.h>
-#include <pwd.h>
+#include "config.h"
 
 int getpw(uid_t uid, char *buf)
 {

+ 18 - 23
libc/pwd_grp/getpwnam.c

@@ -22,43 +22,38 @@
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <pwd.h>
 #include <paths.h>
 #include "config.h"
 
-#define PWD_BUFFER_SIZE 256
-
-/* file descriptor for the password file currently open */
-static char line_buff[PWD_BUFFER_SIZE];
-static struct passwd pwd;
-
-
 int getpwnam_r (const char *name, struct passwd *password,
 	char *buff, size_t buflen, struct passwd **crap)
 {
-	int passwd_fd;
+    int passwd_fd;
 
-	if (name == NULL) {
-		__set_errno(EINVAL);
-		return -1;
-	}
+    if (name == NULL) {
+	__set_errno(EINVAL);
+	return -1;
+    }
 
-	if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0)
-		return -1;
+    if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0)
+	return -1;
 
-	while (__getpwent_r(password, buff, buflen, passwd_fd) != -1)
-		if (!strcmp(password->pw_name, name)) {
-			close(passwd_fd);
-			return 0;
-		}
+    while (__getpwent_r(password, buff, buflen, passwd_fd) != -1)
+	if (!strcmp(password->pw_name, name)) {
+	    close(passwd_fd);
+	    return 0;
+	}
 
-	close(passwd_fd);
-	return -1;
+    close(passwd_fd);
+    return -1;
 }
 
 struct passwd *getpwnam(const char *name)
 {
-    if (getpwnam_r(name, &pwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) {
+    static char line_buff[PWD_BUFFER_SIZE];
+    static struct passwd pwd;
+
+    if (getpwnam_r(name, &pwd, line_buff, sizeof(line_buff), NULL) != -1) {
 	return &pwd;
     }
     return NULL;

+ 15 - 18
libc/pwd_grp/getpwuid.c

@@ -21,37 +21,34 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <pwd.h>
 #include <paths.h>
 #include "config.h"
 
-#define PWD_BUFFER_SIZE 256
-
-/* file descriptor for the password file currently open */
-static char line_buff[PWD_BUFFER_SIZE];
-static struct passwd pwd;
-
 int getpwuid_r (uid_t uid, struct passwd *password,
 	char *buff, size_t buflen, struct passwd **crap)
 {
-	int passwd_fd;
+    int passwd_fd;
 
-	if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0)
-		return -1;
+    if ((passwd_fd = open(_PATH_PASSWD, O_RDONLY)) < 0)
+	return -1;
 
-	while (__getpwent_r(password, buff, buflen, passwd_fd) != -1)
-		if (password->pw_uid == uid) {
-			close(passwd_fd);
-			return 0;
-		}
+    while (__getpwent_r(password, buff, buflen, passwd_fd) != -1)
+	if (password->pw_uid == uid) {
+	    close(passwd_fd);
+	    return 0;
+	}
 
-	close(passwd_fd);
-	return -1;
+    close(passwd_fd);
+    return -1;
 }
 
 struct passwd *getpwuid(uid_t uid)
 {
-    if (getpwuid_r(uid, &pwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) {
+    /* file descriptor for the password file currently open */
+    static char line_buff[PWD_BUFFER_SIZE];
+    static struct passwd pwd;
+
+    if (getpwuid_r(uid, &pwd, line_buff,  sizeof(line_buff), NULL) != -1) {
 	return &pwd;
     }
     return NULL;

+ 21 - 23
libc/pwd_grp/getspnam.c

@@ -21,41 +21,39 @@
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <shadow.h>
-
-#define PWD_BUFFER_SIZE 256
+#include "config.h"
 
 int getspnam_r (const char *name, struct spwd *spwd,
 	char *buff, size_t buflen, struct spwd **crap)
 {
-	int spwd_fd;
+    int spwd_fd;
 
-	if (name == NULL) {
-		__set_errno(EINVAL);
-		return -1;
-	}
+    if (name == NULL) {
+	__set_errno(EINVAL);
+	return -1;
+    }
 
-	if ((spwd_fd = open(_PATH_SHADOW, O_RDONLY)) < 0)
-		return -1;
+    if ((spwd_fd = open(_PATH_SHADOW, O_RDONLY)) < 0)
+	return -1;
 
-	while (__getspent_r(spwd, buff, buflen, spwd_fd) != -1)
-		if (!strcmp(spwd->sp_namp, name)) {
-			close(spwd_fd);
-			return 0;
-		}
+    while (__getspent_r(spwd, buff, buflen, spwd_fd) != -1)
+	if (!strcmp(spwd->sp_namp, name)) {
+	    close(spwd_fd);
+	    return 0;
+	}
 
-	close(spwd_fd);
-	return -1;
+    close(spwd_fd);
+    return -1;
 }
 
 struct spwd *getspnam(const char *name)
 {
-	static char line_buff[PWD_BUFFER_SIZE];
-	static struct spwd spwd;
+    static char line_buff[PWD_BUFFER_SIZE];
+    static struct spwd spwd;
 
-	if (getspnam_r(name, &spwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) {
-		return &spwd;
-	}
-	return NULL;
+    if (getspnam_r(name, &spwd, line_buff,  sizeof(line_buff), NULL) != -1) {
+	return &spwd;
+    }
+    return NULL;
 }
 

+ 12 - 15
libc/pwd_grp/getspuid.c

@@ -20,31 +20,28 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <pwd.h>
-#include <shadow.h>
-
-#define PWD_BUFFER_SIZE 256
+#include "config.h"
 
 int getspuid_r (uid_t uid, struct spwd *spwd,
 	char *buff, size_t buflen, struct spwd **crap)
 {
-	char pwd_buff[PWD_BUFFER_SIZE];
-	struct passwd password;
+    char pwd_buff[PWD_BUFFER_SIZE];
+    struct passwd password;
 
-	if (getpwuid_r(uid, &password, pwd_buff, PWD_BUFFER_SIZE, NULL) < 0)
-		return -1;
+    if (getpwuid_r(uid, &password, pwd_buff,  sizeof(pwd_buff), NULL) < 0)
+	return -1;
 
-	return getspnam_r(password.pw_name, spwd, buff, buflen, crap);
+    return getspnam_r(password.pw_name, spwd, buff, buflen, crap);
 }
 
 struct spwd *getspuid(uid_t uid)
 {
-	static char line_buff[PWD_BUFFER_SIZE];
-	static struct spwd spwd;
+    static char line_buff[PWD_BUFFER_SIZE];
+    static struct spwd spwd;
 
-	if (getspuid_r(uid, &spwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) {
-		return &spwd;
-	}
-	return NULL;
+    if (getspuid_r(uid, &spwd, line_buff, sizeof(line_buff), NULL) != -1) {
+	return &spwd;
+    }
+    return NULL;
 }
 

+ 0 - 1
libc/pwd_grp/grent.c

@@ -26,7 +26,6 @@
 
 #include <unistd.h>
 #include <fcntl.h>
-#include <grp.h>
 #include <paths.h>
 #include "config.h"
 

+ 0 - 1
libc/pwd_grp/initgroups.c

@@ -21,7 +21,6 @@
 #include <unistd.h>
 #include <string.h>
 #include <fcntl.h>
-#include <grp.h>
 #include <paths.h>
 #include "config.h"
 

+ 109 - 114
libc/pwd_grp/lckpwdf.c

@@ -19,7 +19,6 @@
    Boston, MA 02111-1307, USA.  */
 
 #include <fcntl.h>
-#include <shadow.h>
 #include <signal.h>
 #include <string.h>
 #include <unistd.h>
@@ -37,127 +36,123 @@ static int lock_fd = -1;
 static void noop_handler __P ((int __sig));
 
 
-int
-lckpwdf ()
+int lckpwdf (void)
 {
-	int flags;
-	sigset_t saved_set;         /* Saved set of caught signals.  */
-	struct sigaction saved_act; /* Saved signal action.  */
-	sigset_t new_set;           /* New set of caught signals.  */
-	struct sigaction new_act;   /* New signal action.  */
-	struct flock fl;            /* Information struct for locking.  */
-	int result;
-
-	if (lock_fd != -1)
-		/* Still locked by own process.  */
-		return -1;
-
-	lock_fd = open (_PATH_PASSWD, O_WRONLY);
-	if (lock_fd == -1)
-		/* Cannot create lock file.  */
-		return -1;
-
-	/* Make sure file gets correctly closed when process finished.  */
-	flags = fcntl (lock_fd, F_GETFD, 0);
-	if (flags == -1) {
-		/* Cannot get file flags.  */
-		close(lock_fd);
-		lock_fd = -1;
-		return -1;
-	}
-	flags |= FD_CLOEXEC;		/* Close on exit.  */
-	if (fcntl (lock_fd, F_SETFD, flags) < 0) {
-		/* Cannot set new flags.  */
-		close(lock_fd);
-		lock_fd = -1;
-		return -1;
-	}
-
-	/* Now we have to get exclusive write access.  Since multiple
-	   process could try this we won't stop when it first fails.
-	   Instead we set a timeout for the system call.  Once the timer
-	   expires it is likely that there are some problems which cannot be
-	   resolved by waiting.
-	   
-	   It is important that we don't change the signal state.  We must
-	   restore the old signal behaviour.  */
-	memset (&new_act, '\0', sizeof (struct sigaction));
-	new_act.sa_handler = noop_handler;
-	sigfillset (&new_act.sa_mask);
-	new_act.sa_flags = 0ul;
-
-	/* Install new action handler for alarm and save old.  */
-	if (sigaction (SIGALRM, &new_act, &saved_act) < 0) {
-		/* Cannot install signal handler.  */
-		close(lock_fd);
-		lock_fd = -1;
-		return -1;
-	}
-
-	/* Now make sure the alarm signal is not blocked.  */
-	sigemptyset (&new_set);
-	sigaddset (&new_set, SIGALRM);
-	if (sigprocmask (SIG_UNBLOCK, &new_set, &saved_set) < 0) {
-		sigaction (SIGALRM, &saved_act, NULL);
-		close(lock_fd);
-		lock_fd = -1;
-		return -1;
-	}
-
-	/* Start timer.  If we cannot get the lock in the specified time we
-	   get a signal.  */
-	alarm (TIMEOUT);
-
-	/* Try to get the lock.  */
-	memset (&fl, '\0', sizeof (struct flock));
-	fl.l_type = F_WRLCK;
-	fl.l_whence = SEEK_SET;
-	result = fcntl (lock_fd, F_SETLKW, &fl);
-
-	/* Clear alarm.  */
-	alarm (0);
-
-	/* Restore old set of handled signals.  We don't need to know
-	   about the current one.*/
-	sigprocmask (SIG_SETMASK, &saved_set, NULL);
-
-	/* Restore old action handler for alarm.  We don't need to know
-	   about the current one.  */
+    int flags;
+    sigset_t saved_set;         /* Saved set of caught signals.  */
+    struct sigaction saved_act; /* Saved signal action.  */
+    sigset_t new_set;           /* New set of caught signals.  */
+    struct sigaction new_act;   /* New signal action.  */
+    struct flock fl;            /* Information struct for locking.  */
+    int result;
+
+    if (lock_fd != -1)
+	/* Still locked by own process.  */
+	return -1;
+
+    lock_fd = open (_PATH_PASSWD, O_WRONLY);
+    if (lock_fd == -1)
+	/* Cannot create lock file.  */
+	return -1;
+
+    /* Make sure file gets correctly closed when process finished.  */
+    flags = fcntl (lock_fd, F_GETFD, 0);
+    if (flags == -1) {
+	/* Cannot get file flags.  */
+	close(lock_fd);
+	lock_fd = -1;
+	return -1;
+    }
+    flags |= FD_CLOEXEC;		/* Close on exit.  */
+    if (fcntl (lock_fd, F_SETFD, flags) < 0) {
+	/* Cannot set new flags.  */
+	close(lock_fd);
+	lock_fd = -1;
+	return -1;
+    }
+
+    /* Now we have to get exclusive write access.  Since multiple
+       process could try this we won't stop when it first fails.
+       Instead we set a timeout for the system call.  Once the timer
+       expires it is likely that there are some problems which cannot be
+       resolved by waiting.
+
+       It is important that we don't change the signal state.  We must
+       restore the old signal behaviour.  */
+    memset (&new_act, '\0', sizeof (struct sigaction));
+    new_act.sa_handler = noop_handler;
+    sigfillset (&new_act.sa_mask);
+    new_act.sa_flags = 0ul;
+
+    /* Install new action handler for alarm and save old.  */
+    if (sigaction (SIGALRM, &new_act, &saved_act) < 0) {
+	/* Cannot install signal handler.  */
+	close(lock_fd);
+	lock_fd = -1;
+	return -1;
+    }
+
+    /* Now make sure the alarm signal is not blocked.  */
+    sigemptyset (&new_set);
+    sigaddset (&new_set, SIGALRM);
+    if (sigprocmask (SIG_UNBLOCK, &new_set, &saved_set) < 0) {
 	sigaction (SIGALRM, &saved_act, NULL);
-
-	if (result < 0) {
-		close(lock_fd);
-		lock_fd = -1;
-		return -1;
-	}
-
-	return 0;
+	close(lock_fd);
+	lock_fd = -1;
+	return -1;
+    }
+
+    /* Start timer.  If we cannot get the lock in the specified time we
+       get a signal.  */
+    alarm (TIMEOUT);
+
+    /* Try to get the lock.  */
+    memset (&fl, '\0', sizeof (struct flock));
+    fl.l_type = F_WRLCK;
+    fl.l_whence = SEEK_SET;
+    result = fcntl (lock_fd, F_SETLKW, &fl);
+
+    /* Clear alarm.  */
+    alarm (0);
+
+    /* Restore old set of handled signals.  We don't need to know
+       about the current one.*/
+    sigprocmask (SIG_SETMASK, &saved_set, NULL);
+
+    /* Restore old action handler for alarm.  We don't need to know
+       about the current one.  */
+    sigaction (SIGALRM, &saved_act, NULL);
+
+    if (result < 0) {
+	close(lock_fd);
+	lock_fd = -1;
+	return -1;
+    }
+
+    return 0;
 }
 
 
-int
-ulckpwdf ()
+int ulckpwdf (void)
 {
-	int result;
-	
-	if (lock_fd == -1) {
-		/* There is no lock set.  */
-		result = -1;
-	}
-	else {
-		result = close (lock_fd);
-		
-		/* Mark descriptor as unused.  */
-		lock_fd = -1;
-	}
-
-	return result;
+    int result;
+
+    if (lock_fd == -1) {
+	/* There is no lock set.  */
+	result = -1;
+    }
+    else {
+	result = close (lock_fd);
+
+	/* Mark descriptor as unused.  */
+	lock_fd = -1;
+    }
+
+    return result;
 }
 
 
-static void
-noop_handler (sig)
-	int sig;
+static void noop_handler (int sig)
 {
-	/* We simply return which makes the `fcntl' call return with an error.  */
+    /* We simply return which makes the `fcntl' call return with an error.  */
 }

+ 1 - 1
libc/pwd_grp/putpwent.c

@@ -20,7 +20,7 @@
 
 #include <stdio.h>
 #include <errno.h>
-#include <pwd.h>
+#include "config.h"
 
 int putpwent(const struct passwd *passwd, FILE * f)
 {

+ 51 - 52
libc/pwd_grp/putspent.c

@@ -17,63 +17,62 @@
    Boston, MA 02111-1307, USA.  */
 
 #include <stdio.h>
-#include <shadow.h>
+#include "config.h"
 
 #define _S(x)	x ? x : ""
 
 
 /* Write an entry to the given stream.
    This must know the format of the password file.  */
-int
-putspent (const struct spwd *p, FILE *stream)
+int putspent (const struct spwd *p, FILE *stream)
 {
-  int errors = 0;
-
-  if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0)
-    ++errors;
-
-  if ((p->sp_lstchg != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_lstchg) < 0)
-      || (p->sp_lstchg == (long int) -1
-	  && putc (':', stream) == EOF))
-    ++errors;
-
-  if ((p->sp_min != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_min) < 0)
-      || (p->sp_min == (long int) -1
-	  && putc (':', stream) == EOF))
-    ++errors;
-
-  if ((p->sp_max != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_max) < 0)
-      || (p->sp_max == (long int) -1
-	  && putc (':', stream) == EOF))
-    ++errors;
-
-  if ((p->sp_warn != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_warn) < 0)
-      || (p->sp_warn == (long int) -1
-	  && putc (':', stream) == EOF))
-    ++errors;
-
-  if ((p->sp_inact != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_inact) < 0)
-      || (p->sp_inact == (long int) -1
-	  && putc (':', stream) == EOF))
-    ++errors;
-
-  if ((p->sp_expire != (long int) -1
-       && fprintf (stream, "%ld:", p->sp_expire) < 0)
-      || (p->sp_expire == (long int) -1
-	  && putc (':', stream) == EOF))
-    ++errors;
-
-  if (p->sp_flag != ~0ul
-      && fprintf (stream, "%ld", p->sp_flag) < 0)
-    ++errors;
-
-  if (putc ('\n', stream) == EOF)
-    ++errors;
-
-  return errors ? -1 : 0;
+    int errors = 0;
+
+    if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0)
+	++errors;
+
+    if ((p->sp_lstchg != (long int) -1
+		&& fprintf (stream, "%ld:", p->sp_lstchg) < 0)
+	    || (p->sp_lstchg == (long int) -1
+		&& putc (':', stream) == EOF))
+	++errors;
+
+    if ((p->sp_min != (long int) -1
+		&& fprintf (stream, "%ld:", p->sp_min) < 0)
+	    || (p->sp_min == (long int) -1
+		&& putc (':', stream) == EOF))
+	++errors;
+
+    if ((p->sp_max != (long int) -1
+		&& fprintf (stream, "%ld:", p->sp_max) < 0)
+	    || (p->sp_max == (long int) -1
+		&& putc (':', stream) == EOF))
+	++errors;
+
+    if ((p->sp_warn != (long int) -1
+		&& fprintf (stream, "%ld:", p->sp_warn) < 0)
+	    || (p->sp_warn == (long int) -1
+		&& putc (':', stream) == EOF))
+	++errors;
+
+    if ((p->sp_inact != (long int) -1
+		&& fprintf (stream, "%ld:", p->sp_inact) < 0)
+	    || (p->sp_inact == (long int) -1
+		&& putc (':', stream) == EOF))
+	++errors;
+
+    if ((p->sp_expire != (long int) -1
+		&& fprintf (stream, "%ld:", p->sp_expire) < 0)
+	    || (p->sp_expire == (long int) -1
+		&& putc (':', stream) == EOF))
+	++errors;
+
+    if (p->sp_flag != ~0ul
+	    && fprintf (stream, "%ld", p->sp_flag) < 0)
+	++errors;
+
+    if (putc ('\n', stream) == EOF)
+	++errors;
+
+    return errors ? -1 : 0;
 }

+ 9 - 12
libc/pwd_grp/pwent.c

@@ -21,7 +21,6 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <errno.h>
-#include <pwd.h>
 #include <fcntl.h>
 #include <paths.h>
 #include "config.h"
@@ -32,26 +31,22 @@
  * link them all in together.
  */
 
-#define PWD_BUFFER_SIZE 256
-
 /* file descriptor for the password file currently open */
 static int pw_fd = -1;
-static char line_buff[PWD_BUFFER_SIZE];
-static struct passwd pwd;
 
 void setpwent(void)
 {
-	if (pw_fd != -1)
-		close(pw_fd);
+    if (pw_fd != -1)
+	close(pw_fd);
 
-	pw_fd = open(_PATH_PASSWD, O_RDONLY);
+    pw_fd = open(_PATH_PASSWD, O_RDONLY);
 }
 
 void endpwent(void)
 {
-	if (pw_fd != -1)
-		close(pw_fd);
-	pw_fd = -1;
+    if (pw_fd != -1)
+	close(pw_fd);
+    pw_fd = -1;
 }
 
 int getpwent_r (struct passwd *password, char *buff, 
@@ -65,7 +60,9 @@ int getpwent_r (struct passwd *password, char *buff,
 
 struct passwd *getpwent(void)
 {
-    if (getpwent_r(&pwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) {
+    static char line_buff[PWD_BUFFER_SIZE];
+    static struct passwd pwd;
+    if (getpwent_r(&pwd, line_buff, sizeof(line_buff), NULL) != -1) {
 	return &pwd;
     }
     return NULL;

+ 8 - 10
libc/pwd_grp/sgetspent.c

@@ -19,23 +19,21 @@
 
 #include <errno.h>
 #include <stdio.h>
-#include <shadow.h>
-
-#define PWD_BUFFER_SIZE 256
+#include "config.h"
 
 int sgetspent_r (const char *string, struct spwd *spwd,
 	char *buff, size_t buflen, struct spwd **crap)
 {
-	return(__sgetspent_r(string, spwd, buff, buflen));
+    return(__sgetspent_r(string, spwd, buff, buflen));
 }
 
 struct spwd *sgetspent(const char *string)
 {
-	static char line_buff[PWD_BUFFER_SIZE];
-	static struct spwd spwd;
+    static char line_buff[PWD_BUFFER_SIZE];
+    static struct spwd spwd;
 
-	if (sgetspent_r(string, &spwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) {
-		return &spwd;
-	}
-	return NULL;
+    if (sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), NULL) != -1) {
+	return &spwd;
+    }
+    return NULL;
 }

+ 17 - 19
libc/pwd_grp/spent.c

@@ -20,8 +20,8 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <errno.h>
-#include <shadow.h>
 #include <fcntl.h>
+#include "config.h"
 
 /*
  * setspent(), endspent(), and getspent() are included in the same object
@@ -29,43 +29,41 @@
  * link them all in together.
  */
 
-#define PWD_BUFFER_SIZE 256
-
 /* file descriptor for the password file currently open */
 static int spwd_fd = -1;
 
 void setspent(void)
 {
-	if (spwd_fd != -1)
-		close(spwd_fd);
+    if (spwd_fd != -1)
+	close(spwd_fd);
 
-	spwd_fd = open(_PATH_SHADOW, O_RDONLY);
+    spwd_fd = open(_PATH_SHADOW, O_RDONLY);
 }
 
 void endspent(void)
 {
-	if (spwd_fd != -1)
-		close(spwd_fd);
-	spwd_fd = -1;
+    if (spwd_fd != -1)
+	close(spwd_fd);
+    spwd_fd = -1;
 }
 
 int getspent_r (struct spwd *spwd, char *buff, 
 	size_t buflen, struct spwd **crap)
 {
-	if (spwd_fd != -1 && __getspent_r(spwd, buff, buflen, spwd_fd) != -1) {
-		return 0;
-	}
-	return -1;
+    if (spwd_fd != -1 && __getspent_r(spwd, buff, buflen, spwd_fd) != -1) {
+	return 0;
+    }
+    return -1;
 }
 
 struct spwd *getspent(void)
 {
-	static char line_buff[PWD_BUFFER_SIZE];
-	static struct spwd spwd;
+    static char line_buff[PWD_BUFFER_SIZE];
+    static struct spwd spwd;
 
-	if (getspent_r(&spwd, line_buff, PWD_BUFFER_SIZE, NULL) != -1) {
-		return &spwd;
-	}
-	return NULL;
+    if (getspent_r(&spwd, line_buff, sizeof(line_buff), NULL) != -1) {
+	return &spwd;
+    }
+    return NULL;
 }