| @@ -1,1166 +1,1167 @@ | | | @@ -1,1166 +1,1167 @@ |
1 | /* $NetBSD: t_fmemopen.c,v 1.4 2013/10/19 17:45:00 christos Exp $ */ | | 1 | /* $NetBSD: t_fmemopen.c,v 1.5 2021/07/10 07:50:33 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c)2010 Takehiko NOZAKI, | | 4 | * Copyright (c)2010 Takehiko NOZAKI, |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * | | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | * | | 27 | * |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | #if defined(__NetBSD__) | | 30 | #if defined(__NetBSD__) |
31 | #include <atf-c.h> | | 31 | #include <atf-c.h> |
32 | #else | | 32 | #else |
33 | #if defined(__linux__) | | 33 | #if defined(__linux__) |
34 | #define _GNU_SOURCE | | 34 | #define _GNU_SOURCE |
35 | #include <features.h> | | 35 | #include <features.h> |
36 | #endif | | 36 | #endif |
37 | #include <assert.h> | | 37 | #include <assert.h> |
38 | #include <stdio.h> | | 38 | #include <stdio.h> |
39 | #define ATF_TC(arg0) static void arg0##_head(void) | | 39 | #define ATF_TC(arg0) static void arg0##_head(void) |
40 | #define ATF_TC_HEAD(arg0, arg1) static void arg0##_head() | | 40 | #define ATF_TC_HEAD(arg0, arg1) static void arg0##_head() |
41 | #define atf_tc_set_md_var(arg0, arg1, ...) do { \ | | 41 | #define atf_tc_set_md_var(arg0, arg1, ...) do { \ |
42 | printf(__VA_ARGS__); \ | | 42 | printf(__VA_ARGS__); \ |
43 | puts(""); \ | | 43 | puts(""); \ |
44 | } while (/*CONSTCOND*/0) | | 44 | } while (/*CONSTCOND*/0) |
45 | #define ATF_TC_BODY(arg0, arg1) static void arg0##_body() | | 45 | #define ATF_TC_BODY(arg0, arg1) static void arg0##_body() |
46 | #define ATF_CHECK(arg0) assert(arg0) | | 46 | #define ATF_CHECK(arg0) assert(arg0) |
47 | #define ATF_TP_ADD_TCS(arg0) int main(void) | | 47 | #define ATF_TP_ADD_TCS(arg0) int main(void) |
48 | #define ATF_TP_ADD_TC(arg0, arg1) arg1##_head(); arg1##_body() | | 48 | #define ATF_TP_ADD_TC(arg0, arg1) arg1##_head(); arg1##_body() |
49 | #define atf_no_error() 0 | | 49 | #define atf_no_error() 0 |
50 | #endif | | 50 | #endif |
51 | | | 51 | |
52 | #include <errno.h> | | 52 | #include <errno.h> |
53 | #include <stdint.h> | | 53 | #include <stdint.h> |
54 | #include <stdio.h> | | 54 | #include <stdio.h> |
55 | #include <limits.h> | | 55 | #include <limits.h> |
56 | #include <stdlib.h> | | 56 | #include <stdlib.h> |
57 | #include <string.h> | | 57 | #include <string.h> |
58 | | | 58 | |
59 | const char *mode_rwa[] = { | | 59 | const char *mode_rwa[] = { |
60 | "r", "rb", "r+", "rb+", "r+b", | | 60 | "r", "rb", "r+", "rb+", "r+b", |
61 | "w", "wb", "w+", "wb+", "w+b", | | 61 | "w", "wb", "w+", "wb+", "w+b", |
62 | "a", "ab", "a+", "ab+", "a+b", | | 62 | "a", "ab", "a+", "ab+", "a+b", |
63 | NULL | | 63 | NULL |
64 | }; | | 64 | }; |
65 | | | 65 | |
66 | const char *mode_r[] = { "r", "rb", "r+", "rb+", "r+b", NULL }; | | 66 | const char *mode_r[] = { "r", "rb", "r+", "rb+", "r+b", NULL }; |
67 | const char *mode_w[] = { "w", "wb", "w+", "wb+", "w+b", NULL }; | | 67 | const char *mode_w[] = { "w", "wb", "w+", "wb+", "w+b", NULL }; |
68 | const char *mode_a[] = { "a", "ab", "a+", "ab+", "a+b", NULL }; | | 68 | const char *mode_a[] = { "a", "ab", "a+", "ab+", "a+b", NULL }; |
69 | | | 69 | |
70 | struct testcase { | | 70 | struct testcase { |
71 | const char *s; | | 71 | const char *s; |
72 | off_t n; | | 72 | off_t n; |
73 | } testcases[] = { | | 73 | } testcases[] = { |
74 | #define TESTSTR(s) { s, sizeof(s)-1 } | | 74 | #define TESTSTR(s) { s, sizeof(s)-1 } |
75 | TESTSTR("\0he quick brown fox jumps over the lazy dog"), | | 75 | TESTSTR("\0he quick brown fox jumps over the lazy dog"), |
76 | TESTSTR("T\0e quick brown fox jumps over the lazy dog"), | | 76 | TESTSTR("T\0e quick brown fox jumps over the lazy dog"), |
77 | TESTSTR("Th\0 quick brown fox jumps over the lazy dog"), | | 77 | TESTSTR("Th\0 quick brown fox jumps over the lazy dog"), |
78 | TESTSTR("The\0quick brown fox jumps over the lazy dog"), | | 78 | TESTSTR("The\0quick brown fox jumps over the lazy dog"), |
79 | TESTSTR("The \0uick brown fox jumps over the lazy dog"), | | 79 | TESTSTR("The \0uick brown fox jumps over the lazy dog"), |
80 | TESTSTR("The q\0ick brown fox jumps over the lazy dog"), | | 80 | TESTSTR("The q\0ick brown fox jumps over the lazy dog"), |
81 | TESTSTR("The qu\0ck brown fox jumps over the lazy dog"), | | 81 | TESTSTR("The qu\0ck brown fox jumps over the lazy dog"), |
82 | TESTSTR("The qui\0k brown fox jumps over the lazy dog"), | | 82 | TESTSTR("The qui\0k brown fox jumps over the lazy dog"), |
83 | TESTSTR("The quic\0 brown fox jumps over the lazy dog"), | | 83 | TESTSTR("The quic\0 brown fox jumps over the lazy dog"), |
84 | TESTSTR("The quick\0brown fox jumps over the lazy dog"), | | 84 | TESTSTR("The quick\0brown fox jumps over the lazy dog"), |
85 | TESTSTR("The quick \0rown fox jumps over the lazy dog"), | | 85 | TESTSTR("The quick \0rown fox jumps over the lazy dog"), |
86 | TESTSTR("The quick b\0own fox jumps over the lazy dog"), | | 86 | TESTSTR("The quick b\0own fox jumps over the lazy dog"), |
87 | TESTSTR("The quick br\0wn fox jumps over the lazy dog"), | | 87 | TESTSTR("The quick br\0wn fox jumps over the lazy dog"), |
88 | TESTSTR("The quick bro\0n fox jumps over the lazy dog"), | | 88 | TESTSTR("The quick bro\0n fox jumps over the lazy dog"), |
89 | TESTSTR("The quick brow\0 fox jumps over the lazy dog"), | | 89 | TESTSTR("The quick brow\0 fox jumps over the lazy dog"), |
90 | TESTSTR("The quick brown\0fox jumps over the lazy dog"), | | 90 | TESTSTR("The quick brown\0fox jumps over the lazy dog"), |
91 | TESTSTR("The quick brown \0ox jumps over the lazy dog"), | | 91 | TESTSTR("The quick brown \0ox jumps over the lazy dog"), |
92 | TESTSTR("The quick brown f\0x jumps over the lazy dog"), | | 92 | TESTSTR("The quick brown f\0x jumps over the lazy dog"), |
93 | TESTSTR("The quick brown fo\0 jumps over the lazy dog"), | | 93 | TESTSTR("The quick brown fo\0 jumps over the lazy dog"), |
94 | TESTSTR("The quick brown fox\0jumps over the lazy dog"), | | 94 | TESTSTR("The quick brown fox\0jumps over the lazy dog"), |
95 | TESTSTR("The quick brown fox \0umps over the lazy dog"), | | 95 | TESTSTR("The quick brown fox \0umps over the lazy dog"), |
96 | TESTSTR("The quick brown fox j\0mps over the lazy dog"), | | 96 | TESTSTR("The quick brown fox j\0mps over the lazy dog"), |
97 | TESTSTR("The quick brown fox ju\0ps over the lazy dog"), | | 97 | TESTSTR("The quick brown fox ju\0ps over the lazy dog"), |
98 | TESTSTR("The quick brown fox jum\0s over the lazy dog"), | | 98 | TESTSTR("The quick brown fox jum\0s over the lazy dog"), |
99 | TESTSTR("The quick brown fox jump\0 over the lazy dog"), | | 99 | TESTSTR("The quick brown fox jump\0 over the lazy dog"), |
100 | TESTSTR("The quick brown fox jumps\0over the lazy dog"), | | 100 | TESTSTR("The quick brown fox jumps\0over the lazy dog"), |
101 | TESTSTR("The quick brown fox jumps \0ver the lazy dog"), | | 101 | TESTSTR("The quick brown fox jumps \0ver the lazy dog"), |
102 | TESTSTR("The quick brown fox jumps o\0er the lazy dog"), | | 102 | TESTSTR("The quick brown fox jumps o\0er the lazy dog"), |
103 | TESTSTR("The quick brown fox jumps ov\0r the lazy dog"), | | 103 | TESTSTR("The quick brown fox jumps ov\0r the lazy dog"), |
104 | TESTSTR("The quick brown fox jumps ove\0 the lazy dog"), | | 104 | TESTSTR("The quick brown fox jumps ove\0 the lazy dog"), |
105 | TESTSTR("The quick brown fox jumps over\0the lazy dog"), | | 105 | TESTSTR("The quick brown fox jumps over\0the lazy dog"), |
106 | TESTSTR("The quick brown fox jumps over \0he lazy dog"), | | 106 | TESTSTR("The quick brown fox jumps over \0he lazy dog"), |
107 | TESTSTR("The quick brown fox jumps over t\0e lazy dog"), | | 107 | TESTSTR("The quick brown fox jumps over t\0e lazy dog"), |
108 | TESTSTR("The quick brown fox jumps over th\0 lazy dog"), | | 108 | TESTSTR("The quick brown fox jumps over th\0 lazy dog"), |
109 | TESTSTR("The quick brown fox jumps over the\0lazy dog"), | | 109 | TESTSTR("The quick brown fox jumps over the\0lazy dog"), |
110 | TESTSTR("The quick brown fox jumps over the \0azy dog"), | | 110 | TESTSTR("The quick brown fox jumps over the \0azy dog"), |
111 | TESTSTR("The quick brown fox jumps over the l\0zy dog"), | | 111 | TESTSTR("The quick brown fox jumps over the l\0zy dog"), |
112 | TESTSTR("The quick brown fox jumps over the la\0y dog"), | | 112 | TESTSTR("The quick brown fox jumps over the la\0y dog"), |
113 | TESTSTR("The quick brown fox jumps over the laz\0 dog"), | | 113 | TESTSTR("The quick brown fox jumps over the laz\0 dog"), |
114 | TESTSTR("The quick brown fox jumps over the lazy\0dog"), | | 114 | TESTSTR("The quick brown fox jumps over the lazy\0dog"), |
115 | TESTSTR("The quick brown fox jumps over the lazy \0og"), | | 115 | TESTSTR("The quick brown fox jumps over the lazy \0og"), |
116 | TESTSTR("The quick brown fox jumps over the lazy d\0g"), | | 116 | TESTSTR("The quick brown fox jumps over the lazy d\0g"), |
117 | TESTSTR("The quick brown fox jumps over the lazy do\0"), | | 117 | TESTSTR("The quick brown fox jumps over the lazy do\0"), |
118 | TESTSTR("The quick brown fox jumps over the lazy dog"), | | 118 | TESTSTR("The quick brown fox jumps over the lazy dog"), |
119 | { NULL, 0 }, | | 119 | { NULL, 0 }, |
120 | }; | | 120 | }; |
121 | | | 121 | |
122 | ATF_TC(test00); | | 122 | ATF_TC(test00); |
123 | ATF_TC_HEAD(test00, tc) | | 123 | ATF_TC_HEAD(test00, tc) |
124 | { | | 124 | { |
125 | atf_tc_set_md_var(tc, "descr", "test00"); | | 125 | atf_tc_set_md_var(tc, "descr", "test00"); |
126 | } | | 126 | } |
127 | ATF_TC_BODY(test00, tc) | | 127 | ATF_TC_BODY(test00, tc) |
128 | { | | 128 | { |
129 | const char **p; | | 129 | const char **p; |
130 | char buf[BUFSIZ]; | | 130 | char buf[BUFSIZ]; |
131 | FILE *fp; | | 131 | FILE *fp; |
132 | | | 132 | |
133 | for (p = &mode_rwa[0]; *p != NULL; ++p) { | | 133 | for (p = &mode_rwa[0]; *p != NULL; ++p) { |
134 | fp = fmemopen(&buf[0], sizeof(buf), *p); | | 134 | fp = fmemopen(&buf[0], sizeof(buf), *p); |
135 | /* | | 135 | /* |
136 | * Upon successful completion, fmemopen() shall return a pointer to the | | 136 | * Upon successful completion, fmemopen() shall return a pointer to the |
137 | * object controlling the stream. | | 137 | * object controlling the stream. |
138 | */ | | 138 | */ |
139 | ATF_CHECK(fp != NULL); | | 139 | ATF_CHECK(fp != NULL); |
140 | | | 140 | |
141 | ATF_CHECK(fclose(fp) == 0); | | 141 | ATF_CHECK(fclose(fp) == 0); |
142 | } | | 142 | } |
143 | } | | 143 | } |
144 | | | 144 | |
145 | ATF_TC(test01); | | 145 | ATF_TC(test01); |
146 | ATF_TC_HEAD(test01, tc) | | 146 | ATF_TC_HEAD(test01, tc) |
147 | { | | 147 | { |
148 | atf_tc_set_md_var(tc, "descr", "test01"); | | 148 | atf_tc_set_md_var(tc, "descr", "test01"); |
149 | } | | 149 | } |
150 | ATF_TC_BODY(test01, tc) | | 150 | ATF_TC_BODY(test01, tc) |
151 | { | | 151 | { |
152 | const char **p; | | 152 | const char **p; |
153 | const char *mode[] = { | | 153 | const char *mode[] = { |
154 | "r+", "rb+", "r+b", | | 154 | "r+", "rb+", "r+b", |
155 | "w+", "wb+", "w+b", | | 155 | "w+", "wb+", "w+b", |
156 | "a+", "ab+", "a+b", | | 156 | "a+", "ab+", "a+b", |
157 | NULL | | 157 | NULL |
158 | }; | | 158 | }; |
159 | FILE *fp; | | 159 | FILE *fp; |
160 | | | 160 | |
161 | for (p = &mode[0]; *p != NULL; ++p) { | | 161 | for (p = &mode[0]; *p != NULL; ++p) { |
162 | /* | | 162 | /* |
163 | * If a null pointer is specified as the buf argument, fmemopen() shall | | 163 | * If a null pointer is specified as the buf argument, fmemopen() shall |
164 | * allocate size bytes of memory as if by a call to malloc(). | | 164 | * allocate size bytes of memory as if by a call to malloc(). |
165 | */ | | 165 | */ |
166 | fp = fmemopen(NULL, BUFSIZ, *p); | | 166 | fp = fmemopen(NULL, BUFSIZ, *p); |
167 | ATF_CHECK(fp != NULL); | | 167 | ATF_CHECK(fp != NULL); |
168 | | | 168 | |
169 | /* | | 169 | /* |
170 | * If buf is a null pointer, the initial position shall always be set | | 170 | * If buf is a null pointer, the initial position shall always be set |
171 | * to the beginning of the buffer. | | 171 | * to the beginning of the buffer. |
172 | */ | | 172 | */ |
173 | ATF_CHECK(ftello(fp) == (off_t)0); | | 173 | ATF_CHECK(ftello(fp) == (off_t)0); |
174 | | | 174 | |
175 | ATF_CHECK(fclose(fp) == 0); | | 175 | ATF_CHECK(fclose(fp) == 0); |
176 | } | | 176 | } |
177 | } | | 177 | } |
178 | | | 178 | |
179 | ATF_TC(test02); | | 179 | ATF_TC(test02); |
180 | ATF_TC_HEAD(test02, tc) | | 180 | ATF_TC_HEAD(test02, tc) |
181 | { | | 181 | { |
182 | atf_tc_set_md_var(tc, "descr", "test02"); | | 182 | atf_tc_set_md_var(tc, "descr", "test02"); |
183 | } | | 183 | } |
184 | ATF_TC_BODY(test02, tc) | | 184 | ATF_TC_BODY(test02, tc) |
185 | { | | 185 | { |
186 | const char **p; | | 186 | const char **p; |
187 | char buf[BUFSIZ]; | | 187 | char buf[BUFSIZ]; |
188 | FILE *fp; | | 188 | FILE *fp; |
189 | | | 189 | |
190 | for (p = &mode_r[0]; *p != NULL; ++p) { | | 190 | for (p = &mode_r[0]; *p != NULL; ++p) { |
191 | | | 191 | |
192 | memset(&buf[0], 0x1, sizeof(buf)); | | 192 | memset(&buf[0], 0x1, sizeof(buf)); |
193 | fp = fmemopen(&buf[0], sizeof(buf), *p); | | 193 | fp = fmemopen(&buf[0], sizeof(buf), *p); |
194 | ATF_CHECK(fp != NULL); | | 194 | ATF_CHECK(fp != NULL); |
195 | | | 195 | |
196 | /* | | 196 | /* |
197 | * This position is initially set to either the beginning of the buffer | | 197 | * This position is initially set to either the beginning of the buffer |
198 | * (for r and w modes) | | 198 | * (for r and w modes) |
199 | */ | | 199 | */ |
200 | ATF_CHECK((unsigned char)buf[0] == 0x1); | | 200 | ATF_CHECK((unsigned char)buf[0] == 0x1); |
201 | ATF_CHECK(ftello(fp) == (off_t)0); | | 201 | ATF_CHECK(ftello(fp) == (off_t)0); |
202 | | | 202 | |
203 | /* | | 203 | /* |
204 | * The stream also maintains the size of the current buffer contents. | | 204 | * The stream also maintains the size of the current buffer contents. |
205 | * For modes r and r+ the size is set to the value given by the size argument. | | 205 | * For modes r and r+ the size is set to the value given by the size argument. |
206 | */ | | 206 | */ |
207 | #if !defined(__GLIBC__) | | 207 | #if !defined(__GLIBC__) |
208 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); | | 208 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); |
209 | ATF_CHECK(ftello(fp) == (off_t)sizeof(buf)); | | 209 | ATF_CHECK(ftello(fp) == (off_t)sizeof(buf)); |
210 | #endif | | 210 | #endif |
211 | ATF_CHECK(fclose(fp) == 0); | | 211 | ATF_CHECK(fclose(fp) == 0); |
212 | } | | 212 | } |
213 | } | | 213 | } |
214 | | | 214 | |
215 | ATF_TC(test03); | | 215 | ATF_TC(test03); |
216 | ATF_TC_HEAD(test03, tc) | | 216 | ATF_TC_HEAD(test03, tc) |
217 | { | | 217 | { |
218 | atf_tc_set_md_var(tc, "descr", "test03"); | | 218 | atf_tc_set_md_var(tc, "descr", "test03"); |
219 | } | | 219 | } |
220 | ATF_TC_BODY(test03, tc) | | 220 | ATF_TC_BODY(test03, tc) |
221 | { | | 221 | { |
222 | const char **p; | | 222 | const char **p; |
223 | char buf[BUFSIZ]; | | 223 | char buf[BUFSIZ]; |
224 | FILE *fp; | | 224 | FILE *fp; |
225 | | | 225 | |
226 | for (p = &mode_w[0]; *p != NULL; ++p) { | | 226 | for (p = &mode_w[0]; *p != NULL; ++p) { |
227 | | | 227 | |
228 | memset(&buf[0], 0x1, sizeof(buf)); | | 228 | memset(&buf[0], 0x1, sizeof(buf)); |
229 | fp = fmemopen(&buf[0], sizeof(buf), *p); | | 229 | fp = fmemopen(&buf[0], sizeof(buf), *p); |
230 | ATF_CHECK(fp != NULL); | | 230 | ATF_CHECK(fp != NULL); |
231 | | | 231 | |
232 | /* | | 232 | /* |
233 | * This position is initially set to either the beginning of the buffer | | 233 | * This position is initially set to either the beginning of the buffer |
234 | * (for r and w modes) | | 234 | * (for r and w modes) |
235 | */ | | 235 | */ |
236 | ATF_CHECK(buf[0] == '\0'); | | 236 | ATF_CHECK(buf[0] == '\0'); |
237 | ATF_CHECK(ftello(fp) == (off_t)0); | | 237 | ATF_CHECK(ftello(fp) == (off_t)0); |
238 | | | 238 | |
239 | /* | | 239 | /* |
240 | * For modes w and w+ the initial size is zero | | 240 | * For modes w and w+ the initial size is zero |
241 | */ | | 241 | */ |
242 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); | | 242 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); |
243 | ATF_CHECK(ftello(fp) == (off_t)0); | | 243 | ATF_CHECK(ftello(fp) == (off_t)0); |
244 | | | 244 | |
245 | ATF_CHECK(fclose(fp) == 0); | | 245 | ATF_CHECK(fclose(fp) == 0); |
246 | } | | 246 | } |
247 | } | | 247 | } |
248 | | | 248 | |
249 | ATF_TC(test04); | | 249 | ATF_TC(test04); |
250 | ATF_TC_HEAD(test04, tc) | | 250 | ATF_TC_HEAD(test04, tc) |
251 | { | | 251 | { |
252 | atf_tc_set_md_var(tc, "descr", "test04"); | | 252 | atf_tc_set_md_var(tc, "descr", "test04"); |
253 | } | | 253 | } |
254 | ATF_TC_BODY(test04, tc) | | 254 | ATF_TC_BODY(test04, tc) |
255 | { | | 255 | { |
256 | const char **p; | | 256 | const char **p; |
257 | char buf[BUFSIZ]; | | 257 | char buf[BUFSIZ]; |
258 | FILE *fp; | | 258 | FILE *fp; |
259 | | | 259 | |
260 | /* | | 260 | /* |
261 | * or to the first null byte in the buffer (for a modes) | | 261 | * or to the first null byte in the buffer (for a modes) |
262 | */ | | 262 | */ |
263 | for (p = &mode_a[0]; *p != NULL; ++p) { | | 263 | for (p = &mode_a[0]; *p != NULL; ++p) { |
264 | | | 264 | |
265 | memset(&buf[0], 0x1, sizeof(buf)); | | 265 | memset(&buf[0], 0x1, sizeof(buf)); |
266 | fp = fmemopen(&buf[0], sizeof(buf), *p); | | 266 | fp = fmemopen(&buf[0], sizeof(buf), *p); |
267 | ATF_CHECK(fp != NULL); | | 267 | ATF_CHECK(fp != NULL); |
268 | | | 268 | |
269 | ATF_CHECK((unsigned char)buf[0] == 0x1); | | 269 | ATF_CHECK((unsigned char)buf[0] == 0x1); |
270 | | | 270 | |
271 | /* If no null byte is found in append mode, | | 271 | /* If no null byte is found in append mode, |
272 | * the initial position is set to one byte after the end of the buffer. | | 272 | * the initial position is set to one byte after the end of the buffer. |
273 | */ | | 273 | */ |
274 | #if !defined(__GLIBC__) | | 274 | #if !defined(__GLIBC__) |
275 | ATF_CHECK(ftello(fp) == (off_t)sizeof(buf)); | | 275 | ATF_CHECK(ftello(fp) == (off_t)sizeof(buf)); |
276 | #endif | | 276 | #endif |
277 | | | 277 | |
278 | /* | | 278 | /* |
279 | * and for modes a and a+ the initial size is either the position of the | | 279 | * and for modes a and a+ the initial size is either the position of the |
280 | * first null byte in the buffer or the value of the size argument | | 280 | * first null byte in the buffer or the value of the size argument |
281 | * if no null byte is found. | | 281 | * if no null byte is found. |
282 | */ | | 282 | */ |
283 | #if !defined(__GLIBC__) | | 283 | #if !defined(__GLIBC__) |
284 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); | | 284 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); |
285 | ATF_CHECK(ftello(fp) == (off_t)sizeof(buf)); | | 285 | ATF_CHECK(ftello(fp) == (off_t)sizeof(buf)); |
286 | #endif | | 286 | #endif |
287 | | | 287 | |
288 | ATF_CHECK(fclose(fp) == 0); | | 288 | ATF_CHECK(fclose(fp) == 0); |
289 | } | | 289 | } |
290 | } | | 290 | } |
291 | | | 291 | |
292 | ATF_TC(test05); | | 292 | ATF_TC(test05); |
293 | ATF_TC_HEAD(test05, tc) | | 293 | ATF_TC_HEAD(test05, tc) |
294 | { | | 294 | { |
295 | atf_tc_set_md_var(tc, "descr", "test05"); | | 295 | atf_tc_set_md_var(tc, "descr", "test05"); |
296 | } | | 296 | } |
297 | ATF_TC_BODY(test05, tc) | | 297 | ATF_TC_BODY(test05, tc) |
298 | { | | 298 | { |
299 | const char **p; | | 299 | const char **p; |
300 | FILE *fp; | | 300 | FILE *fp; |
301 | char buf[BUFSIZ]; | | 301 | char buf[BUFSIZ]; |
302 | | | 302 | |
303 | for (p = &mode_rwa[0]; *p != NULL; ++p) { | | 303 | for (p = &mode_rwa[0]; *p != NULL; ++p) { |
304 | /* | | 304 | /* |
305 | * Otherwise, a null pointer shall be returned, and errno shall be set | | 305 | * Otherwise, a null pointer shall be returned, and errno shall be set |
306 | * to indicate the error. | | 306 | * to indicate the error. |
307 | */ | | 307 | */ |
308 | errno = 0; | | 308 | errno = 0; |
309 | fp = fmemopen(NULL, (size_t)0, *p); | | 309 | fp = fmemopen(NULL, (size_t)0, *p); |
310 | ATF_CHECK(fp == NULL); | | 310 | ATF_CHECK(fp == NULL); |
311 | ATF_CHECK(errno == EINVAL); | | 311 | ATF_CHECK(errno == EINVAL); |
312 | | | 312 | |
313 | errno = 0; | | 313 | errno = 0; |
314 | fp = fmemopen((void *)&buf[0], 0, *p); | | 314 | fp = fmemopen((void *)&buf[0], 0, *p); |
315 | ATF_CHECK(fp == NULL); | | 315 | ATF_CHECK(fp == NULL); |
316 | ATF_CHECK(errno == EINVAL); | | 316 | ATF_CHECK(errno == EINVAL); |
317 | } | | 317 | } |
318 | } | | 318 | } |
319 | | | 319 | |
320 | ATF_TC(test06); | | 320 | ATF_TC(test06); |
321 | ATF_TC_HEAD(test06, tc) | | 321 | ATF_TC_HEAD(test06, tc) |
322 | { | | 322 | { |
323 | atf_tc_set_md_var(tc, "descr", "test06"); | | 323 | atf_tc_set_md_var(tc, "descr", "test06"); |
324 | } | | 324 | } |
325 | ATF_TC_BODY(test06, tc) | | 325 | ATF_TC_BODY(test06, tc) |
326 | { | | 326 | { |
327 | const char **p; | | 327 | const char **p; |
328 | const char *mode[] = { "", " ", "???", NULL }; | | 328 | const char *mode[] = { "", " ", "???", NULL }; |
329 | FILE *fp; | | 329 | FILE *fp; |
330 | | | 330 | |
331 | for (p = &mode[0]; *p != NULL; ++p) { | | 331 | for (p = &mode[0]; *p != NULL; ++p) { |
332 | /* | | 332 | /* |
333 | * The value of the mode argument is not valid. | | 333 | * The value of the mode argument is not valid. |
334 | */ | | 334 | */ |
335 | fp = fmemopen(NULL, 1, *p); | | 335 | fp = fmemopen(NULL, 1, *p); |
336 | ATF_CHECK(fp == NULL); | | 336 | ATF_CHECK(fp == NULL); |
337 | ATF_CHECK(errno == EINVAL); | | 337 | ATF_CHECK(errno == EINVAL); |
338 | } | | 338 | } |
339 | } | | 339 | } |
340 | | | 340 | |
341 | ATF_TC(test07); | | 341 | ATF_TC(test07); |
342 | ATF_TC_HEAD(test07, tc) | | 342 | ATF_TC_HEAD(test07, tc) |
343 | { | | 343 | { |
344 | atf_tc_set_md_var(tc, "descr", "test07"); | | 344 | atf_tc_set_md_var(tc, "descr", "test07"); |
345 | } | | 345 | } |
346 | ATF_TC_BODY(test07, tc) | | 346 | ATF_TC_BODY(test07, tc) |
347 | { | | 347 | { |
348 | #if !defined(__GLIBC__) | | 348 | #if !defined(__GLIBC__) |
349 | const char **p; | | 349 | const char **p; |
350 | const char *mode[] = { | | 350 | const char *mode[] = { |
351 | "r", "rb", | | 351 | "r", "rb", |
352 | "w", "wb", | | 352 | "w", "wb", |
353 | "a", "ab", | | 353 | "a", "ab", |
354 | NULL | | 354 | NULL |
355 | }; | | 355 | }; |
356 | FILE *fp; | | 356 | FILE *fp; |
357 | | | 357 | |
358 | for (p = &mode[0]; *p != NULL; ++p) { | | 358 | for (p = &mode[0]; *p != NULL; ++p) { |
359 | /* | | 359 | /* |
360 | * Because this feature is only useful when the stream is opened for updating | | 360 | * Because this feature is only useful when the stream is opened for updating |
361 | * (because there is no way to get a pointer to the buffer) the fmemopen() | | 361 | * (because there is no way to get a pointer to the buffer) the fmemopen() |
362 | * call may fail if the mode argument does not include a '+' . | | 362 | * call may fail if the mode argument does not include a '+' . |
363 | */ | | 363 | */ |
364 | errno = 0; | | 364 | errno = 0; |
365 | fp = fmemopen(NULL, 1, *p); | | 365 | fp = fmemopen(NULL, 1, *p); |
366 | ATF_CHECK(fp == NULL); | | 366 | ATF_CHECK(fp == NULL); |
367 | ATF_CHECK(errno == EINVAL); | | 367 | ATF_CHECK(errno == EINVAL); |
368 | } | | 368 | } |
369 | #endif | | 369 | #endif |
370 | } | | 370 | } |
371 | | | 371 | |
372 | ATF_TC(test08); | | 372 | ATF_TC(test08); |
373 | ATF_TC_HEAD(test08, tc) | | 373 | ATF_TC_HEAD(test08, tc) |
374 | { | | 374 | { |
375 | atf_tc_set_md_var(tc, "descr", "test08"); | | 375 | atf_tc_set_md_var(tc, "descr", "test08"); |
376 | } | | 376 | } |
377 | ATF_TC_BODY(test08, tc) | | 377 | ATF_TC_BODY(test08, tc) |
378 | { | | 378 | { |
379 | #if !defined(__GLIBC__) | | 379 | #if !defined(__GLIBC__) |
380 | const char **p; | | 380 | const char **p; |
381 | const char *mode[] = { | | 381 | const char *mode[] = { |
382 | "r+", "rb+", "r+b", | | 382 | "r+", "rb+", "r+b", |
383 | "w+", "wb+", "w+b", | | 383 | "w+", "wb+", "w+b", |
384 | "a+", "ab+", "a+b", | | 384 | "a+", "ab+", "a+b", |
385 | NULL | | 385 | NULL |
386 | }; | | 386 | }; |
387 | FILE *fp; | | 387 | FILE *fp; |
388 | | | 388 | |
389 | for (p = &mode[0]; *p != NULL; ++p) { | | 389 | for (p = &mode[0]; *p != NULL; ++p) { |
390 | /* | | 390 | /* |
391 | * The buf argument is a null pointer and the allocation of a buffer of | | 391 | * The buf argument is a null pointer and the allocation of a buffer of |
392 | * length size has failed. | | 392 | * length size has failed. |
393 | */ | | 393 | */ |
394 | fp = fmemopen(NULL, SIZE_MAX, *p); | | 394 | fp = fmemopen(NULL, SIZE_MAX, *p); |
395 | ATF_CHECK(fp == NULL); | | 395 | ATF_CHECK(fp == NULL); |
396 | ATF_CHECK(errno == ENOMEM); | | 396 | ATF_CHECK(errno == ENOMEM); |
397 | } | | 397 | } |
398 | #endif | | 398 | #endif |
399 | } | | 399 | } |
400 | | | 400 | |
401 | /* | | 401 | /* |
402 | * test09 - test14: | | 402 | * test09 - test14: |
403 | * An attempt to seek a memory buffer stream to a negative position or to a | | 403 | * An attempt to seek a memory buffer stream to a negative position or to a |
404 | * position larger than the buffer size given in the size argument shall fail. | | 404 | * position larger than the buffer size given in the size argument shall fail. |
405 | */ | | 405 | */ |
406 | | | 406 | |
407 | ATF_TC(test09); | | 407 | ATF_TC(test09); |
408 | ATF_TC_HEAD(test09, tc) | | 408 | ATF_TC_HEAD(test09, tc) |
409 | { | | 409 | { |
410 | atf_tc_set_md_var(tc, "descr", "test09"); | | 410 | atf_tc_set_md_var(tc, "descr", "test09"); |
411 | } | | 411 | } |
412 | ATF_TC_BODY(test09, tc) | | 412 | ATF_TC_BODY(test09, tc) |
413 | { | | 413 | { |
414 | struct testcase *t; | | 414 | struct testcase *t; |
415 | const char **p; | | 415 | const char **p; |
416 | char buf[BUFSIZ]; | | 416 | char buf[BUFSIZ]; |
417 | FILE *fp; | | 417 | FILE *fp; |
418 | off_t i; | | 418 | off_t i; |
419 | | | 419 | |
420 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 420 | for (t = &testcases[0]; t->s != NULL; ++t) { |
421 | for (p = &mode_rwa[0]; *p != NULL; ++p) { | | 421 | for (p = &mode_rwa[0]; *p != NULL; ++p) { |
422 | | | 422 | |
423 | memcpy(&buf[0], t->s, t->n); | | 423 | memcpy(&buf[0], t->s, t->n); |
424 | fp = fmemopen(&buf[0], t->n, *p); | | 424 | fp = fmemopen(&buf[0], t->n, *p); |
425 | ATF_CHECK(fp != NULL); | | 425 | ATF_CHECK(fp != NULL); |
426 | | | 426 | |
427 | /* | | 427 | /* |
428 | * test fmemopen_seek(SEEK_SET) | | 428 | * test fmemopen_seek(SEEK_SET) |
429 | */ | | 429 | */ |
430 | /* zero */ | | 430 | /* zero */ |
431 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_SET) == 0); | | 431 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_SET) == 0); |
432 | ATF_CHECK(ftello(fp) == (off_t)0); | | 432 | ATF_CHECK(ftello(fp) == (off_t)0); |
433 | | | 433 | |
434 | /* positive */ | | 434 | /* positive */ |
435 | for (i = (off_t)1; i <= (off_t)t->n; ++i) { | | 435 | for (i = (off_t)1; i <= (off_t)t->n; ++i) { |
436 | ATF_CHECK(fseeko(fp, i, SEEK_SET) == 0); | | 436 | ATF_CHECK(fseeko(fp, i, SEEK_SET) == 0); |
437 | ATF_CHECK(ftello(fp) == i); | | 437 | ATF_CHECK(ftello(fp) == i); |
438 | } | | 438 | } |
439 | /* positive + OOB */ | | 439 | /* positive + OOB */ |
440 | ATF_CHECK(fseeko(fp, t->n + 1, SEEK_SET) == -1); | | 440 | ATF_CHECK(fseeko(fp, t->n + 1, SEEK_SET) == -1); |
441 | ATF_CHECK(ftello(fp) == t->n); | | 441 | ATF_CHECK(ftello(fp) == t->n); |
442 | | | 442 | |
443 | /* negative + OOB */ | | 443 | /* negative + OOB */ |
444 | ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_SET) == -1); | | 444 | ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_SET) == -1); |
445 | ATF_CHECK(ftello(fp) == t->n); | | 445 | ATF_CHECK(ftello(fp) == t->n); |
446 | | | 446 | |
447 | ATF_CHECK(fclose(fp) == 0); | | 447 | ATF_CHECK(fclose(fp) == 0); |
448 | } | | 448 | } |
449 | } | | 449 | } |
450 | } | | 450 | } |
451 | | | 451 | |
452 | const char *mode_rw[] = { | | 452 | const char *mode_rw[] = { |
453 | "r", "rb", "r+", "rb+", "r+b", | | 453 | "r", "rb", "r+", "rb+", "r+b", |
454 | "w", "wb", "w+", "wb+", "w+b", | | 454 | "w", "wb", "w+", "wb+", "w+b", |
455 | NULL | | 455 | NULL |
456 | }; | | 456 | }; |
457 | | | 457 | |
458 | ATF_TC(test10); | | 458 | ATF_TC(test10); |
459 | ATF_TC_HEAD(test10, tc) | | 459 | ATF_TC_HEAD(test10, tc) |
460 | { | | 460 | { |
461 | atf_tc_set_md_var(tc, "descr", "test10"); | | 461 | atf_tc_set_md_var(tc, "descr", "test10"); |
462 | } | | 462 | } |
463 | ATF_TC_BODY(test10, tc) | | 463 | ATF_TC_BODY(test10, tc) |
464 | { | | 464 | { |
465 | struct testcase *t; | | 465 | struct testcase *t; |
466 | off_t i; | | 466 | off_t i; |
467 | const char **p; | | 467 | const char **p; |
468 | char buf[BUFSIZ]; | | 468 | char buf[BUFSIZ]; |
469 | FILE *fp; | | 469 | FILE *fp; |
470 | | | 470 | |
471 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 471 | for (t = &testcases[0]; t->s != NULL; ++t) { |
472 | for (p = &mode_rw[0]; *p != NULL; ++p) { | | 472 | for (p = &mode_rw[0]; *p != NULL; ++p) { |
473 | | | 473 | |
474 | memcpy(&buf[0], t->s, t->n); | | 474 | memcpy(&buf[0], t->s, t->n); |
475 | fp = fmemopen(&buf[0], t->n, *p); | | 475 | fp = fmemopen(&buf[0], t->n, *p); |
476 | ATF_CHECK(fp != NULL); | | 476 | ATF_CHECK(fp != NULL); |
477 | | | 477 | |
478 | /* | | 478 | /* |
479 | * test fmemopen_seek(SEEK_CUR) | | 479 | * test fmemopen_seek(SEEK_CUR) |
480 | */ | | 480 | */ |
481 | ATF_CHECK(ftello(fp) == (off_t)0); | | 481 | ATF_CHECK(ftello(fp) == (off_t)0); |
482 | | | 482 | |
483 | /* zero */ | | 483 | /* zero */ |
484 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_CUR) == 0); | | 484 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_CUR) == 0); |
485 | ATF_CHECK(ftello(fp) == (off_t)0); | | 485 | ATF_CHECK(ftello(fp) == (off_t)0); |
486 | | | 486 | |
487 | /* negative & OOB */ | | 487 | /* negative & OOB */ |
488 | ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == -1); | | 488 | ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == -1); |
489 | ATF_CHECK(ftello(fp) == (off_t)0); | | 489 | ATF_CHECK(ftello(fp) == (off_t)0); |
490 | | | 490 | |
491 | /* positive */ | | 491 | /* positive */ |
492 | for (i = 0; i < (off_t)t->n; ++i) { | | 492 | for (i = 0; i < (off_t)t->n; ++i) { |
493 | ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == 0); | | 493 | ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == 0); |
494 | ATF_CHECK(ftello(fp) == i + 1); | | 494 | ATF_CHECK(ftello(fp) == i + 1); |
495 | } | | 495 | } |
496 | | | 496 | |
497 | /* positive & OOB */ | | 497 | /* positive & OOB */ |
498 | ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == -1); | | 498 | ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == -1); |
499 | ATF_CHECK(ftello(fp) == (off_t)t->n); | | 499 | ATF_CHECK(ftello(fp) == (off_t)t->n); |
500 | | | 500 | |
501 | ATF_CHECK(fclose(fp) == 0); | | 501 | ATF_CHECK(fclose(fp) == 0); |
502 | } | | 502 | } |
503 | } | | 503 | } |
504 | } | | 504 | } |
505 | | | 505 | |
506 | ATF_TC(test11); | | 506 | ATF_TC(test11); |
507 | ATF_TC_HEAD(test11, tc) | | 507 | ATF_TC_HEAD(test11, tc) |
508 | { | | 508 | { |
509 | atf_tc_set_md_var(tc, "descr", "test11"); | | 509 | atf_tc_set_md_var(tc, "descr", "test11"); |
510 | } | | 510 | } |
511 | ATF_TC_BODY(test11, tc) | | 511 | ATF_TC_BODY(test11, tc) |
512 | { | | 512 | { |
513 | struct testcase *t; | | 513 | struct testcase *t; |
514 | off_t len, rest, i; | | 514 | off_t len, rest, i; |
515 | const char **p; | | 515 | const char **p; |
516 | char buf[BUFSIZ]; | | 516 | char buf[BUFSIZ]; |
517 | FILE *fp; | | 517 | FILE *fp; |
518 | | | 518 | |
519 | /* test fmemopen_seek(SEEK_CUR) */ | | 519 | /* test fmemopen_seek(SEEK_CUR) */ |
520 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 520 | for (t = &testcases[0]; t->s != NULL; ++t) { |
521 | len = (off_t)strnlen(t->s, t->n); | | 521 | len = (off_t)strnlen(t->s, t->n); |
522 | rest = (off_t)t->n - len; | | 522 | rest = (off_t)t->n - len; |
523 | for (p = &mode_a[0]; *p != NULL; ++p) { | | 523 | for (p = &mode_a[0]; *p != NULL; ++p) { |
524 | | | 524 | |
525 | memcpy(&buf[0], t->s, t->n); | | 525 | memcpy(&buf[0], t->s, t->n); |
526 | fp = fmemopen(&buf[0], t->n, *p); | | 526 | fp = fmemopen(&buf[0], t->n, *p); |
527 | ATF_CHECK(fp != NULL); | | 527 | ATF_CHECK(fp != NULL); |
528 | /* | | 528 | /* |
529 | * test fmemopen_seek(SEEK_CUR) | | 529 | * test fmemopen_seek(SEEK_CUR) |
530 | */ | | 530 | */ |
531 | #if defined(__GLIBC__) | | 531 | #if defined(__GLIBC__) |
532 | if (i < (off_t)t->n) { | | 532 | if (i < (off_t)t->n) { |
533 | #endif | | 533 | #endif |
534 | /* zero */ | | 534 | /* zero */ |
535 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_CUR) == 0); | | 535 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_CUR) == 0); |
536 | ATF_CHECK(ftello(fp) == len); | | 536 | ATF_CHECK(ftello(fp) == len); |
537 | | | 537 | |
538 | /* posive */ | | 538 | /* posive */ |
539 | for (i = (off_t)1; i <= rest; ++i) { | | 539 | for (i = (off_t)1; i <= rest; ++i) { |
540 | ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == 0); | | 540 | ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == 0); |
541 | ATF_CHECK(ftello(fp) == len + i); | | 541 | ATF_CHECK(ftello(fp) == len + i); |
542 | } | | 542 | } |
543 | | | 543 | |
544 | /* positive + OOB */ | | 544 | /* positive + OOB */ |
545 | ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == -1); | | 545 | ATF_CHECK(fseeko(fp, (off_t)1, SEEK_CUR) == -1); |
546 | ATF_CHECK(ftello(fp) == (off_t)t->n); | | 546 | ATF_CHECK(ftello(fp) == (off_t)t->n); |
547 | | | 547 | |
548 | /* negative */ | | 548 | /* negative */ |
549 | for (i = (off_t)1; i <= (off_t)t->n; ++i) { | | 549 | for (i = (off_t)1; i <= (off_t)t->n; ++i) { |
550 | ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == 0); | | 550 | ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == 0); |
551 | ATF_CHECK(ftello(fp) == (off_t)t->n - i); | | 551 | ATF_CHECK(ftello(fp) == (off_t)t->n - i); |
552 | } | | 552 | } |
553 | | | 553 | |
554 | /* negative + OOB */ | | 554 | /* negative + OOB */ |
555 | ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == -1); | | 555 | ATF_CHECK(fseeko(fp, (off_t)-1, SEEK_CUR) == -1); |
556 | ATF_CHECK(ftello(fp) == (off_t)0); | | 556 | ATF_CHECK(ftello(fp) == (off_t)0); |
557 | | | 557 | |
558 | #if defined(__GLIBC__) | | 558 | #if defined(__GLIBC__) |
559 | } | | 559 | } |
560 | #endif | | 560 | #endif |
561 | ATF_CHECK(fclose(fp) == 0); | | 561 | ATF_CHECK(fclose(fp) == 0); |
562 | } | | 562 | } |
563 | } | | 563 | } |
564 | } | | 564 | } |
565 | | | 565 | |
566 | ATF_TC(test12); | | 566 | ATF_TC(test12); |
567 | ATF_TC_HEAD(test12, tc) | | 567 | ATF_TC_HEAD(test12, tc) |
568 | { | | 568 | { |
569 | atf_tc_set_md_var(tc, "descr", "test12"); | | 569 | atf_tc_set_md_var(tc, "descr", "test12"); |
570 | } | | 570 | } |
571 | ATF_TC_BODY(test12, tc) | | 571 | ATF_TC_BODY(test12, tc) |
572 | { | | 572 | { |
573 | struct testcase *t; | | 573 | struct testcase *t; |
574 | off_t len, rest, i; | | 574 | off_t len, rest, i; |
575 | const char **p; | | 575 | const char **p; |
576 | char buf[BUFSIZ]; | | 576 | char buf[BUFSIZ]; |
577 | FILE *fp; | | 577 | FILE *fp; |
578 | | | 578 | |
579 | /* test fmemopen_seek(SEEK_END) */ | | 579 | /* test fmemopen_seek(SEEK_END) */ |
580 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 580 | for (t = &testcases[0]; t->s != NULL; ++t) { |
581 | len = (off_t)strnlen(t->s, t->n); | | 581 | len = (off_t)strnlen(t->s, t->n); |
582 | rest = t->n - len; | | 582 | rest = t->n - len; |
583 | for (p = &mode_r[0]; *p != NULL; ++p) { | | 583 | for (p = &mode_r[0]; *p != NULL; ++p) { |
584 | | | 584 | |
585 | memcpy(buf, t->s, t->n); | | 585 | memcpy(buf, t->s, t->n); |
586 | fp = fmemopen(&buf[0], t->n, *p); | | 586 | fp = fmemopen(&buf[0], t->n, *p); |
587 | ATF_CHECK(fp != NULL); | | 587 | ATF_CHECK(fp != NULL); |
588 | | | 588 | |
589 | /* | | 589 | /* |
590 | * test fmemopen_seek(SEEK_END) | | 590 | * test fmemopen_seek(SEEK_END) |
591 | */ | | 591 | */ |
592 | #if !defined(__GLIBC__) | | 592 | #if !defined(__GLIBC__) |
593 | ATF_CHECK(ftello(fp) == (off_t)0); | | 593 | ATF_CHECK(ftello(fp) == (off_t)0); |
594 | | | 594 | |
595 | /* zero */ | | 595 | /* zero */ |
596 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); | | 596 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); |
597 | ATF_CHECK(ftello(fp) == len); | | 597 | ATF_CHECK(ftello(fp) == len); |
598 | | | 598 | |
599 | /* positive + OOB */ | | 599 | /* positive + OOB */ |
600 | ATF_CHECK(fseeko(fp, rest + 1, SEEK_END) == -1); | | 600 | ATF_CHECK(fseeko(fp, rest + 1, SEEK_END) == -1); |
601 | ATF_CHECK(ftello(fp) == len); | | 601 | ATF_CHECK(ftello(fp) == len); |
602 | | | 602 | |
603 | /* negative + OOB */ | | 603 | /* negative + OOB */ |
604 | ATF_CHECK(fseeko(fp, -(len + 1), SEEK_END) == -1); | | 604 | ATF_CHECK(fseeko(fp, -(len + 1), SEEK_END) == -1); |
605 | ATF_CHECK(ftello(fp) == len); | | 605 | ATF_CHECK(ftello(fp) == len); |
606 | | | 606 | |
607 | /* positive */ | | 607 | /* positive */ |
608 | for (i = 1; i <= rest; ++i) { | | 608 | for (i = 1; i <= rest; ++i) { |
609 | ATF_CHECK(fseeko(fp, i, SEEK_END) == 0); | | 609 | ATF_CHECK(fseeko(fp, i, SEEK_END) == 0); |
610 | ATF_CHECK(ftello(fp) == len + i); | | 610 | ATF_CHECK(ftello(fp) == len + i); |
611 | } | | 611 | } |
612 | | | 612 | |
613 | /* negative */ | | 613 | /* negative */ |
614 | for (i = 1; i < len; ++i) { | | 614 | for (i = 1; i < len; ++i) { |
615 | ATF_CHECK(fseeko(fp, -i, SEEK_END) == 0); | | 615 | ATF_CHECK(fseeko(fp, -i, SEEK_END) == 0); |
616 | ATF_CHECK(ftello(fp) == len - i); | | 616 | ATF_CHECK(ftello(fp) == len - i); |
617 | } | | 617 | } |
618 | #endif | | 618 | #endif |
619 | ATF_CHECK(fclose(fp) == 0); | | 619 | ATF_CHECK(fclose(fp) == 0); |
620 | } | | 620 | } |
621 | } | | 621 | } |
622 | } | | 622 | } |
623 | | | 623 | |
624 | ATF_TC(test13); | | 624 | ATF_TC(test13); |
625 | ATF_TC_HEAD(test13, tc) | | 625 | ATF_TC_HEAD(test13, tc) |
626 | { | | 626 | { |
627 | atf_tc_set_md_var(tc, "descr", "test13"); | | 627 | atf_tc_set_md_var(tc, "descr", "test13"); |
628 | } | | 628 | } |
629 | ATF_TC_BODY(test13, tc) | | 629 | ATF_TC_BODY(test13, tc) |
630 | { | | 630 | { |
631 | struct testcase *t; | | 631 | struct testcase *t; |
632 | off_t i; | | 632 | off_t i; |
633 | const char **p; | | 633 | const char **p; |
634 | char buf[BUFSIZ]; | | 634 | char buf[BUFSIZ]; |
635 | FILE *fp; | | 635 | FILE *fp; |
636 | | | 636 | |
637 | /* test fmemopen_seek(SEEK_END) */ | | 637 | /* test fmemopen_seek(SEEK_END) */ |
638 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 638 | for (t = &testcases[0]; t->s != NULL; ++t) { |
639 | for (p = &mode_w[0]; *p != NULL; ++p) { | | 639 | for (p = &mode_w[0]; *p != NULL; ++p) { |
640 | | | 640 | |
641 | memcpy(buf, t->s, t->n); | | 641 | memcpy(buf, t->s, t->n); |
642 | fp = fmemopen(&buf[0], t->n, *p); | | 642 | fp = fmemopen(&buf[0], t->n, *p); |
643 | ATF_CHECK(fp != NULL); | | 643 | ATF_CHECK(fp != NULL); |
644 | /* | | 644 | /* |
645 | * test fmemopen_seek(SEEK_END) | | 645 | * test fmemopen_seek(SEEK_END) |
646 | */ | | 646 | */ |
647 | #if !defined(__GLIBC__) | | 647 | #if !defined(__GLIBC__) |
648 | ATF_CHECK(ftello(fp) == (off_t)0); | | 648 | ATF_CHECK(ftello(fp) == (off_t)0); |
649 | ATF_CHECK(buf[0] == '\0'); | | 649 | ATF_CHECK(buf[0] == '\0'); |
650 | | | 650 | |
651 | /* zero */ | | 651 | /* zero */ |
652 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); | | 652 | ATF_CHECK(fseeko(fp, (off_t)0, SEEK_END) == 0); |
653 | ATF_CHECK(ftello(fp) == (off_t)0); | | 653 | ATF_CHECK(ftello(fp) == (off_t)0); |
654 | | | 654 | |
655 | /* positive + OOB */ | | 655 | /* positive + OOB */ |
656 | ATF_CHECK(fseeko(fp, (off_t)t->n + 1, SEEK_END) == -1); | | 656 | ATF_CHECK(fseeko(fp, (off_t)t->n + 1, SEEK_END) == -1); |
657 | ATF_CHECK(ftello(fp) == (off_t)0); | | 657 | ATF_CHECK(ftello(fp) == (off_t)0); |
658 | | | 658 | |
659 | /* negative + OOB */ | | 659 | /* negative + OOB */ |
660 | ATF_CHECK(fseeko(fp, -1, SEEK_END) == -1); | | 660 | ATF_CHECK(fseeko(fp, -1, SEEK_END) == -1); |
661 | ATF_CHECK(ftello(fp) == (off_t)0); | | 661 | ATF_CHECK(ftello(fp) == (off_t)0); |
662 | | | 662 | |
663 | /* positive */ | | 663 | /* positive */ |
664 | for (i = 1; i <= t->n; ++i) { | | 664 | for (i = 1; i <= t->n; ++i) { |
665 | ATF_CHECK(fseeko(fp, i, SEEK_END) == 0); | | 665 | ATF_CHECK(fseeko(fp, i, SEEK_END) == 0); |
666 | ATF_CHECK(ftello(fp) == i); | | 666 | ATF_CHECK(ftello(fp) == i); |
667 | } | | 667 | } |
668 | #endif | | 668 | #endif |
669 | ATF_CHECK(fclose(fp) == 0); | | 669 | ATF_CHECK(fclose(fp) == 0); |
670 | } | | 670 | } |
671 | } | | 671 | } |
672 | } | | 672 | } |
673 | | | 673 | |
674 | ATF_TC(test14); | | 674 | ATF_TC(test14); |
675 | ATF_TC_HEAD(test14, tc) | | 675 | ATF_TC_HEAD(test14, tc) |
676 | { | | 676 | { |
677 | atf_tc_set_md_var(tc, "descr", "test14"); | | 677 | atf_tc_set_md_var(tc, "descr", "test14"); |
678 | } | | 678 | } |
679 | ATF_TC_BODY(test14, tc) | | 679 | ATF_TC_BODY(test14, tc) |
680 | { | | 680 | { |
681 | struct testcase *t; | | 681 | struct testcase *t; |
682 | off_t len, rest, i; | | 682 | off_t len, rest, i; |
683 | const char **p; | | 683 | const char **p; |
684 | char buf[BUFSIZ]; | | 684 | char buf[BUFSIZ]; |
685 | FILE *fp; | | 685 | FILE *fp; |
686 | | | 686 | |
687 | /* test fmemopen_seek(SEEK_END) */ | | 687 | /* test fmemopen_seek(SEEK_END) */ |
688 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 688 | for (t = &testcases[0]; t->s != NULL; ++t) { |
689 | len = (off_t)strnlen(t->s, t->n); | | 689 | len = (off_t)strnlen(t->s, t->n); |
690 | rest = (off_t)t->n - len; | | 690 | rest = (off_t)t->n - len; |
691 | for (p = &mode_a[0]; *p != NULL; ++p) { | | 691 | for (p = &mode_a[0]; *p != NULL; ++p) { |
692 | | | 692 | |
693 | memcpy(buf, t->s, t->n); | | 693 | memcpy(buf, t->s, t->n); |
694 | fp = fmemopen(&buf[0], t->n, *p); | | 694 | fp = fmemopen(&buf[0], t->n, *p); |
695 | ATF_CHECK(fp != NULL); | | 695 | ATF_CHECK(fp != NULL); |
696 | /* | | 696 | /* |
697 | * test fmemopen_seek(SEEK_END) | | 697 | * test fmemopen_seek(SEEK_END) |
698 | */ | | 698 | */ |
699 | #if !defined(__GLIBC__) | | 699 | #if !defined(__GLIBC__) |
700 | ATF_CHECK(ftello(fp) == len); | | 700 | ATF_CHECK(ftello(fp) == len); |
701 | | | 701 | |
702 | /* zero */ | | 702 | /* zero */ |
703 | ATF_CHECK(fseeko(fp, 0, SEEK_END) == 0); | | 703 | ATF_CHECK(fseeko(fp, 0, SEEK_END) == 0); |
704 | ATF_CHECK(ftello(fp) == len); | | 704 | ATF_CHECK(ftello(fp) == len); |
705 | | | 705 | |
706 | /* positive + OOB */ | | 706 | /* positive + OOB */ |
707 | ATF_CHECK(fseeko(fp, rest + 1, SEEK_END) == -1); | | 707 | ATF_CHECK(fseeko(fp, rest + 1, SEEK_END) == -1); |
708 | ATF_CHECK(ftello(fp) == len); | | 708 | ATF_CHECK(ftello(fp) == len); |
709 | | | 709 | |
710 | /* negative + OOB */ | | 710 | /* negative + OOB */ |
711 | ATF_CHECK(fseeko(fp, -(len + 1), SEEK_END) == -1); | | 711 | ATF_CHECK(fseeko(fp, -(len + 1), SEEK_END) == -1); |
712 | ATF_CHECK(ftello(fp) == len); | | 712 | ATF_CHECK(ftello(fp) == len); |
713 | | | 713 | |
714 | /* positive */ | | 714 | /* positive */ |
715 | for (i = 1; i <= rest; ++i) { | | 715 | for (i = 1; i <= rest; ++i) { |
716 | ATF_CHECK(fseeko(fp, i, SEEK_END) == 0); | | 716 | ATF_CHECK(fseeko(fp, i, SEEK_END) == 0); |
717 | ATF_CHECK(ftello(fp) == len + i); | | 717 | ATF_CHECK(ftello(fp) == len + i); |
718 | } | | 718 | } |
719 | | | 719 | |
720 | /* negative */ | | 720 | /* negative */ |
721 | for (i = 1; i < len; ++i) { | | 721 | for (i = 1; i < len; ++i) { |
722 | ATF_CHECK(fseeko(fp, -i, SEEK_END) == 0); | | 722 | ATF_CHECK(fseeko(fp, -i, SEEK_END) == 0); |
723 | ATF_CHECK(ftello(fp) == len - i); | | 723 | ATF_CHECK(ftello(fp) == len - i); |
724 | } | | 724 | } |
725 | #endif | | 725 | #endif |
726 | ATF_CHECK(fclose(fp) == 0); | | 726 | ATF_CHECK(fclose(fp) == 0); |
727 | } | | 727 | } |
728 | } | | 728 | } |
729 | } | | 729 | } |
730 | | | 730 | |
731 | const char *mode_rw1[] = { | | 731 | const char *mode_rw1[] = { |
732 | "r", "rb", "r+", "rb+", "r+b", | | 732 | "r", "rb", "r+", "rb+", "r+b", |
733 | "w+", "wb+", | | 733 | "w+", "wb+", |
734 | NULL | | 734 | NULL |
735 | }; | | 735 | }; |
736 | | | 736 | |
737 | /* test15 - 18: | | 737 | /* test15 - 18: |
738 | * When a stream open for writing is flushed or closed, a null byte is written | | 738 | * When a stream open for writing is flushed or closed, a null byte is written |
739 | * at the current position or at the end of the buffer, depending on the size | | 739 | * at the current position or at the end of the buffer, depending on the size |
740 | * of the contents. | | 740 | * of the contents. |
741 | */ | | 741 | */ |
742 | | | 742 | |
743 | ATF_TC(test15); | | 743 | ATF_TC(test15); |
744 | ATF_TC_HEAD(test15, tc) | | 744 | ATF_TC_HEAD(test15, tc) |
745 | { | | 745 | { |
746 | atf_tc_set_md_var(tc, "descr", "test15"); | | 746 | atf_tc_set_md_var(tc, "descr", "test15"); |
747 | } | | 747 | } |
748 | ATF_TC_BODY(test15, tc) | | 748 | ATF_TC_BODY(test15, tc) |
749 | { | | 749 | { |
750 | struct testcase *t; | | 750 | struct testcase *t; |
751 | const char **p; | | 751 | const char **p; |
752 | char buf0[BUFSIZ]; | | 752 | char buf0[BUFSIZ]; |
753 | FILE *fp; | | 753 | FILE *fp; |
754 | int i; | | 754 | int i; |
755 | | | 755 | |
756 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 756 | for (t = &testcases[0]; t->s != NULL; ++t) { |
757 | for (p = &mode_rw1[0]; *p != NULL; ++p) { | | 757 | for (p = &mode_rw1[0]; *p != NULL; ++p) { |
758 | | | 758 | |
759 | memcpy(&buf0[0], t->s, t->n); | | 759 | memcpy(&buf0[0], t->s, t->n); |
760 | fp = fmemopen(&buf0[0], t->n, *p); | | 760 | fp = fmemopen(&buf0[0], t->n, *p); |
761 | ATF_CHECK(fp != NULL); | | 761 | ATF_CHECK(fp != NULL); |
762 | /* | | 762 | /* |
763 | * test fmemopen_read + fgetc(3) | | 763 | * test fmemopen_read + fgetc(3) |
764 | */ | | 764 | */ |
765 | for (i = 0; i < t->n; ++i) { | | 765 | for (i = 0; i < t->n; ++i) { |
766 | ATF_CHECK(ftello(fp) == (off_t)i); | | 766 | ATF_CHECK(ftello(fp) == (off_t)i); |
767 | ATF_CHECK(fgetc(fp) == buf0[i]); | | 767 | ATF_CHECK(fgetc(fp) == buf0[i]); |
768 | ATF_CHECK(feof(fp) == 0); | | 768 | ATF_CHECK(feof(fp) == 0); |
769 | ATF_CHECK(ftello(fp) == (off_t)i + 1); | | 769 | ATF_CHECK(ftello(fp) == (off_t)i + 1); |
770 | } | | 770 | } |
771 | ATF_CHECK(fgetc(fp) == EOF); | | 771 | ATF_CHECK(fgetc(fp) == EOF); |
772 | ATF_CHECK(feof(fp) != 0); | | 772 | ATF_CHECK(feof(fp) != 0); |
773 | ATF_CHECK(ftello(fp) == (off_t)t->n); | | 773 | ATF_CHECK(ftello(fp) == (off_t)t->n); |
774 | ATF_CHECK(fclose(fp) == 0); | | 774 | ATF_CHECK(fclose(fp) == 0); |
775 | } | | 775 | } |
776 | } | | 776 | } |
777 | } | | 777 | } |
778 | | | 778 | |
779 | ATF_TC(test16); | | 779 | ATF_TC(test16); |
780 | ATF_TC_HEAD(test16, tc) | | 780 | ATF_TC_HEAD(test16, tc) |
781 | { | | 781 | { |
782 | atf_tc_set_md_var(tc, "descr", "test16"); | | 782 | atf_tc_set_md_var(tc, "descr", "test16"); |
783 | } | | 783 | } |
784 | ATF_TC_BODY(test16, tc) | | 784 | ATF_TC_BODY(test16, tc) |
785 | { | | 785 | { |
786 | struct testcase *t; | | 786 | struct testcase *t; |
787 | const char **p; | | 787 | const char **p; |
788 | char buf0[BUFSIZ], buf1[BUFSIZ]; | | 788 | char buf0[BUFSIZ], buf1[BUFSIZ]; |
789 | FILE *fp; | | 789 | FILE *fp; |
790 | | | 790 | |
791 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 791 | for (t = &testcases[0]; t->s != NULL; ++t) { |
792 | for (p = &mode_rw1[0]; *p != NULL; ++p) { | | 792 | for (p = &mode_rw1[0]; *p != NULL; ++p) { |
793 | | | 793 | |
794 | memcpy(&buf0[0], t->s, t->n); | | 794 | memcpy(&buf0[0], t->s, t->n); |
795 | buf1[t->n] = 0x1; | | 795 | buf1[t->n] = 0x1; |
796 | fp = fmemopen(&buf0[0], t->n, *p); | | 796 | fp = fmemopen(&buf0[0], t->n, *p); |
797 | ATF_CHECK(fp != NULL); | | 797 | ATF_CHECK(fp != NULL); |
798 | /* | | 798 | /* |
799 | * test fmemopen_read + fread(4) | | 799 | * test fmemopen_read + fread(4) |
800 | */ | | 800 | */ |
801 | ATF_CHECK(ftello(fp) == (off_t)0); | | 801 | ATF_CHECK(ftello(fp) == (off_t)0); |
802 | ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp) == (size_t)t->n); | | 802 | ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp) == (size_t)t->n); |
803 | ATF_CHECK(feof(fp) != 0); | | 803 | ATF_CHECK(feof(fp) != 0); |
804 | ATF_CHECK(memcmp(&buf0[0], &buf1[0], t->n) == 0); | | 804 | ATF_CHECK(memcmp(&buf0[0], &buf1[0], t->n) == 0); |
805 | ATF_CHECK((unsigned char)buf1[t->n] == 0x1); | | 805 | ATF_CHECK((unsigned char)buf1[t->n] == 0x1); |
806 | | | 806 | |
807 | ATF_CHECK(fclose(fp) == 0); | | 807 | ATF_CHECK(fclose(fp) == 0); |
808 | } | | 808 | } |
809 | } | | 809 | } |
810 | } | | 810 | } |
811 | | | 811 | |
812 | const char *mode_a1[] = { "a+", "ab+", NULL }; | | 812 | const char *mode_a1[] = { "a+", "ab+", NULL }; |
813 | | | 813 | |
814 | ATF_TC(test17); | | 814 | ATF_TC(test17); |
815 | ATF_TC_HEAD(test17, tc) | | 815 | ATF_TC_HEAD(test17, tc) |
816 | { | | 816 | { |
817 | atf_tc_set_md_var(tc, "descr", "test17"); | | 817 | atf_tc_set_md_var(tc, "descr", "test17"); |
818 | } | | 818 | } |
819 | ATF_TC_BODY(test17, tc) | | 819 | ATF_TC_BODY(test17, tc) |
820 | { | | 820 | { |
821 | struct testcase *t; | | 821 | struct testcase *t; |
822 | size_t len; | | 822 | size_t len; |
823 | int i; | | 823 | int i; |
824 | const char **p; | | 824 | const char **p; |
825 | char buf[BUFSIZ]; | | 825 | char buf[BUFSIZ]; |
826 | FILE *fp; | | 826 | FILE *fp; |
827 | | | 827 | |
828 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 828 | for (t = &testcases[0]; t->s != NULL; ++t) { |
829 | len = strnlen(t->s, t->n); | | 829 | len = strnlen(t->s, t->n); |
830 | for (p = &mode_a1[0]; *p != NULL; ++p) { | | 830 | for (p = &mode_a1[0]; *p != NULL; ++p) { |
831 | | | 831 | |
832 | memcpy(&buf[0], t->s, t->n); | | 832 | memcpy(&buf[0], t->s, t->n); |
833 | fp = fmemopen(&buf[0], t->n, *p); | | 833 | fp = fmemopen(&buf[0], t->n, *p); |
834 | ATF_CHECK(fp != NULL); | | 834 | ATF_CHECK(fp != NULL); |
835 | /* | | 835 | /* |
836 | * test fmemopen_read + fgetc(3) | | 836 | * test fmemopen_read + fgetc(3) |
837 | */ | | 837 | */ |
838 | #if defined(__GLIBC__) | | 838 | #if defined(__GLIBC__) |
839 | if (i < t->n) { | | 839 | if (i < t->n) { |
840 | #endif | | 840 | #endif |
841 | for (i = len; i < t->n; ++i) { | | 841 | for (i = len; i < t->n; ++i) { |
842 | ATF_CHECK(ftello(fp) == (off_t)i); | | 842 | ATF_CHECK(ftello(fp) == (off_t)i); |
843 | ATF_CHECK(fgetc(fp) == buf[i]); | | 843 | ATF_CHECK(fgetc(fp) == buf[i]); |
844 | ATF_CHECK(feof(fp) == 0); | | 844 | ATF_CHECK(feof(fp) == 0); |
845 | ATF_CHECK(ftello(fp) == (off_t)i + 1); | | 845 | ATF_CHECK(ftello(fp) == (off_t)i + 1); |
846 | } | | 846 | } |
847 | ATF_CHECK(fgetc(fp) == EOF); | | 847 | ATF_CHECK(fgetc(fp) == EOF); |
848 | ATF_CHECK(feof(fp) != 0); | | 848 | ATF_CHECK(feof(fp) != 0); |
849 | ATF_CHECK(ftello(fp) == (off_t)t->n); | | 849 | ATF_CHECK(ftello(fp) == (off_t)t->n); |
850 | rewind(fp); | | 850 | rewind(fp); |
851 | for (i = 0; i < t->n; ++i) { | | 851 | for (i = 0; i < t->n; ++i) { |
852 | ATF_CHECK(ftello(fp) == (off_t)i); | | 852 | ATF_CHECK(ftello(fp) == (off_t)i); |
853 | ATF_CHECK(fgetc(fp) == buf[i]); | | 853 | ATF_CHECK(fgetc(fp) == buf[i]); |
854 | ATF_CHECK(feof(fp) == 0); | | 854 | ATF_CHECK(feof(fp) == 0); |
855 | ATF_CHECK(ftello(fp) == (off_t)i + 1); | | 855 | ATF_CHECK(ftello(fp) == (off_t)i + 1); |
856 | } | | 856 | } |
857 | ATF_CHECK(fgetc(fp) == EOF); | | 857 | ATF_CHECK(fgetc(fp) == EOF); |
858 | ATF_CHECK(feof(fp) != 0); | | 858 | ATF_CHECK(feof(fp) != 0); |
859 | ATF_CHECK(ftello(fp) == (off_t)t->n); | | 859 | ATF_CHECK(ftello(fp) == (off_t)t->n); |
860 | #if defined(__GLIBC__) | | 860 | #if defined(__GLIBC__) |
861 | } | | 861 | } |
862 | #endif | | 862 | #endif |
863 | ATF_CHECK(fclose(fp) == 0); | | 863 | ATF_CHECK(fclose(fp) == 0); |
864 | } | | 864 | } |
865 | } | | 865 | } |
866 | } | | 866 | } |
867 | | | 867 | |
868 | ATF_TC(test18); | | 868 | ATF_TC(test18); |
869 | ATF_TC_HEAD(test18, tc) | | 869 | ATF_TC_HEAD(test18, tc) |
870 | { | | 870 | { |
871 | atf_tc_set_md_var(tc, "descr", "test18"); | | 871 | atf_tc_set_md_var(tc, "descr", "test18"); |
872 | } | | 872 | } |
873 | ATF_TC_BODY(test18, tc) | | 873 | ATF_TC_BODY(test18, tc) |
874 | { | | 874 | { |
875 | struct testcase *t; | | 875 | struct testcase *t; |
876 | size_t len; | | 876 | size_t len; |
877 | const char **p; | | 877 | const char **p; |
878 | char buf0[BUFSIZ], buf1[BUFSIZ]; | | 878 | char buf0[BUFSIZ], buf1[BUFSIZ]; |
879 | FILE *fp; | | 879 | FILE *fp; |
880 | | | 880 | |
881 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 881 | for (t = &testcases[0]; t->s != NULL; ++t) { |
882 | len = strnlen(t->s, t->n); | | 882 | len = strnlen(t->s, t->n); |
883 | for (p = &mode_a1[0]; *p != NULL; ++p) { | | 883 | for (p = &mode_a1[0]; *p != NULL; ++p) { |
884 | | | 884 | |
885 | memcpy(&buf0[0], t->s, t->n); | | 885 | memcpy(&buf0[0], t->s, t->n); |
886 | buf1[t->n - len] = 0x1; | | 886 | buf1[t->n - len] = 0x1; |
887 | fp = fmemopen(&buf0[0], t->n, *p); | | 887 | fp = fmemopen(&buf0[0], t->n, *p); |
888 | ATF_CHECK(fp != NULL); | | 888 | ATF_CHECK(fp != NULL); |
889 | /* | | 889 | /* |
890 | * test fmemopen_read + fread(3) | | 890 | * test fmemopen_read + fread(3) |
891 | */ | | 891 | */ |
892 | #if defined(__GLIBC__) | | 892 | #if defined(__GLIBC__) |
893 | if (i < t->n) { | | 893 | if (i < t->n) { |
894 | #endif | | 894 | #endif |
895 | ATF_CHECK(ftello(fp) == (off_t)len); | | 895 | ATF_CHECK(ftello(fp) == (off_t)len); |
896 | ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp) | | 896 | ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp) |
897 | == t->n - len); | | 897 | == t->n - len); |
898 | ATF_CHECK(feof(fp) != 0); | | 898 | ATF_CHECK(feof(fp) != 0); |
899 | ATF_CHECK(!memcmp(&buf0[len], &buf1[0], t->n - len)); | | 899 | ATF_CHECK(!memcmp(&buf0[len], &buf1[0], t->n - len)); |
900 | ATF_CHECK((unsigned char)buf1[t->n - len] == 0x1); | | 900 | ATF_CHECK((unsigned char)buf1[t->n - len] == 0x1); |
901 | rewind(fp); | | 901 | rewind(fp); |
902 | buf1[t->n] = 0x1; | | 902 | buf1[t->n] = 0x1; |
903 | ATF_CHECK(ftello(fp) == (off_t)0); | | 903 | ATF_CHECK(ftello(fp) == (off_t)0); |
904 | ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp) | | 904 | ATF_CHECK(fread(&buf1[0], 1, sizeof(buf1), fp) |
905 | == (size_t)t->n); | | 905 | == (size_t)t->n); |
906 | ATF_CHECK(feof(fp) != 0); | | 906 | ATF_CHECK(feof(fp) != 0); |
907 | ATF_CHECK(!memcmp(&buf0[0], &buf1[0], t->n)); | | 907 | ATF_CHECK(!memcmp(&buf0[0], &buf1[0], t->n)); |
908 | ATF_CHECK((unsigned char)buf1[t->n] == 0x1); | | 908 | ATF_CHECK((unsigned char)buf1[t->n] == 0x1); |
909 | #if defined(__GLIBC__) | | 909 | #if defined(__GLIBC__) |
910 | } | | 910 | } |
911 | #endif | | 911 | #endif |
912 | ATF_CHECK(fclose(fp) == 0); | | 912 | ATF_CHECK(fclose(fp) == 0); |
913 | } | | 913 | } |
914 | } | | 914 | } |
915 | } | | 915 | } |
916 | | | 916 | |
917 | /* | | 917 | /* |
918 | * test19 - test22: | | 918 | * test19 - test22: |
919 | * If a stream open for update is flushed or closed and the last write has | | 919 | * If a stream open for update is flushed or closed and the last write has |
920 | * advanced the current buffer size, a null byte is written at the end of the | | 920 | * advanced the current buffer size, a null byte is written at the end of the |
921 | * buffer if it fits. | | 921 | * buffer if it fits. |
922 | */ | | 922 | */ |
923 | | | 923 | |
924 | const char *mode_rw2[] = { | | 924 | const char *mode_rw2[] = { |
925 | "r+", "rb+", "r+b", | | 925 | "r+", "rb+", "r+b", |
926 | "w", "wb", "w+", "wb+", "w+b", | | 926 | "w", "wb", "w+", "wb+", "w+b", |
927 | NULL | | 927 | NULL |
928 | }; | | 928 | }; |
929 | | | 929 | |
930 | ATF_TC(test19); | | 930 | ATF_TC(test19); |
931 | ATF_TC_HEAD(test19, tc) | | 931 | ATF_TC_HEAD(test19, tc) |
932 | { | | 932 | { |
933 | atf_tc_set_md_var(tc, "descr", "test19"); | | 933 | atf_tc_set_md_var(tc, "descr", "test19"); |
934 | } | | 934 | } |
935 | ATF_TC_BODY(test19, tc) | | 935 | ATF_TC_BODY(test19, tc) |
936 | { | | 936 | { |
937 | struct testcase *t; | | 937 | struct testcase *t; |
938 | int i; | | 938 | int i; |
939 | const char **p; | | 939 | const char **p; |
940 | char buf[BUFSIZ]; | | 940 | char buf[BUFSIZ]; |
941 | FILE *fp; | | 941 | FILE *fp; |
942 | | | 942 | |
943 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 943 | for (t = &testcases[0]; t->s != NULL; ++t) { |
944 | for (p = &mode_rw2[0]; *p != NULL; ++p) { | | 944 | for (p = &mode_rw2[0]; *p != NULL; ++p) { |
945 | | | 945 | |
946 | memcpy(&buf[0], t->s, t->n); | | 946 | memcpy(&buf[0], t->s, t->n); |
947 | buf[t->n] = 0x1; | | 947 | buf[t->n] = 0x1; |
948 | fp = fmemopen(&buf[0], t->n + 1, *p); | | 948 | fp = fmemopen(&buf[0], t->n + 1, *p); |
949 | ATF_CHECK(fp != NULL); | | 949 | ATF_CHECK(fp != NULL); |
950 | setbuf(fp, NULL); | | 950 | setbuf(fp, NULL); |
951 | /* | | 951 | /* |
952 | * test fmemopen_write + fputc(3) | | 952 | * test fmemopen_write + fputc(3) |
953 | */ | | 953 | */ |
954 | for (i = 0; i < t->n; ++i) { | | 954 | for (i = 0; i < t->n; ++i) { |
955 | ATF_CHECK(ftello(fp) == (off_t)i); | | 955 | ATF_CHECK(ftello(fp) == (off_t)i); |
956 | ATF_CHECK(fputc(t->s[i], fp) == t->s[i]); | | 956 | ATF_CHECK(fputc(t->s[i], fp) == t->s[i]); |
957 | ATF_CHECK(buf[i] == t->s[i]); | | 957 | ATF_CHECK(buf[i] == t->s[i]); |
958 | ATF_CHECK(ftello(fp) == (off_t)i + 1); | | 958 | ATF_CHECK(ftello(fp) == (off_t)i + 1); |
959 | ATF_CHECK(buf[i] == t->s[i]); | | 959 | ATF_CHECK(buf[i] == t->s[i]); |
960 | #if !defined(__GLIBC__) | | 960 | #if !defined(__GLIBC__) |
961 | ATF_CHECK(buf[i + 1] == '\0'); | | 961 | ATF_CHECK(buf[i + 1] == '\0'); |
962 | #endif | | 962 | #endif |
963 | } | | 963 | } |
964 | | | 964 | |
965 | /* don't accept non nul character at end of buffer */ | | 965 | /* don't accept non nul character at end of buffer */ |
966 | ATF_CHECK(fputc(0x1, fp) == EOF); | | 966 | ATF_CHECK(fputc(0x1, fp) == EOF); |
967 | ATF_CHECK(ftello(fp) == (off_t)t->n); | | 967 | ATF_CHECK_MSG(ftello(fp) == (off_t)t->n, |
| | | 968 | "%td != %td", ftello(fp), (off_t)t->n); |
968 | ATF_CHECK(feof(fp) == 0); | | 969 | ATF_CHECK(feof(fp) == 0); |
969 | | | 970 | |
970 | /* accept nul character at end of buffer */ | | 971 | /* accept nul character at end of buffer */ |
971 | ATF_CHECK(fputc('\0', fp) == '\0'); | | 972 | ATF_CHECK(fputc('\0', fp) == '\0'); |
972 | ATF_CHECK(ftello(fp) == (off_t)t->n + 1); | | 973 | ATF_CHECK(ftello(fp) == (off_t)t->n + 1); |
973 | ATF_CHECK(feof(fp) == 0); | | 974 | ATF_CHECK(feof(fp) == 0); |
974 | | | 975 | |
975 | /* reach EOF */ | | 976 | /* reach EOF */ |
976 | ATF_CHECK(fputc('\0', fp) == EOF); | | 977 | ATF_CHECK(fputc('\0', fp) == EOF); |
977 | ATF_CHECK(ftello(fp) == (off_t)t->n + 1); | | 978 | ATF_CHECK(ftello(fp) == (off_t)t->n + 1); |
978 | | | 979 | |
979 | /* compare */ | | 980 | /* compare */ |
980 | ATF_CHECK(memcmp(&buf[0], t->s, t->n) == 0); | | 981 | ATF_CHECK(memcmp(&buf[0], t->s, t->n) == 0); |
981 | ATF_CHECK(buf[t->n] == '\0'); | | 982 | ATF_CHECK(buf[t->n] == '\0'); |
982 | | | 983 | |
983 | ATF_CHECK(fclose(fp) == 0); | | 984 | ATF_CHECK(fclose(fp) == 0); |
984 | } | | 985 | } |
985 | } | | 986 | } |
986 | } | | 987 | } |
987 | | | 988 | |
988 | ATF_TC(test20); | | 989 | ATF_TC(test20); |
989 | ATF_TC_HEAD(test20, tc) | | 990 | ATF_TC_HEAD(test20, tc) |
990 | { | | 991 | { |
991 | atf_tc_set_md_var(tc, "descr", "test20"); | | 992 | atf_tc_set_md_var(tc, "descr", "test20"); |
992 | } | | 993 | } |
993 | ATF_TC_BODY(test20, tc) | | 994 | ATF_TC_BODY(test20, tc) |
994 | { | | 995 | { |
995 | struct testcase *t; | | 996 | struct testcase *t; |
996 | const char **p; | | 997 | const char **p; |
997 | char buf[BUFSIZ]; | | 998 | char buf[BUFSIZ]; |
998 | FILE *fp; | | 999 | FILE *fp; |
999 | | | 1000 | |
1000 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 1001 | for (t = &testcases[0]; t->s != NULL; ++t) { |
1001 | for (p = &mode_rw2[0]; *p != NULL; ++p) { | | 1002 | for (p = &mode_rw2[0]; *p != NULL; ++p) { |
1002 | | | 1003 | |
1003 | memcpy(&buf[0], t->s, t->n); | | 1004 | memcpy(&buf[0], t->s, t->n); |
1004 | buf[t->n] = 0x1; | | 1005 | buf[t->n] = 0x1; |
1005 | fp = fmemopen(&buf[0], t->n + 1, *p); | | 1006 | fp = fmemopen(&buf[0], t->n + 1, *p); |
1006 | ATF_CHECK(fp != NULL); | | 1007 | ATF_CHECK(fp != NULL); |
1007 | setbuf(fp, NULL); | | 1008 | setbuf(fp, NULL); |
1008 | ATF_CHECK(fwrite(t->s, 1, t->n, fp) == (size_t)t->n); | | 1009 | ATF_CHECK(fwrite(t->s, 1, t->n, fp) == (size_t)t->n); |
1009 | /* | | 1010 | /* |
1010 | * test fmemopen_write + fwrite(3) | | 1011 | * test fmemopen_write + fwrite(3) |
1011 | */ | | 1012 | */ |
1012 | #if !defined(__GLIBC__) | | 1013 | #if !defined(__GLIBC__) |
1013 | ATF_CHECK(buf[t->n] == '\0'); | | 1014 | ATF_CHECK(buf[t->n] == '\0'); |
1014 | | | 1015 | |
1015 | /* don't accept non nul character at end of buffer */ | | 1016 | /* don't accept non nul character at end of buffer */ |
1016 | ATF_CHECK(fwrite("\x1", 1, 1, fp) == 0); | | 1017 | ATF_CHECK(fwrite("\x1", 1, 1, fp) == 0); |
1017 | ATF_CHECK(ftello(fp) == (off_t)t->n); | | 1018 | ATF_CHECK(ftello(fp) == (off_t)t->n); |
1018 | ATF_CHECK(feof(fp) == 0); | | 1019 | ATF_CHECK(feof(fp) == 0); |
1019 | #endif | | 1020 | #endif |
1020 | | | 1021 | |
1021 | /* accept nul character at end of buffer */ | | 1022 | /* accept nul character at end of buffer */ |
1022 | ATF_CHECK(fwrite("\x0", 1, 1, fp) == 1); | | 1023 | ATF_CHECK(fwrite("\x0", 1, 1, fp) == 1); |
1023 | ATF_CHECK(ftello(fp) == (off_t)t->n + 1); | | 1024 | ATF_CHECK(ftello(fp) == (off_t)t->n + 1); |
1024 | ATF_CHECK(feof(fp) == 0); | | 1025 | ATF_CHECK(feof(fp) == 0); |
1025 | | | 1026 | |
1026 | /* reach EOF */ | | 1027 | /* reach EOF */ |
1027 | ATF_CHECK(fputc('\0', fp) == EOF); | | 1028 | ATF_CHECK(fputc('\0', fp) == EOF); |
1028 | ATF_CHECK(ftello(fp) == (off_t)t->n + 1); | | 1029 | ATF_CHECK(ftello(fp) == (off_t)t->n + 1); |
1029 | | | 1030 | |
1030 | /* compare */ | | 1031 | /* compare */ |
1031 | ATF_CHECK(memcmp(&buf[0], t->s, t->n) == 0); | | 1032 | ATF_CHECK(memcmp(&buf[0], t->s, t->n) == 0); |
1032 | ATF_CHECK(buf[t->n] == '\0'); | | 1033 | ATF_CHECK(buf[t->n] == '\0'); |
1033 | | | 1034 | |
1034 | ATF_CHECK(fclose(fp) == 0); | | 1035 | ATF_CHECK(fclose(fp) == 0); |
1035 | } | | 1036 | } |
1036 | } | | 1037 | } |
1037 | } | | 1038 | } |
1038 | | | 1039 | |
1039 | ATF_TC(test21); | | 1040 | ATF_TC(test21); |
1040 | ATF_TC_HEAD(test21, tc) | | 1041 | ATF_TC_HEAD(test21, tc) |
1041 | { | | 1042 | { |
1042 | atf_tc_set_md_var(tc, "descr", "test21"); | | 1043 | atf_tc_set_md_var(tc, "descr", "test21"); |
1043 | } | | 1044 | } |
1044 | ATF_TC_BODY(test21, tc) | | 1045 | ATF_TC_BODY(test21, tc) |
1045 | { | | 1046 | { |
1046 | struct testcase *t; | | 1047 | struct testcase *t; |
1047 | int len, i; | | 1048 | int len, i; |
1048 | const char **p; | | 1049 | const char **p; |
1049 | char buf[BUFSIZ]; | | 1050 | char buf[BUFSIZ]; |
1050 | FILE *fp; | | 1051 | FILE *fp; |
1051 | | | 1052 | |
1052 | for (t = &testcases[0]; t->s != NULL; ++t) { | | 1053 | for (t = &testcases[0]; t->s != NULL; ++t) { |
1053 | len = strnlen(t->s, t->n); | | 1054 | len = strnlen(t->s, t->n); |
1054 | for (p = &mode_a[0]; *p != NULL; ++p) { | | 1055 | for (p = &mode_a[0]; *p != NULL; ++p) { |
1055 | memcpy(&buf[0], t->s, t->n); | | 1056 | memcpy(&buf[0], t->s, t->n); |
1056 | fp = fmemopen(&buf[0], t->n, *p); | | 1057 | fp = fmemopen(&buf[0], t->n, *p); |
1057 | ATF_CHECK(fp != NULL); | | 1058 | ATF_CHECK(fp != NULL); |
1058 | setbuf(fp, NULL); | | 1059 | setbuf(fp, NULL); |
1059 | /* | | 1060 | /* |
1060 | * test fmemopen_write + fputc(3) | | 1061 | * test fmemopen_write + fputc(3) |
1061 | */ | | 1062 | */ |
1062 | if (len < t->n) { | | 1063 | if (len < t->n) { |
1063 | for (i = len; i < t->n - 1; ++i) { | | 1064 | for (i = len; i < t->n - 1; ++i) { |
1064 | ATF_CHECK(ftello(fp) == (off_t)i); | | 1065 | ATF_CHECK(ftello(fp) == (off_t)i); |
1065 | ATF_CHECK(fputc(t->s[i - len], fp) | | 1066 | ATF_CHECK(fputc(t->s[i - len], fp) |
1066 | == t->s[i - len]); | | 1067 | == t->s[i - len]); |
1067 | ATF_CHECK(buf[i] == t->s[i - len]); | | 1068 | ATF_CHECK(buf[i] == t->s[i - len]); |
1068 | ATF_CHECK(ftello(fp) == (off_t)i + 1); | | 1069 | ATF_CHECK(ftello(fp) == (off_t)i + 1); |
1069 | #if !defined(__GLIBC__) | | 1070 | #if !defined(__GLIBC__) |
1070 | ATF_CHECK(buf[i + 1] == '\0'); | | 1071 | ATF_CHECK(buf[i + 1] == '\0'); |
1071 | #endif | | 1072 | #endif |
1072 | } | | 1073 | } |
1073 | | | 1074 | |
1074 | /* don't accept non nul character at end of buffer */ | | 1075 | /* don't accept non nul character at end of buffer */ |
1075 | ATF_CHECK(ftello(fp) == (off_t)t->n - 1); | | 1076 | ATF_CHECK(ftello(fp) == (off_t)t->n - 1); |
1076 | ATF_CHECK(fputc(0x1, fp) == EOF); | | 1077 | ATF_CHECK(fputc(0x1, fp) == EOF); |
1077 | ATF_CHECK(ftello(fp) == (off_t)t->n - 1); | | 1078 | ATF_CHECK(ftello(fp) == (off_t)t->n - 1); |
1078 | | | 1079 | |
1079 | /* accept nul character at end of buffer */ | | 1080 | /* accept nul character at end of buffer */ |
1080 | ATF_CHECK(ftello(fp) == (off_t)t->n - 1); | | 1081 | ATF_CHECK(ftello(fp) == (off_t)t->n - 1); |
1081 | ATF_CHECK(fputc('\0', fp) == '\0'); | | 1082 | ATF_CHECK(fputc('\0', fp) == '\0'); |
1082 | ATF_CHECK(ftello(fp) == (off_t)t->n); | | 1083 | ATF_CHECK(ftello(fp) == (off_t)t->n); |
1083 | } | | 1084 | } |
1084 | | | 1085 | |
1085 | /* reach EOF */ | | 1086 | /* reach EOF */ |
1086 | ATF_CHECK(ftello(fp) == (off_t)t->n); | | 1087 | ATF_CHECK(ftello(fp) == (off_t)t->n); |
1087 | ATF_CHECK(fputc('\0', fp) == EOF); | | 1088 | ATF_CHECK(fputc('\0', fp) == EOF); |
1088 | ATF_CHECK(ftello(fp) == (off_t)t->n); | | 1089 | ATF_CHECK(ftello(fp) == (off_t)t->n); |
1089 | | | 1090 | |
1090 | ATF_CHECK(fclose(fp) == 0); | | 1091 | ATF_CHECK(fclose(fp) == 0); |
1091 | } | | 1092 | } |
1092 | } | | 1093 | } |
1093 | } | | 1094 | } |
1094 | | | 1095 | |
1095 | ATF_TC(test22); | | 1096 | ATF_TC(test22); |
1096 | ATF_TC_HEAD(test22, tc) | | 1097 | ATF_TC_HEAD(test22, tc) |
1097 | { | | 1098 | { |
1098 | atf_tc_set_md_var(tc, "descr", "test22"); | | 1099 | atf_tc_set_md_var(tc, "descr", "test22"); |
1099 | } | | 1100 | } |
1100 | ATF_TC_BODY(test22, tc) | | 1101 | ATF_TC_BODY(test22, tc) |
1101 | { | | 1102 | { |
1102 | struct testcase *t0, *t1; | | 1103 | struct testcase *t0, *t1; |
1103 | size_t len0, len1, nleft; | | 1104 | size_t len0, len1, nleft; |
1104 | const char **p; | | 1105 | const char **p; |
1105 | char buf[BUFSIZ]; | | 1106 | char buf[BUFSIZ]; |
1106 | FILE *fp; | | 1107 | FILE *fp; |
1107 | | | 1108 | |
1108 | for (t0 = &testcases[0]; t0->s != NULL; ++t0) { | | 1109 | for (t0 = &testcases[0]; t0->s != NULL; ++t0) { |
1109 | len0 = strnlen(t0->s, t0->n); | | 1110 | len0 = strnlen(t0->s, t0->n); |
1110 | for (t1 = &testcases[0]; t1->s != NULL; ++t1) { | | 1111 | for (t1 = &testcases[0]; t1->s != NULL; ++t1) { |
1111 | len1 = strnlen(t1->s, t1->n); | | 1112 | len1 = strnlen(t1->s, t1->n); |
1112 | for (p = &mode_a[0]; *p != NULL; ++p) { | | 1113 | for (p = &mode_a[0]; *p != NULL; ++p) { |
1113 | | | 1114 | |
1114 | memcpy(&buf[0], t0->s, t0->n); | | 1115 | memcpy(&buf[0], t0->s, t0->n); |
1115 | fp = fmemopen(&buf[0], t0->n, *p); | | 1116 | fp = fmemopen(&buf[0], t0->n, *p); |
1116 | ATF_CHECK(fp != NULL); | | 1117 | ATF_CHECK(fp != NULL); |
1117 | setbuf(fp, NULL); | | 1118 | setbuf(fp, NULL); |
1118 | /* | | 1119 | /* |
1119 | * test fmemopen_write + fwrite(3) | | 1120 | * test fmemopen_write + fwrite(3) |
1120 | */ | | 1121 | */ |
1121 | nleft = t0->n - len0; | | 1122 | nleft = t0->n - len0; |
1122 | #if !defined(__GLIBC__) | | 1123 | #if !defined(__GLIBC__) |
1123 | if (nleft == 0 || len1 == nleft - 1) { | | 1124 | if (nleft == 0 || len1 == nleft - 1) { |
1124 | ATF_CHECK(fwrite(t1->s, 1, t1->n, fp) | | 1125 | ATF_CHECK(fwrite(t1->s, 1, t1->n, fp) |
1125 | == nleft); | | 1126 | == nleft); |
1126 | ATF_CHECK(ftell(fp) == t1->n); | | 1127 | ATF_CHECK(ftell(fp) == t1->n); |
1127 | } else { | | 1128 | } else { |
1128 | ATF_CHECK(fwrite(t1->s, 1, t1->n, fp) | | 1129 | ATF_CHECK(fwrite(t1->s, 1, t1->n, fp) |
1129 | == nleft - 1); | | 1130 | == nleft - 1); |
1130 | ATF_CHECK(ftell(fp) == t1->n - 1); | | 1131 | ATF_CHECK(ftell(fp) == t1->n - 1); |
1131 | } | | 1132 | } |
1132 | #endif | | 1133 | #endif |
1133 | ATF_CHECK(fclose(fp) == 0); | | 1134 | ATF_CHECK(fclose(fp) == 0); |
1134 | } | | 1135 | } |
1135 | } | | 1136 | } |
1136 | } | | 1137 | } |
1137 | } | | 1138 | } |
1138 | | | 1139 | |
1139 | ATF_TP_ADD_TCS(tp) | | 1140 | ATF_TP_ADD_TCS(tp) |
1140 | { | | 1141 | { |
1141 | ATF_TP_ADD_TC(tp, test00); | | 1142 | ATF_TP_ADD_TC(tp, test00); |
1142 | ATF_TP_ADD_TC(tp, test01); | | 1143 | ATF_TP_ADD_TC(tp, test01); |
1143 | ATF_TP_ADD_TC(tp, test02); | | 1144 | ATF_TP_ADD_TC(tp, test02); |
1144 | ATF_TP_ADD_TC(tp, test03); | | 1145 | ATF_TP_ADD_TC(tp, test03); |
1145 | ATF_TP_ADD_TC(tp, test04); | | 1146 | ATF_TP_ADD_TC(tp, test04); |
1146 | ATF_TP_ADD_TC(tp, test05); | | 1147 | ATF_TP_ADD_TC(tp, test05); |
1147 | ATF_TP_ADD_TC(tp, test06); | | 1148 | ATF_TP_ADD_TC(tp, test06); |
1148 | ATF_TP_ADD_TC(tp, test07); | | 1149 | ATF_TP_ADD_TC(tp, test07); |
1149 | ATF_TP_ADD_TC(tp, test08); | | 1150 | ATF_TP_ADD_TC(tp, test08); |
1150 | ATF_TP_ADD_TC(tp, test09); | | 1151 | ATF_TP_ADD_TC(tp, test09); |
1151 | ATF_TP_ADD_TC(tp, test10); | | 1152 | ATF_TP_ADD_TC(tp, test10); |
1152 | ATF_TP_ADD_TC(tp, test11); | | 1153 | ATF_TP_ADD_TC(tp, test11); |
1153 | ATF_TP_ADD_TC(tp, test12); | | 1154 | ATF_TP_ADD_TC(tp, test12); |
1154 | ATF_TP_ADD_TC(tp, test13); | | 1155 | ATF_TP_ADD_TC(tp, test13); |
1155 | ATF_TP_ADD_TC(tp, test14); | | 1156 | ATF_TP_ADD_TC(tp, test14); |
1156 | ATF_TP_ADD_TC(tp, test15); | | 1157 | ATF_TP_ADD_TC(tp, test15); |
1157 | ATF_TP_ADD_TC(tp, test16); | | 1158 | ATF_TP_ADD_TC(tp, test16); |
1158 | ATF_TP_ADD_TC(tp, test17); | | 1159 | ATF_TP_ADD_TC(tp, test17); |
1159 | ATF_TP_ADD_TC(tp, test18); | | 1160 | ATF_TP_ADD_TC(tp, test18); |
1160 | ATF_TP_ADD_TC(tp, test19); | | 1161 | ATF_TP_ADD_TC(tp, test19); |
1161 | ATF_TP_ADD_TC(tp, test20); | | 1162 | ATF_TP_ADD_TC(tp, test20); |
1162 | ATF_TP_ADD_TC(tp, test21); | | 1163 | ATF_TP_ADD_TC(tp, test21); |
1163 | ATF_TP_ADD_TC(tp, test22); | | 1164 | ATF_TP_ADD_TC(tp, test22); |
1164 | | | 1165 | |
1165 | return atf_no_error(); | | 1166 | return atf_no_error(); |
1166 | } | | 1167 | } |