Module Name: src Committed By: christos Date: Tue Jan 10 15:19:00 UTC 2017
Modified Files: src/tests/lib/libc/gen: t_dir.c Log Message: PR/51808: Ngie Cooper: fix leaks, sort includes, check returns To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/lib/libc/gen/t_dir.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/libc/gen/t_dir.c diff -u src/tests/lib/libc/gen/t_dir.c:1.6 src/tests/lib/libc/gen/t_dir.c:1.7 --- src/tests/lib/libc/gen/t_dir.c:1.6 Sat Oct 19 13:45:00 2013 +++ src/tests/lib/libc/gen/t_dir.c Tue Jan 10 10:19:00 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: t_dir.c,v 1.6 2013/10/19 17:45:00 christos Exp $ */ +/* $NetBSD: t_dir.c,v 1.7 2017/01/10 15:19:00 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -26,18 +26,19 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include <atf-c.h> - +#include <sys/stat.h> #include <assert.h> +#include <atf-c.h> #include <dirent.h> #include <err.h> +#include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> -#include <sys/stat.h> + ATF_TC(seekdir_basic); ATF_TC_HEAD(seekdir_basic, tc) @@ -54,10 +55,19 @@ ATF_TC_BODY(seekdir_basic, tc) struct dirent *entry; long here; - mkdir("t", 0755); - creat("t/a", 0600); - creat("t/b", 0600); - creat("t/c", 0600); +#define CREAT(x, m) do { \ + int _creat_fd; \ + ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))), \ + "creat(%s, %x) failed: %s", (x), (m), \ + strerror(errno)); \ + (void)close(_creat_fd); \ + } while(0); + + ATF_REQUIRE_MSG(mkdir("t", 0755) == 0, + "mkdir failed: %s", strerror(errno)); + CREAT("t/a", 0600); + CREAT("t/b", 0600); + CREAT("t/c", 0600); dp = opendir("t"); if ( dp == NULL) @@ -70,6 +80,8 @@ ATF_TC_BODY(seekdir_basic, tc) /* get first entry */ entry = readdir(dp); here = telldir(dp); + ATF_REQUIRE_MSG(here != -1, + "telldir failed: %s", strerror(errno)); /* get second entry */ entry = readdir(dp); @@ -109,6 +121,7 @@ ATF_TC_BODY(seekdir_basic, tc) atf_tc_fail("3rd seekdir found wrong name"); closedir(dp); + free(wasname); } ATF_TC(telldir_leak);