t_dir.c (312090) | t_dir.c (313227) |
---|---|
1/* $NetBSD: t_dir.c,v 1.6 2013/10/19 17:45:00 christos Exp $ */ | 1/* $NetBSD: t_dir.c,v 1.8 2017/01/11 07:26:17 christos Exp $ */ |
2 3/*- 4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 11 unchanged lines hidden (view full) --- 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 | 2 3/*- 4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 11 unchanged lines hidden (view full) --- 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 |
29#include <atf-c.h> 30 | 29#include <sys/stat.h> |
31#include <assert.h> | 30#include <assert.h> |
31#include <atf-c.h> |
|
32#include <dirent.h> 33#include <err.h> | 32#include <dirent.h> 33#include <err.h> |
34#include <errno.h> |
|
34#include <fcntl.h> 35#include <stdio.h> 36#include <stdlib.h> 37#include <string.h> 38#include <unistd.h> 39 | 35#include <fcntl.h> 36#include <stdio.h> 37#include <stdlib.h> 38#include <string.h> 39#include <unistd.h> 40 |
40#include <sys/stat.h> | |
41 | 41 |
42#ifdef __FreeBSD__ 43#include <errno.h> 44#endif | |
45 46ATF_TC(seekdir_basic); 47ATF_TC_HEAD(seekdir_basic, tc) 48{ 49 50 atf_tc_set_md_var(tc, "descr", "Check telldir(3) and seekdir(3) " 51 "for correct behavior (PR lib/24324)"); 52} 53 54ATF_TC_BODY(seekdir_basic, tc) 55{ 56 DIR *dp; 57 char *wasname; 58 struct dirent *entry; 59 long here; 60 | 42 43ATF_TC(seekdir_basic); 44ATF_TC_HEAD(seekdir_basic, tc) 45{ 46 47 atf_tc_set_md_var(tc, "descr", "Check telldir(3) and seekdir(3) " 48 "for correct behavior (PR lib/24324)"); 49} 50 51ATF_TC_BODY(seekdir_basic, tc) 52{ 53 DIR *dp; 54 char *wasname; 55 struct dirent *entry; 56 long here; 57 |
61#ifdef __FreeBSD__ | |
62#define CREAT(x, m) do { \ 63 int _creat_fd; \ 64 ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))) != -1, \ 65 "creat(%s, %x) failed: %s", (x), (m), \ 66 strerror(errno)); \ 67 (void)close(_creat_fd); \ 68 } while(0); 69 70 ATF_REQUIRE_MSG(mkdir("t", 0755) == 0, 71 "mkdir failed: %s", strerror(errno)); 72 CREAT("t/a", 0600); 73 CREAT("t/b", 0600); 74 CREAT("t/c", 0600); | 58#define CREAT(x, m) do { \ 59 int _creat_fd; \ 60 ATF_REQUIRE_MSG((_creat_fd = creat((x), (m))) != -1, \ 61 "creat(%s, %x) failed: %s", (x), (m), \ 62 strerror(errno)); \ 63 (void)close(_creat_fd); \ 64 } while(0); 65 66 ATF_REQUIRE_MSG(mkdir("t", 0755) == 0, 67 "mkdir failed: %s", strerror(errno)); 68 CREAT("t/a", 0600); 69 CREAT("t/b", 0600); 70 CREAT("t/c", 0600); |
75#else 76 mkdir("t", 0755); 77 creat("t/a", 0600); 78 creat("t/b", 0600); 79 creat("t/c", 0600); 80#endif | |
81 82 dp = opendir("t"); 83 if ( dp == NULL) 84 atf_tc_fail("Could not open temp directory."); 85 86 /* skip two for . and .. */ 87 entry = readdir(dp); 88 entry = readdir(dp); 89 90 /* get first entry */ 91 entry = readdir(dp); 92 here = telldir(dp); | 71 72 dp = opendir("t"); 73 if ( dp == NULL) 74 atf_tc_fail("Could not open temp directory."); 75 76 /* skip two for . and .. */ 77 entry = readdir(dp); 78 entry = readdir(dp); 79 80 /* get first entry */ 81 entry = readdir(dp); 82 here = telldir(dp); |
93#ifdef __FreeBSD__ | |
94 ATF_REQUIRE_MSG(here != -1, 95 "telldir failed: %s", strerror(errno)); | 83 ATF_REQUIRE_MSG(here != -1, 84 "telldir failed: %s", strerror(errno)); |
96#endif | |
97 98 /* get second entry */ 99 entry = readdir(dp); 100#ifdef __FreeBSD__ 101 ATF_REQUIRE_MSG(entry != NULL, 102 "readdir failed: %s", strerror(errno)); 103#endif 104 wasname = strdup(entry->d_name); --- 27 unchanged lines hidden (view full) --- 132 entry = readdir(dp); 133 134 if (entry == NULL) 135 atf_tc_fail("entry 3 not found"); 136 if (strcmp(entry->d_name, wasname) != 0) 137 atf_tc_fail("3rd seekdir found wrong name"); 138 139 closedir(dp); | 85 86 /* get second entry */ 87 entry = readdir(dp); 88#ifdef __FreeBSD__ 89 ATF_REQUIRE_MSG(entry != NULL, 90 "readdir failed: %s", strerror(errno)); 91#endif 92 wasname = strdup(entry->d_name); --- 27 unchanged lines hidden (view full) --- 120 entry = readdir(dp); 121 122 if (entry == NULL) 123 atf_tc_fail("entry 3 not found"); 124 if (strcmp(entry->d_name, wasname) != 0) 125 atf_tc_fail("3rd seekdir found wrong name"); 126 127 closedir(dp); |
140#ifdef __FreeBSD__ | |
141 free(wasname); | 128 free(wasname); |
142#endif | |
143} 144 145/* There is no sbrk on AArch64 and RISC-V */ 146#if !defined(__aarch64__) && !defined(__riscv__) 147ATF_TC(telldir_leak); 148ATF_TC_HEAD(telldir_leak, tc) 149{ 150 --- 51 unchanged lines hidden --- | 129} 130 131/* There is no sbrk on AArch64 and RISC-V */ 132#if !defined(__aarch64__) && !defined(__riscv__) 133ATF_TC(telldir_leak); 134ATF_TC_HEAD(telldir_leak, tc) 135{ 136 --- 51 unchanged lines hidden --- |