summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2016-05-23 05:11:31 +0000
committerngie <ngie@FreeBSD.org>2016-05-23 05:11:31 +0000
commit60eb189f712d30131dea862031451ef39f49124f (patch)
treee0548f9b8be15c753c4e3d6e80d54e6a2d854752 /lib
parentb92c1d64bb76696e6668913a140f5ec64a0e24d8 (diff)
downloadFreeBSD-src-60eb189f712d30131dea862031451ef39f49124f.zip
FreeBSD-src-60eb189f712d30131dea862031451ef39f49124f.tar.gz
MFC r299654:
Read the contents of the snapshot files properly - Use fgetln instead of fgets; localize complexity related to fgetln(3) inside the loop. - Skip over blank lines. - Skip over lines (properly) that start with a "#"
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/tests/nss/testutil.h33
1 files changed, 15 insertions, 18 deletions
diff --git a/lib/libc/tests/nss/testutil.h b/lib/libc/tests/nss/testutil.h
index 39c4f41..ff9e8f0 100644
--- a/lib/libc/tests/nss/testutil.h
+++ b/lib/libc/tests/nss/testutil.h
@@ -252,9 +252,7 @@ int \
__##ent##_snapshot_read(char const *fname, struct ent##_test_data *td, \
int (*read_func)(struct ent *, char *)) \
{ \
- char buffer[1024]; \
struct ent data; \
- char *s; \
FILE *fi; \
size_t len; \
int rv; \
@@ -267,23 +265,22 @@ __##ent##_snapshot_read(char const *fname, struct ent##_test_data *td, \
return (-1); \
\
rv = 0; \
- memset(buffer, 0, sizeof(buffer)); \
while (!feof(fi)) { \
- s = fgets(buffer, sizeof(buffer), fi); \
- if (s != NULL && s[0] != '#') { \
- len = strlen(s); \
- if (len == 0) \
- continue; \
- if (buffer[len - 1] == '\n') \
- buffer[len -1] = '\0'; \
- \
- rv = read_func(&data, s); \
- if (rv == 0) { \
- __##ent##_test_data_append(td, &data); \
- td->free_func(&data); \
- } else \
- goto fin; \
- } \
+ char *buf = fgetln(fi, &len); \
+ if (buf == NULL || len <= 1) \
+ continue; \
+ if (buf[len - 1] == '\n') \
+ buf[len - 1] = '\0'; \
+ else \
+ buf[len] = '\0'; \
+ if (buf[0] == '#') \
+ continue; \
+ rv = read_func(&data, buf); \
+ if (rv == 0) { \
+ __##ent##_test_data_append(td, &data); \
+ td->free_func(&data); \
+ } else \
+ goto fin; \
} \
\
fin: \
OpenPOWER on IntegriCloud