aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/sys/getdirentries.218
-rw-r--r--lib/libc/tests/nss/Makefile15
-rw-r--r--lib/libc/tests/nss/getaddrinfo_test.c53
-rw-r--r--lib/libc/tests/nss/getgr_test.c12
-rw-r--r--lib/libc/tests/nss/gethostby_test.c127
-rw-r--r--lib/libc/tests/nss/getproto_test.c14
-rw-r--r--lib/libc/tests/nss/getpw_test.c12
-rw-r--r--lib/libc/tests/nss/getrpc_test.c16
-rw-r--r--lib/libc/tests/nss/getserv_test.c14
-rw-r--r--lib/libc/tests/nss/getusershell_test.c7
10 files changed, 149 insertions, 139 deletions
diff --git a/lib/libc/sys/getdirentries.2 b/lib/libc/sys/getdirentries.2
index d3f2129d400f..74fa6a9b889e 100644
--- a/lib/libc/sys/getdirentries.2
+++ b/lib/libc/sys/getdirentries.2
@@ -28,7 +28,7 @@
.\" @(#)getdirentries.2 8.2 (Berkeley) 5/3/95
.\" $FreeBSD$
.\"
-.Dd May 3, 1995
+.Dd May 28, 2017
.Dt GETDIRENTRIES 2
.Os
.Sh NAME
@@ -71,10 +71,11 @@ The data in the buffer is a series of
.Vt dirent
structures each containing the following entries:
.Bd -literal -offset indent
-uint32_t d_fileno;
-uint16_t d_reclen;
-uint8_t d_type;
-uint8_t d_namlen;
+ino_t d_fileno;
+off_t d_off;
+uint16_t d_reclen;
+uint8_t d_type;
+uint16_t d_namlen;
char d_name[MAXNAMLEN + 1]; /* see below */
.Ed
.Pp
@@ -124,7 +125,10 @@ or
A value of zero is returned when
the end of the directory has been reached.
.Pp
-The
+If the
+.Fa basep
+pointer value is non-NULL ,
+the
.Fn getdirentries
system call writes the position of the block read into the location pointed to by
.Fa basep .
@@ -157,7 +161,7 @@ is not a valid file descriptor open for reading.
.It Bq Er EFAULT
Either
.Fa buf
-or
+or non-NULL
.Fa basep
point outside the allocated address space.
.It Bq Er EINVAL
diff --git a/lib/libc/tests/nss/Makefile b/lib/libc/tests/nss/Makefile
index 6075b3157953..c2f6e0940c07 100644
--- a/lib/libc/tests/nss/Makefile
+++ b/lib/libc/tests/nss/Makefile
@@ -1,18 +1,13 @@
# $FreeBSD$
+.PATH: ${.CURDIR:H}/resolv
+
PACKAGE= tests
TESTSDIR= ${TESTSBASE}/lib/libc/nss
BINDIR= ${TESTSDIR}
-.PATH: ${.CURDIR:H}/resolv
-
-${PACKAGE}FILES+= mach
-
-WARNS?= 1
-CFLAGS+= -I${SRCTOP}/tests
-
ATF_TESTS_C+= getaddrinfo_test
ATF_TESTS_C+= getgr_test
ATF_TESTS_C+= gethostby_test
@@ -23,4 +18,10 @@ ATF_TESTS_C+= getrpc_test
ATF_TESTS_C+= getserv_test
ATF_TESTS_C+= getusershell_test
+${PACKAGE}FILES+= mach
+
+WARNS?= 3
+
+CFLAGS+= -I${SRCTOP}/tests
+
.include <bsd.test.mk>
diff --git a/lib/libc/tests/nss/getaddrinfo_test.c b/lib/libc/tests/nss/getaddrinfo_test.c
index 0c9704fe366d..aeac04110510 100644
--- a/lib/libc/tests/nss/getaddrinfo_test.c
+++ b/lib/libc/tests/nss/getaddrinfo_test.c
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/types.h>
+#include <sys/param.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
@@ -125,7 +125,8 @@ compare_addrinfo_(struct addrinfo *ai1, struct addrinfo *ai2)
}
static int
-compare_addrinfo(struct addrinfo *ai1, struct addrinfo *ai2, void *mdata)
+compare_addrinfo(struct addrinfo *ai1, struct addrinfo *ai2,
+ void *mdata __unused)
{
int rv;
@@ -144,7 +145,7 @@ compare_addrinfo(struct addrinfo *ai1, struct addrinfo *ai2, void *mdata)
return (rv);
}
-void
+static void
free_addrinfo(struct addrinfo *ai)
{
if (ai == NULL)
@@ -164,30 +165,30 @@ sdump_addrinfo(struct addrinfo *ai, char *buffer, size_t buflen)
ai->ai_flags, ai->ai_family, ai->ai_socktype, ai->ai_protocol,
ai->ai_addrlen);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
written = snprintf(buffer, buflen, "%s ",
ai->ai_canonname == NULL ? "(null)" : ai->ai_canonname);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
if (ai->ai_addr == NULL) {
written = snprintf(buffer, buflen, "(null)");
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
} else {
- for (i = 0; i < ai->ai_addrlen; i++) {
+ for (i = 0; i < (int)ai->ai_addrlen; i++) {
written = snprintf(buffer, buflen,
- i + 1 != ai->ai_addrlen ? "%d." : "%d",
+ i + 1 != (int)ai->ai_addrlen ? "%d." : "%d",
((unsigned char *)ai->ai_addr)[i]);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
@@ -199,7 +200,7 @@ sdump_addrinfo(struct addrinfo *ai, char *buffer, size_t buflen)
if (ai->ai_next != NULL) {
written = snprintf(buffer, buflen, ":");
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
@@ -309,12 +310,11 @@ addrinfo_read_snapshot_func(struct addrinfo *ai, char *line)
{
struct addrinfo *ai2;
char *s, *ps;
- int i, rv;
+ int rv;
printf("1 line read from snapshot:\n%s\n", line);
rv = 0;
- i = 0;
ps = line;
s = strsep(&ps, ":");
@@ -344,7 +344,7 @@ addrinfo_read_snapshot_func(struct addrinfo *ai, char *line)
}
static int
-addrinfo_test_correctness(struct addrinfo *ai, void *mdata)
+addrinfo_test_correctness(struct addrinfo *ai, void *mdata __unused)
{
printf("testing correctness with the following data:\n");
@@ -409,12 +409,20 @@ addrinfo_read_hostlist_func(struct addrinfo *ai, char *line)
return (0);
}
-void
-run_tests(char *hostlist_file, char *snapshot_file, int ai_family)
+static void
+run_tests(char *hostlist_file, const char *snapshot_file, int ai_family)
{
struct addrinfo_test_data td, td_snap;
+ char *snapshot_file_copy;
int rv;
+ if (snapshot_file == NULL)
+ snapshot_file_copy = NULL;
+ else {
+ snapshot_file_copy = strdup(snapshot_file);
+ ATF_REQUIRE(snapshot_file_copy != NULL);
+ }
+
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = ai_family;
hints.ai_flags = AI_CANONNAME;
@@ -477,24 +485,17 @@ fin:
TEST_DATA_DESTROY(addrinfo, &td_snap);
TEST_DATA_DESTROY(addrinfo, &td);
- free(hostlist_file);
- free(snapshot_file);
+ free(snapshot_file_copy);
}
#define HOSTLIST_FILE "mach"
#define RUN_TESTS(tc, snapshot_file, ai_family) do { \
char *_hostlist_file; \
- char *_snapshot_file; \
ATF_REQUIRE(0 < asprintf(&_hostlist_file, "%s/%s", \
atf_tc_get_config_var(tc, "srcdir"), HOSTLIST_FILE)); \
- if (snapshot_file == NULL) \
- _snapshot_file = NULL; \
- else { \
- _snapshot_file = strdup(snapshot_file); \
- ATF_REQUIRE(_snapshot_file != NULL); \
- } \
- run_tests(_hostlist_file, _snapshot_file, ai_family); \
-} while(0)
+ run_tests(_hostlist_file, snapshot_file, ai_family); \
+ free(_hostlist_file); \
+} while (0)
ATF_TC_WITHOUT_HEAD(pf_unspec);
ATF_TC_BODY(pf_unspec, tc)
diff --git a/lib/libc/tests/nss/getgr_test.c b/lib/libc/tests/nss/getgr_test.c
index 5730a62b5000..43e651872f96 100644
--- a/lib/libc/tests/nss/getgr_test.c
+++ b/lib/libc/tests/nss/getgr_test.c
@@ -49,8 +49,6 @@ enum test_methods {
TEST_BUILD_SNAPSHOT = 16,
};
-static enum test_methods method = TEST_BUILD_SNAPSHOT;
-
DECLARE_TEST_DATA(group)
DECLARE_TEST_FILE_SNAPSHOT(group)
DECLARE_1PASS_TEST(group)
@@ -104,7 +102,7 @@ clone_group(struct group *dest, struct group const *src)
for (cp = src->gr_mem; *cp; ++cp)
++members_num;
- dest->gr_mem = calloc(1, (members_num + 1) * sizeof(char *));
+ dest->gr_mem = calloc(members_num + 1, sizeof(char *));
ATF_REQUIRE(dest->gr_mem != NULL);
for (cp = src->gr_mem; *cp; ++cp) {
@@ -179,7 +177,7 @@ sdump_group(struct group *grp, char *buffer, size_t buflen)
written = snprintf(buffer, buflen, "%s:%s:%d:",
grp->gr_name, grp->gr_passwd, grp->gr_gid);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
@@ -189,7 +187,7 @@ sdump_group(struct group *grp, char *buffer, size_t buflen)
written = snprintf(buffer, buflen, "%s%s",
cp == grp->gr_mem ? "" : ",", *cp);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
@@ -309,7 +307,7 @@ group_fill_test_data(struct group_test_data *td)
}
static int
-group_test_correctness(struct group *grp, void *mdata)
+group_test_correctness(struct group *grp, void *mdata __unused)
{
printf("testing correctness with the following data:\n");
dump_group(grp);
@@ -387,7 +385,7 @@ group_test_getgrgid(struct group *grp_model, void *mdata)
}
static int
-group_test_getgrent(struct group *grp, void *mdata)
+group_test_getgrent(struct group *grp, void *mdata __unused)
{
/* Only correctness can be checked when doing 1-pass test for
* getgrent(). */
diff --git a/lib/libc/tests/nss/gethostby_test.c b/lib/libc/tests/nss/gethostby_test.c
index 618f7470920b..39dbb9d9d55a 100644
--- a/lib/libc/tests/nss/gethostby_test.c
+++ b/lib/libc/tests/nss/gethostby_test.c
@@ -87,8 +87,6 @@ static int hostent_test_gethostbyaddr(struct hostent *, void *);
static int hostent_test_getaddrinfo_eq(struct hostent *, void *);
static int hostent_test_getnameinfo_eq(struct hostent *, void *);
-static void usage(void) __attribute__((__noreturn__));
-
IMPLEMENT_TEST_DATA(hostent)
IMPLEMENT_TEST_FILE_SNAPSHOT(hostent)
IMPLEMENT_1PASS_TEST(hostent)
@@ -163,8 +161,7 @@ clone_hostent(struct hostent *dest, struct hostent const *src)
for (cp = src->h_aliases; *cp; ++cp)
++aliases_num;
- dest->h_aliases = calloc(1, (aliases_num + 1) *
- sizeof(char *));
+ dest->h_aliases = calloc(aliases_num + 1, sizeof(char *));
ATF_REQUIRE(dest->h_aliases != NULL);
for (cp = src->h_aliases; *cp; ++cp) {
@@ -178,7 +175,7 @@ clone_hostent(struct hostent *dest, struct hostent const *src)
for (cp = src->h_addr_list; *cp; ++cp)
++addrs_num;
- dest->h_addr_list = calloc(1, (addrs_num + 1) * sizeof(char *));
+ dest->h_addr_list = calloc(addrs_num + 1, sizeof(char *));
ATF_REQUIRE(dest->h_addr_list != NULL);
for (cp = src->h_addr_list; *cp; ++cp) {
@@ -413,7 +410,7 @@ sdump_hostent(struct hostent *ht, char *buffer, size_t buflen)
written = snprintf(buffer, buflen, "%s %d %d",
ht->h_name, ht->h_addrtype, ht->h_length);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
@@ -422,7 +419,7 @@ sdump_hostent(struct hostent *ht, char *buffer, size_t buflen)
for (cp = ht->h_aliases; *cp; ++cp) {
written = snprintf(buffer, buflen, " %s",*cp);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
@@ -432,59 +429,61 @@ sdump_hostent(struct hostent *ht, char *buffer, size_t buflen)
} else {
written = snprintf(buffer, buflen, " noaliases");
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
}
} else {
written = snprintf(buffer, buflen, " (null)");
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
}
written = snprintf(buffer, buflen, " : ");
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
if (ht->h_addr_list != NULL) {
if (*(ht->h_addr_list) != NULL) {
for (cp = ht->h_addr_list; *cp; ++cp) {
- for (i = 0; i < ht->h_length; ++i ) {
- written = snprintf(buffer, buflen,
- i + 1 != ht->h_length ? "%d." : "%d",
- (unsigned char)(*cp)[i]);
- buffer += written;
- if (written > buflen)
- return;
- buflen -= written;
-
- if (buflen == 0)
- return;
- }
+ for (i = 0; i < (size_t)ht->h_length; ++i) {
+ written = snprintf(buffer, buflen,
+ i + 1 != (size_t)ht->h_length ?
+ "%d." : "%d",
+ (unsigned char)(*cp)[i]);
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+
+ if (buflen == 0)
+ return;
+ }
- if (*(cp + 1) ) {
- written = snprintf(buffer, buflen, " ");
- buffer += written;
- if (written > buflen)
- return;
- buflen -= written;
- }
+ if (*(cp + 1)) {
+ written = snprintf(buffer, buflen,
+ " ");
+ buffer += written;
+ if (written > (int)buflen)
+ return;
+ buflen -= written;
+ }
}
} else {
written = snprintf(buffer, buflen, " noaddrs");
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
}
} else {
written = snprintf(buffer, buflen, " (null)");
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
}
@@ -676,7 +675,7 @@ dump_hostent(struct hostent *result)
}
static int
-hostent_test_correctness(struct hostent *ht, void *mdata)
+hostent_test_correctness(struct hostent *ht, void *mdata __unused)
{
#ifdef DEBUG
@@ -759,7 +758,7 @@ hostent_test_gethostbyaddr(struct hostent *he, void *mdata)
}
static int
-hostent_test_getaddrinfo_eq(struct hostent *he, void *mdata)
+hostent_test_getaddrinfo_eq(struct hostent *he, void *mdata __unused)
{
struct addrinfo *ai, hints;
int rv;
@@ -777,28 +776,30 @@ hostent_test_getaddrinfo_eq(struct hostent *he, void *mdata)
rv = getaddrinfo(he->h_name, NULL, &hints, &ai);
if (rv == 0) {
printf("not ok - shouldn't have been resolved\n");
- return (-1);
- }
+ rv = -1;
+ } else
+ rv = 0;
} else {
rv = getaddrinfo(he->h_name, NULL, &hints, &ai);
if (rv != 0) {
printf("not ok - should have been resolved\n");
- return (-1);
+ rv = -1;
+ goto done;
}
-
rv = is_hostent_equal(he, ai);
if (rv != 0) {
printf("not ok - addrinfo and hostent are not equal\n");
- return (-1);
+ rv = -1;
}
-
}
-
- return (0);
+done:
+ if (ai != NULL)
+ freeaddrinfo(ai);
+ return (rv);
}
static int
-hostent_test_getnameinfo_eq(struct hostent *he, void *mdata)
+hostent_test_getnameinfo_eq(struct hostent *he, void *mdata __unused)
{
char **cp;
char buffer[NI_MAXHOST];
@@ -885,7 +886,7 @@ hostent_test_getnameinfo_eq(struct hostent *he, void *mdata)
* An address might reverse resolve to hostname alias or the
* official hostname, e.g. moon.vub.ac.be.
*/
- bool found_a_match;
+ bool found_a_match = false;
if (strcmp(result->h_name, buffer) == 0) {
found_a_match = true;
@@ -921,15 +922,24 @@ hostent_test_getnameinfo_eq(struct hostent *he, void *mdata)
return (0);
}
-int
-run_tests(const char *hostlist_file, const char *snapshot_file, int af_type,
+static int
+run_tests(const char *hostlist_file, const char *snapshot_file, int _af_type,
enum test_methods method, bool use_ipv6_mapping)
{
+ char *snapshot_file_copy;
struct hostent_test_data td, td_addr, td_snap;
res_state statp;
int rv = -2;
- switch (af_type) {
+ if (snapshot_file == NULL)
+ snapshot_file_copy = NULL;
+ else {
+ snapshot_file_copy = strdup(snapshot_file);
+ ATF_REQUIRE(snapshot_file_copy != NULL);
+ }
+ snapshot_file = snapshot_file_copy;
+
+ switch (_af_type) {
case AF_INET:
ATF_REQUIRE_FEATURE("inet");
ATF_REQUIRE(!use_ipv6_mapping);
@@ -938,7 +948,7 @@ run_tests(const char *hostlist_file, const char *snapshot_file, int af_type,
ATF_REQUIRE_FEATURE("inet6");
break;
default:
- atf_tc_fail("unhandled address family: %d", af_type);
+ atf_tc_fail("unhandled address family: %d", _af_type);
break;
}
@@ -947,8 +957,8 @@ run_tests(const char *hostlist_file, const char *snapshot_file, int af_type,
if (statp == NULL || ((statp->options & RES_INIT) == 0 &&
res_ninit(statp) == -1)) {
printf("error: can't init res_state\n");
-
- return (-1);
+ rv = -1;
+ goto fin2;
}
if (use_ipv6_mapping)
@@ -1052,6 +1062,9 @@ fin:
TEST_DATA_DESTROY(hostent, &td_addr);
TEST_DATA_DESTROY(hostent, &td);
+fin2:
+ free(snapshot_file_copy);
+
return (rv);
}
@@ -1060,30 +1073,24 @@ fin:
#define _RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
do { \
char *_hostlist_file; \
- char *_snapshot_file; \
ATF_REQUIRE(0 < asprintf(&_hostlist_file, "%s/%s", \
atf_tc_get_config_var(tc, "srcdir"), HOSTLIST_FILE)); \
- if (snapshot_file == NULL) \
- _snapshot_file = NULL; \
- else { \
- _snapshot_file = strdup(snapshot_file); \
- ATF_REQUIRE(_snapshot_file != NULL); \
- } \
- ATF_REQUIRE(run_tests(_hostlist_file, _snapshot_file, af_type, \
+ ATF_REQUIRE(run_tests(_hostlist_file, snapshot_file, af_type, \
method, use_ipv6_mapping) == 0); \
-} while(0)
+ free(_hostlist_file); \
+} while (0)
#define RUN_HOST_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
do { \
use_ipnode_functions = false; \
_RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping); \
-} while(0)
+} while (0)
#define RUN_IPNODE_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping) \
do { \
use_ipnode_functions = true; \
_RUN_TESTS(tc, snapshot_file, af_type, method, use_ipv6_mapping); \
-} while(0)
+} while (0)
ATF_TC_WITHOUT_HEAD(gethostbyaddr_ipv4);
ATF_TC_BODY(gethostbyaddr_ipv4, tc)
diff --git a/lib/libc/tests/nss/getproto_test.c b/lib/libc/tests/nss/getproto_test.c
index 5ae855542f9e..5e2bec50b20b 100644
--- a/lib/libc/tests/nss/getproto_test.c
+++ b/lib/libc/tests/nss/getproto_test.c
@@ -99,7 +99,7 @@ clone_protoent(struct protoent *dest, struct protoent const *src)
for (cp = src->p_aliases; *cp; ++cp)
++aliases_num;
- dest->p_aliases = calloc(1, (aliases_num+1) * sizeof(char *));
+ dest->p_aliases = calloc(aliases_num + 1, sizeof(char *));
assert(dest->p_aliases != NULL);
for (cp = src->p_aliases; *cp; ++cp) {
@@ -172,16 +172,16 @@ sdump_protoent(struct protoent *pe, char *buffer, size_t buflen)
written = snprintf(buffer, buflen, "%s %d",
pe->p_name, pe->p_proto);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
if (pe->p_aliases != NULL) {
if (*(pe->p_aliases) != '\0') {
for (cp = pe->p_aliases; *cp; ++cp) {
- written = snprintf(buffer, buflen, " %s",*cp);
+ written = snprintf(buffer, buflen, " %s", *cp);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
@@ -288,7 +288,7 @@ protoent_fill_test_data(struct protoent_test_data *td)
}
static int
-protoent_test_correctness(struct protoent *pe, void *mdata)
+protoent_test_correctness(struct protoent *pe, void *mdata __unused)
{
printf("testing correctness with the following data:\n");
dump_protoent(pe);
@@ -388,14 +388,14 @@ protoent_test_getprotobynumber(struct protoent *pe_model, void *mdata)
}
static int
-protoent_test_getprotoent(struct protoent *pe, void *mdata)
+protoent_test_getprotoent(struct protoent *pe, void *mdata __unused)
{
/* Only correctness can be checked when doing 1-pass test for
* getprotoent(). */
return (protoent_test_correctness(pe, NULL));
}
-int
+static int
run_tests(const char *snapshot_file, enum test_methods method)
{
struct protoent_test_data td, td_snap, td_2pass;
diff --git a/lib/libc/tests/nss/getpw_test.c b/lib/libc/tests/nss/getpw_test.c
index 98f890ff7313..c7ad2e5a4889 100644
--- a/lib/libc/tests/nss/getpw_test.c
+++ b/lib/libc/tests/nss/getpw_test.c
@@ -47,8 +47,6 @@ enum test_methods {
TEST_BUILD_SNAPSHOT
};
-static enum test_methods method = TEST_BUILD_SNAPSHOT;
-
DECLARE_TEST_DATA(passwd)
DECLARE_TEST_FILE_SNAPSHOT(passwd)
DECLARE_1PASS_TEST(passwd)
@@ -59,7 +57,9 @@ static int compare_passwd(struct passwd *, struct passwd *, void *);
static void free_passwd(struct passwd *);
static void sdump_passwd(struct passwd *, char *, size_t);
+#ifdef DEBUG
static void dump_passwd(struct passwd *);
+#endif
static int passwd_read_snapshot_func(struct passwd *, char *);
@@ -97,7 +97,7 @@ clone_passwd(struct passwd *dest, struct passwd const *src)
}
static int
-compare_passwd(struct passwd *pwd1, struct passwd *pwd2, void *mdata)
+compare_passwd(struct passwd *pwd1, struct passwd *pwd2, void *mdata __unused)
{
ATF_REQUIRE(pwd1 != NULL);
ATF_REQUIRE(pwd2 != NULL);
@@ -142,6 +142,7 @@ sdump_passwd(struct passwd *pwd, char *buffer, size_t buflen)
pwd->pw_fields);
}
+#ifdef DEBUG
static void
dump_passwd(struct passwd *pwd)
{
@@ -152,6 +153,7 @@ dump_passwd(struct passwd *pwd)
} else
printf("(null)\n");
}
+#endif
static int
passwd_read_snapshot_func(struct passwd *pwd, char *line)
@@ -251,7 +253,7 @@ passwd_fill_test_data(struct passwd_test_data *td)
}
static int
-passwd_test_correctness(struct passwd *pwd, void *mdata)
+passwd_test_correctness(struct passwd *pwd, void *mdata __unused)
{
#ifdef DEBUG
@@ -363,7 +365,7 @@ passwd_test_getpwuid(struct passwd *pwd_model, void *mdata)
}
static int
-passwd_test_getpwent(struct passwd *pwd, void *mdata)
+passwd_test_getpwent(struct passwd *pwd, void *mdata __unused)
{
/* Only correctness can be checked when doing 1-pass test for
* getpwent(). */
diff --git a/lib/libc/tests/nss/getrpc_test.c b/lib/libc/tests/nss/getrpc_test.c
index 54e04b269542..6b9f30d4fbe7 100644
--- a/lib/libc/tests/nss/getrpc_test.c
+++ b/lib/libc/tests/nss/getrpc_test.c
@@ -70,8 +70,6 @@ static int rpcent_test_getrpcbyname(struct rpcent *, void *);
static int rpcent_test_getrpcbynumber(struct rpcent *, void *);
static int rpcent_test_getrpcent(struct rpcent *, void *);
-static void usage(void) __attribute__((__noreturn__));
-
IMPLEMENT_TEST_DATA(rpcent)
IMPLEMENT_TEST_FILE_SNAPSHOT(rpcent)
IMPLEMENT_1PASS_TEST(rpcent)
@@ -100,7 +98,7 @@ clone_rpcent(struct rpcent *dest, struct rpcent const *src)
for (cp = src->r_aliases; *cp; ++cp)
++aliases_num;
- dest->r_aliases = calloc(1, (aliases_num + 1) * sizeof(char *));
+ dest->r_aliases = calloc(aliases_num + 1, sizeof(char *));
ATF_REQUIRE(dest->r_aliases != NULL);
for (cp = src->r_aliases; *cp; ++cp) {
@@ -173,16 +171,16 @@ sdump_rpcent(struct rpcent *rpc, char *buffer, size_t buflen)
written = snprintf(buffer, buflen, "%s %d",
rpc->r_name, rpc->r_number);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
if (rpc->r_aliases != NULL) {
if (*(rpc->r_aliases) != '\0') {
for (cp = rpc->r_aliases; *cp; ++cp) {
- written = snprintf(buffer, buflen, " %s",*cp);
+ written = snprintf(buffer, buflen, " %s", *cp);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
@@ -289,7 +287,7 @@ rpcent_fill_test_data(struct rpcent_test_data *td)
}
static int
-rpcent_test_correctness(struct rpcent *rpc, void *mdata)
+rpcent_test_correctness(struct rpcent *rpc, void *mdata __unused)
{
printf("testing correctness with the following data:\n");
@@ -390,7 +388,7 @@ rpcent_test_getrpcbynumber(struct rpcent *rpc_model, void *mdata)
}
static int
-rpcent_test_getrpcent(struct rpcent *rpc, void *mdata)
+rpcent_test_getrpcent(struct rpcent *rpc, void *mdata __unused)
{
/*
@@ -400,7 +398,7 @@ rpcent_test_getrpcent(struct rpcent *rpc, void *mdata)
return (rpcent_test_correctness(rpc, NULL));
}
-int
+static int
run_tests(const char *snapshot_file, enum test_methods method)
{
struct rpcent_test_data td, td_snap, td_2pass;
diff --git a/lib/libc/tests/nss/getserv_test.c b/lib/libc/tests/nss/getserv_test.c
index 29c1dfaf2ddd..dcde9293d22a 100644
--- a/lib/libc/tests/nss/getserv_test.c
+++ b/lib/libc/tests/nss/getserv_test.c
@@ -102,7 +102,7 @@ clone_servent(struct servent *dest, struct servent const *src)
for (cp = src->s_aliases; *cp; ++cp)
++aliases_num;
- dest->s_aliases = calloc(1, (aliases_num + 1) * sizeof(char *));
+ dest->s_aliases = calloc(aliases_num + 1, sizeof(char *));
ATF_REQUIRE(dest->s_aliases != NULL);
for (cp = src->s_aliases; *cp; ++cp) {
@@ -177,16 +177,16 @@ sdump_servent(struct servent *serv, char *buffer, size_t buflen)
written = snprintf(buffer, buflen, "%s %d %s",
serv->s_name, ntohs(serv->s_port), serv->s_proto);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
if (serv->s_aliases != NULL) {
if (*(serv->s_aliases) != '\0') {
for (cp = serv->s_aliases; *cp; ++cp) {
- written = snprintf(buffer, buflen, " %s",*cp);
+ written = snprintf(buffer, buflen, " %s", *cp);
buffer += written;
- if (written > buflen)
+ if (written > (int)buflen)
return;
buflen -= written;
@@ -300,7 +300,7 @@ servent_fill_test_data(struct servent_test_data *td)
}
static int
-servent_test_correctness(struct servent *serv, void *mdata)
+servent_test_correctness(struct servent *serv, void *mdata __unused)
{
printf("testing correctness with the following data:\n");
dump_servent(serv);
@@ -403,14 +403,14 @@ servent_test_getservbyport(struct servent *serv_model, void *mdata)
}
static int
-servent_test_getservent(struct servent *serv, void *mdata)
+servent_test_getservent(struct servent *serv, void *mdata __unused)
{
/* Only correctness can be checked when doing 1-pass test for
* getservent(). */
return (servent_test_correctness(serv, NULL));
}
-int
+static int
run_tests(const char *snapshot_file, enum test_methods method)
{
struct servent_test_data td, td_snap, td_2pass;
diff --git a/lib/libc/tests/nss/getusershell_test.c b/lib/libc/tests/nss/getusershell_test.c
index ccd8cf96a6ed..e5c4b6755263 100644
--- a/lib/libc/tests/nss/getusershell_test.c
+++ b/lib/libc/tests/nss/getusershell_test.c
@@ -48,8 +48,6 @@ struct usershell {
char *path;
};
-static enum test_methods method = TEST_GETUSERSHELL;
-
DECLARE_TEST_DATA(usershell)
DECLARE_TEST_FILE_SNAPSHOT(usershell)
DECLARE_2PASS_TEST(usershell)
@@ -78,7 +76,8 @@ clone_usershell(struct usershell *dest, struct usershell const *src)
}
static int
-compare_usershell(struct usershell *us1, struct usershell *us2, void *mdata)
+compare_usershell(struct usershell *us1, struct usershell *us2,
+ void *mdata __unused)
{
int rv;
@@ -134,7 +133,7 @@ usershell_read_snapshot_func(struct usershell *us, char *line)
return (0);
}
-int
+static int
run_tests(const char *snapshot_file, enum test_methods method)
{
struct usershell_test_data td, td_snap;