Deleted Added
full compact
getproto_test.c (302408) getproto_test.c (319299)
1/*-
2 * Copyright (c) 2006 Michael Bushkov <bushman@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006 Michael Bushkov <bushman@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: stable/11/lib/libc/tests/nss/getproto_test.c 298830 2016-04-30 01:24:24Z pfg $");
29__FBSDID("$FreeBSD: stable/11/lib/libc/tests/nss/getproto_test.c 319299 2017-05-31 08:32:05Z ngie $");
30
31#include <arpa/inet.h>
32#include <assert.h>
33#include <errno.h>
34#include <netdb.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>

--- 56 unchanged lines hidden (view full) ---

94
95 dest->p_proto = src->p_proto;
96
97 if (src->p_aliases != NULL) {
98 aliases_num = 0;
99 for (cp = src->p_aliases; *cp; ++cp)
100 ++aliases_num;
101
30
31#include <arpa/inet.h>
32#include <assert.h>
33#include <errno.h>
34#include <netdb.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>

--- 56 unchanged lines hidden (view full) ---

94
95 dest->p_proto = src->p_proto;
96
97 if (src->p_aliases != NULL) {
98 aliases_num = 0;
99 for (cp = src->p_aliases; *cp; ++cp)
100 ++aliases_num;
101
102 dest->p_aliases = calloc(1, (aliases_num+1) * sizeof(char *));
102 dest->p_aliases = calloc(aliases_num + 1, sizeof(char *));
103 assert(dest->p_aliases != NULL);
104
105 for (cp = src->p_aliases; *cp; ++cp) {
106 dest->p_aliases[cp - src->p_aliases] = strdup(*cp);
107 assert(dest->p_aliases[cp - src->p_aliases] != NULL);
108 }
109 }
110}

--- 56 unchanged lines hidden (view full) ---

167sdump_protoent(struct protoent *pe, char *buffer, size_t buflen)
168{
169 char **cp;
170 int written;
171
172 written = snprintf(buffer, buflen, "%s %d",
173 pe->p_name, pe->p_proto);
174 buffer += written;
103 assert(dest->p_aliases != NULL);
104
105 for (cp = src->p_aliases; *cp; ++cp) {
106 dest->p_aliases[cp - src->p_aliases] = strdup(*cp);
107 assert(dest->p_aliases[cp - src->p_aliases] != NULL);
108 }
109 }
110}

--- 56 unchanged lines hidden (view full) ---

167sdump_protoent(struct protoent *pe, char *buffer, size_t buflen)
168{
169 char **cp;
170 int written;
171
172 written = snprintf(buffer, buflen, "%s %d",
173 pe->p_name, pe->p_proto);
174 buffer += written;
175 if (written > buflen)
175 if (written > (int)buflen)
176 return;
177 buflen -= written;
178
179 if (pe->p_aliases != NULL) {
180 if (*(pe->p_aliases) != '\0') {
181 for (cp = pe->p_aliases; *cp; ++cp) {
176 return;
177 buflen -= written;
178
179 if (pe->p_aliases != NULL) {
180 if (*(pe->p_aliases) != '\0') {
181 for (cp = pe->p_aliases; *cp; ++cp) {
182 written = snprintf(buffer, buflen, " %s",*cp);
182 written = snprintf(buffer, buflen, " %s", *cp);
183 buffer += written;
183 buffer += written;
184 if (written > buflen)
184 if (written > (int)buflen)
185 return;
186 buflen -= written;
187
188 if (buflen == 0)
189 return;
190 }
191 } else
192 snprintf(buffer, buflen, " noaliases");

--- 90 unchanged lines hidden (view full) ---

283 return (-1);
284 }
285 endprotoent();
286
287 return (0);
288}
289
290static int
185 return;
186 buflen -= written;
187
188 if (buflen == 0)
189 return;
190 }
191 } else
192 snprintf(buffer, buflen, " noaliases");

--- 90 unchanged lines hidden (view full) ---

283 return (-1);
284 }
285 endprotoent();
286
287 return (0);
288}
289
290static int
291protoent_test_correctness(struct protoent *pe, void *mdata)
291protoent_test_correctness(struct protoent *pe, void *mdata __unused)
292{
293 printf("testing correctness with the following data:\n");
294 dump_protoent(pe);
295
296 if (pe == NULL)
297 goto errfin;
298
299 if (pe->p_name == NULL)

--- 83 unchanged lines hidden (view full) ---

383 return (-1);
384 } else {
385 printf("ok\n");
386 return (0);
387 }
388}
389
390static int
292{
293 printf("testing correctness with the following data:\n");
294 dump_protoent(pe);
295
296 if (pe == NULL)
297 goto errfin;
298
299 if (pe->p_name == NULL)

--- 83 unchanged lines hidden (view full) ---

383 return (-1);
384 } else {
385 printf("ok\n");
386 return (0);
387 }
388}
389
390static int
391protoent_test_getprotoent(struct protoent *pe, void *mdata)
391protoent_test_getprotoent(struct protoent *pe, void *mdata __unused)
392{
393 /* Only correctness can be checked when doing 1-pass test for
394 * getprotoent(). */
395 return (protoent_test_correctness(pe, NULL));
396}
397
392{
393 /* Only correctness can be checked when doing 1-pass test for
394 * getprotoent(). */
395 return (protoent_test_correctness(pe, NULL));
396}
397
398int
398static int
399run_tests(const char *snapshot_file, enum test_methods method)
400{
401 struct protoent_test_data td, td_snap, td_2pass;
402 int rv;
403
404 TEST_DATA_INIT(protoent, &td, clone_protoent, free_protoent);
405 TEST_DATA_INIT(protoent, &td_snap, clone_protoent, free_protoent);
406 if (snapshot_file != NULL) {

--- 150 unchanged lines hidden ---
399run_tests(const char *snapshot_file, enum test_methods method)
400{
401 struct protoent_test_data td, td_snap, td_2pass;
402 int rv;
403
404 TEST_DATA_INIT(protoent, &td, clone_protoent, free_protoent);
405 TEST_DATA_INIT(protoent, &td_snap, clone_protoent, free_protoent);
406 if (snapshot_file != NULL) {

--- 150 unchanged lines hidden ---