Date: Mon, 23 May 2016 05:11:32 +0000 (UTC) From: Garrett Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r300454 - stable/10/lib/libc/tests/nss Message-ID: <201605230511.u4N5BW56082177@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Mon May 23 05:11:31 2016 New Revision: 300454 URL: https://svnweb.freebsd.org/changeset/base/300454 Log: 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 "#" Modified: stable/10/lib/libc/tests/nss/testutil.h Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/tests/nss/testutil.h ============================================================================== --- stable/10/lib/libc/tests/nss/testutil.h Mon May 23 05:11:08 2016 (r300453) +++ stable/10/lib/libc/tests/nss/testutil.h Mon May 23 05:11:31 2016 (r300454) @@ -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 *fnam 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: \
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605230511.u4N5BW56082177>