diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-10-10 07:34:27 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-10-10 07:34:27 +0000 |
commit | 56104838733c81ba410ac41f767ac72267049489 (patch) | |
tree | 54057d78cdae893235b86787a735629396d857a5 /libc/pwd_grp/__getpwent_r.c | |
parent | 61011662018fa98c4610c1ae826e417678cd5c80 (diff) |
Implement getgrgid_r and getgrnam_r. Rework group handling code to be fully
reentrant, since there was still a shared static value. indent stuff,
Diffstat (limited to 'libc/pwd_grp/__getpwent_r.c')
-rw-r--r-- | libc/pwd_grp/__getpwent_r.c | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/libc/pwd_grp/__getpwent_r.c b/libc/pwd_grp/__getpwent_r.c index 5cfdd89ba..6e6de4038 100644 --- a/libc/pwd_grp/__getpwent_r.c +++ b/libc/pwd_grp/__getpwent_r.c @@ -1,7 +1,8 @@ +/* vi: set sw=4 ts=4: */ /* * __getpwent_r.c - This file is part of the libc-8086/pwd package for ELKS, * Copyright (C) 1995, 1996 Nat Friedman <ndf@linux.mit.edu>. - * Copyright (C) 2001 Erik Andersen <andersee@debian.org> + * Copyright (C) 2001-2003 Erik Andersen <andersee@debian.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -18,6 +19,7 @@ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * March 7, 2001 -- Reworked to be reentrant by Erik Andersen + * Oct 9, 2003 -- Reworked again by Erik Andersen to be fully reentrant */ #include <stdlib.h> @@ -36,38 +38,35 @@ int __getpwent_r(struct passwd * passwd, char * line_buff, size_t buflen, int pwd_fd) { - char *field_begin; - char *endptr; + char *endptr, *field_begin; char *gid_ptr=NULL; char *uid_ptr=NULL; - int line_len; - int i; + int i, line_len; - if (buflen<PWD_BUFFER_SIZE) + if (buflen<PWD_BUFFER_SIZE) { return ERANGE; + } /* We use the restart label to handle malformatted lines */ restart: - /* Read the passwd line into the static buffer using a minimum of - syscalls. */ - if ((line_len = read(pwd_fd, line_buff, buflen)) <= 0) + /* Read the passwd line into the buffer for processing */ + if ((line_len = read(pwd_fd, line_buff, buflen)) <= 0) { return EIO; + } field_begin = strchr(line_buff, '\n'); if (field_begin != NULL) - lseek(pwd_fd, (long) (1 + field_begin - (line_buff + line_len)), - SEEK_CUR); - else { /* The line is too long - skip it. :-\ */ - + lseek(pwd_fd, (long) (1 + field_begin - (line_buff + line_len)), SEEK_CUR); + else { + /* The line is too long - skip it. :-\ */ do { - if ((line_len = read(pwd_fd, line_buff, buflen)) <= 0) + if ((line_len = read(pwd_fd, line_buff, buflen)) <= 0) { return EIO; + } } while (!(field_begin = strchr(line_buff, '\n'))); - lseek(pwd_fd, (long) (field_begin - line_buff) - line_len + 1, - SEEK_CUR); + lseek(pwd_fd, (long) (field_begin - line_buff) - line_len + 1, SEEK_CUR); goto restart; } - if (*line_buff == '#' || *line_buff == ' ' || *line_buff == '\n' || - *line_buff == '\t') + if (*line_buff == '#' || *line_buff == ' ' || *line_buff == '\n' || *line_buff == '\t') goto restart; *field_begin = '\0'; @@ -75,27 +74,27 @@ restart: field_begin = line_buff; for (i = 0; i < 7; i++) { switch (i) { - case 0: - passwd->pw_name = field_begin; - break; - case 1: - passwd->pw_passwd = field_begin; - break; - case 2: - uid_ptr = field_begin; - break; - case 3: - gid_ptr = field_begin; - break; - case 4: - passwd->pw_gecos = field_begin; - break; - case 5: - passwd->pw_dir = field_begin; - break; - case 6: - passwd->pw_shell = field_begin; - break; + case 0: + passwd->pw_name = field_begin; + break; + case 1: + passwd->pw_passwd = field_begin; + break; + case 2: + uid_ptr = field_begin; + break; + case 3: + gid_ptr = field_begin; + break; + case 4: + passwd->pw_gecos = field_begin; + break; + case 5: + passwd->pw_dir = field_begin; + break; + case 6: + passwd->pw_shell = field_begin; + break; } if (i < 6) { field_begin = strchr(field_begin, ':'); |