summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/__getpwent_r.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-06-27 10:19:29 +0000
committerEric Andersen <andersen@codepoet.org>2003-06-27 10:19:29 +0000
commit2e55dec21f3310e6868689fc1f4c4074ea3a35bb (patch)
tree77479d130301a86ca26009cf712dc0ebe3ddd340 /libc/pwd_grp/__getpwent_r.c
parentea3abe244d9ad2ec59d00b29152fc457571d2d37 (diff)
Fixup errno handling
-Erik
Diffstat (limited to 'libc/pwd_grp/__getpwent_r.c')
-rw-r--r--libc/pwd_grp/__getpwent_r.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/libc/pwd_grp/__getpwent_r.c b/libc/pwd_grp/__getpwent_r.c
index db49ae255..5cfdd89ba 100644
--- a/libc/pwd_grp/__getpwent_r.c
+++ b/libc/pwd_grp/__getpwent_r.c
@@ -24,6 +24,7 @@
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
+#include <errno.h>
#include "config.h"
@@ -42,12 +43,15 @@ int __getpwent_r(struct passwd * passwd, char * line_buff, size_t buflen, int pw
int line_len;
int i;
+ 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 minimal of
+restart:
+ /* Read the passwd line into the static buffer using a minimum of
syscalls. */
if ((line_len = read(pwd_fd, line_buff, buflen)) <= 0)
- return -1;
+ return EIO;
field_begin = strchr(line_buff, '\n');
if (field_begin != NULL)
lseek(pwd_fd, (long) (1 + field_begin - (line_buff + line_len)),
@@ -56,7 +60,7 @@ int __getpwent_r(struct passwd * passwd, char * line_buff, size_t buflen, int pw
do {
if ((line_len = read(pwd_fd, line_buff, buflen)) <= 0)
- return -1;
+ return EIO;
} while (!(field_begin = strchr(line_buff, '\n')));
lseek(pwd_fd, (long) (field_begin - line_buff) - line_len + 1,
SEEK_CUR);