diff options
| author | Garance A Drosehn <gad@FreeBSD.org> | 2000-12-02 00:07:56 +0000 |
|---|---|---|
| committer | Garance A Drosehn <gad@FreeBSD.org> | 2000-12-02 00:07:56 +0000 |
| commit | bbe8edb0ac4fc0e8b89dfe6000e2ced76bcfbef6 (patch) | |
| tree | a46ff3882428e1aecc405c5e657e449523c3c261 /lib/libc | |
| parent | 1c32c37c06aa427bff3f780b962f7e599d29cde4 (diff) | |
Notes
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/gen/getcap.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index b3261aeb54ae0..edb828b0fad08 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -647,7 +647,7 @@ cgetnext(bp, db_array) char **db_array; { size_t len; - int status, i, done; + int done, hadreaderr, i, savederrno, status; char *cp, *line, *rp, *np, buf[BSIZE], nbuf[BSIZE]; u_int dummy; @@ -665,9 +665,14 @@ cgetnext(bp, db_array) } else { line = fgetln(pfp, &len); if (line == NULL && pfp) { - (void)fclose(pfp); - if (ferror(pfp)) { - (void)cgetclose(); + hadreaderr = ferror(pfp); + if (hadreaderr) + savederrno = errno; + fclose(pfp); + pfp = NULL; + if (hadreaderr) { + cgetclose(); + errno = savederrno; return (-1); } else { if (*++dbp == NULL) { @@ -724,9 +729,18 @@ cgetnext(bp, db_array) } else { /* name field extends beyond the line */ line = fgetln(pfp, &len); if (line == NULL && pfp) { - (void)fclose(pfp); - if (ferror(pfp)) { - (void)cgetclose(); + /* Name extends beyond the EOF! */ + hadreaderr = ferror(pfp); + if (hadreaderr) + savederrno = errno; + fclose(pfp); + pfp = NULL; + if (hadreaderr) { + cgetclose(); + errno = savederrno; + return (-1); + } else { + cgetclose(); return (-1); } } else |
