diff options
author | mpi <> | 2013-03-28 09:35:58 +0000 |
---|---|---|
committer | mpi <> | 2013-03-28 09:35:58 +0000 |
commit | 4ac463dc130bdb00f62e4ece898870cfe8b51ec2 (patch) | |
tree | f13fc73977d5bc9d35902b7f68990eb778d06878 /src | |
parent | df80a6f3fce0a41f80bb51a076a108fbdde0a0db (diff) | |
download | openbsd-4ac463dc130bdb00f62e4ece898870cfe8b51ec2.tar.gz openbsd-4ac463dc130bdb00f62e4ece898870cfe8b51ec2.tar.bz2 openbsd-4ac463dc130bdb00f62e4ece898870cfe8b51ec2.zip |
More tests for negative seeks, prodded by matthew@
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libc/fmemopen/fmemopentest.c | 41 | ||||
-rw-r--r-- | src/regress/lib/libc/open_memstream/open_memstreamtest.c | 24 |
2 files changed, 63 insertions, 2 deletions
diff --git a/src/regress/lib/libc/fmemopen/fmemopentest.c b/src/regress/lib/libc/fmemopen/fmemopentest.c index 57063aeb0a..203c93be65 100644 --- a/src/regress/lib/libc/fmemopen/fmemopentest.c +++ b/src/regress/lib/libc/fmemopen/fmemopentest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: fmemopentest.c,v 1.2 2013/03/27 15:08:13 mpi Exp $ */ | 1 | /* $OpenBSD: fmemopentest.c,v 1.3 2013/03/28 09:35:58 mpi Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> | 4 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> |
@@ -161,6 +161,44 @@ writetest(void) | |||
161 | } | 161 | } |
162 | 162 | ||
163 | int | 163 | int |
164 | seektest(void) | ||
165 | { | ||
166 | FILE *s1; | ||
167 | char string[] = "long string for testing seek"; | ||
168 | size_t len, slen; | ||
169 | int failures = 0; | ||
170 | |||
171 | slen = strlen(string) + 1; | ||
172 | |||
173 | s1 = fmemopen(string, slen, "r"); | ||
174 | if (s1 == NULL) | ||
175 | return (1); | ||
176 | |||
177 | if (fseek(s1, 8, SEEK_SET) != 0) { | ||
178 | warnx("failed to fseek. (14)"); | ||
179 | failures++; | ||
180 | } | ||
181 | |||
182 | if (ftell(s1) != 8) { | ||
183 | warnx("failed seek test. (15)"); | ||
184 | failures++; | ||
185 | } | ||
186 | |||
187 | /* Try to seek backward */ | ||
188 | if (fseek(s1, -1, SEEK_CUR) != 0) { | ||
189 | warnx("failed to fseek. (16)"); | ||
190 | failures++; | ||
191 | } | ||
192 | |||
193 | if (ftell(s1) != 7) { | ||
194 | warnx("failed seeking backward. (17)"); | ||
195 | failures++; | ||
196 | } | ||
197 | |||
198 | return (failures); | ||
199 | } | ||
200 | |||
201 | int | ||
164 | main(void) | 202 | main(void) |
165 | { | 203 | { |
166 | int failures = 0; | 204 | int failures = 0; |
@@ -168,6 +206,7 @@ main(void) | |||
168 | failures += simpletest(); | 206 | failures += simpletest(); |
169 | failures += updatetest(); | 207 | failures += updatetest(); |
170 | failures += writetest(); | 208 | failures += writetest(); |
209 | failures += seektest(); | ||
171 | 210 | ||
172 | return (failures); | 211 | return (failures); |
173 | } | 212 | } |
diff --git a/src/regress/lib/libc/open_memstream/open_memstreamtest.c b/src/regress/lib/libc/open_memstream/open_memstreamtest.c index b9c0221b1a..a2327f21c5 100644 --- a/src/regress/lib/libc/open_memstream/open_memstreamtest.c +++ b/src/regress/lib/libc/open_memstream/open_memstreamtest.c | |||
@@ -1,4 +1,5 @@ | |||
1 | /* $OpenBSD: open_memstreamtest.c,v 1.2 2013/03/25 03:33:28 guenther Exp $ */ | 1 | /* $OpenBSD: open_memstreamtest.c,v 1.3 2013/03/28 09:35:58 mpi Exp $ */ |
2 | |||
2 | /* | 3 | /* |
3 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> | 4 | * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> |
4 | * | 5 | * |
@@ -137,6 +138,27 @@ main(void) | |||
137 | failures++; | 138 | failures++; |
138 | } | 139 | } |
139 | 140 | ||
141 | if (fseek(fp, 8, SEEK_SET) != 0) { | ||
142 | warnx("failed to fseek. (19)"); | ||
143 | failures++; | ||
144 | } | ||
145 | |||
146 | if (ftell(fp) != 8) { | ||
147 | warnx("failed seek test. (20)"); | ||
148 | failures++; | ||
149 | } | ||
150 | |||
151 | /* Try to seek backward */ | ||
152 | if (fseek(fp, -1, SEEK_CUR) != 0) { | ||
153 | warnx("failed to fseek. (21)"); | ||
154 | failures++; | ||
155 | } | ||
156 | |||
157 | if (ftell(fp) != 7) { | ||
158 | warnx("failed seeking backward. (22)"); | ||
159 | failures++; | ||
160 | } | ||
161 | |||
140 | free(buf); | 162 | free(buf); |
141 | 163 | ||
142 | return (failures); | 164 | return (failures); |