summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2013-03-28 09:35:59 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2013-03-28 09:35:59 +0000
commitb5ef94356f336bf382eb0fcc634d3420d1104d50 (patch)
tree4b6daa9f6d74eb35dd42b9ea20abe39b1cea5131
parentdaa12e324da3d06e02e5e85bc27d5855273f2617 (diff)
More tests for negative seeks, prodded by matthew@
-rw-r--r--regress/lib/libc/fmemopen/fmemopentest.c41
-rw-r--r--regress/lib/libc/open_memstream/open_memstreamtest.c24
2 files changed, 63 insertions, 2 deletions
diff --git a/regress/lib/libc/fmemopen/fmemopentest.c b/regress/lib/libc/fmemopen/fmemopentest.c
index 57063aeb0a8..203c93be650 100644
--- a/regress/lib/libc/fmemopen/fmemopentest.c
+++ b/regress/lib/libc/fmemopen/fmemopentest.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmemopentest.c,v 1.2 2013/03/27 15:08:13 mpi Exp $ */
+/* $OpenBSD: fmemopentest.c,v 1.3 2013/03/28 09:35:58 mpi Exp $ */
/*
* Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org>
@@ -161,6 +161,44 @@ writetest(void)
}
int
+seektest(void)
+{
+ FILE *s1;
+ char string[] = "long string for testing seek";
+ size_t len, slen;
+ int failures = 0;
+
+ slen = strlen(string) + 1;
+
+ s1 = fmemopen(string, slen, "r");
+ if (s1 == NULL)
+ return (1);
+
+ if (fseek(s1, 8, SEEK_SET) != 0) {
+ warnx("failed to fseek. (14)");
+ failures++;
+ }
+
+ if (ftell(s1) != 8) {
+ warnx("failed seek test. (15)");
+ failures++;
+ }
+
+ /* Try to seek backward */
+ if (fseek(s1, -1, SEEK_CUR) != 0) {
+ warnx("failed to fseek. (16)");
+ failures++;
+ }
+
+ if (ftell(s1) != 7) {
+ warnx("failed seeking backward. (17)");
+ failures++;
+ }
+
+ return (failures);
+}
+
+int
main(void)
{
int failures = 0;
@@ -168,6 +206,7 @@ main(void)
failures += simpletest();
failures += updatetest();
failures += writetest();
+ failures += seektest();
return (failures);
}
diff --git a/regress/lib/libc/open_memstream/open_memstreamtest.c b/regress/lib/libc/open_memstream/open_memstreamtest.c
index b9c0221b1a5..a2327f21c50 100644
--- a/regress/lib/libc/open_memstream/open_memstreamtest.c
+++ b/regress/lib/libc/open_memstream/open_memstreamtest.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: open_memstreamtest.c,v 1.2 2013/03/25 03:33:28 guenther Exp $ */
+/* $OpenBSD: open_memstreamtest.c,v 1.3 2013/03/28 09:35:58 mpi Exp $ */
+
/*
* Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org>
*
@@ -137,6 +138,27 @@ main(void)
failures++;
}
+ if (fseek(fp, 8, SEEK_SET) != 0) {
+ warnx("failed to fseek. (19)");
+ failures++;
+ }
+
+ if (ftell(fp) != 8) {
+ warnx("failed seek test. (20)");
+ failures++;
+ }
+
+ /* Try to seek backward */
+ if (fseek(fp, -1, SEEK_CUR) != 0) {
+ warnx("failed to fseek. (21)");
+ failures++;
+ }
+
+ if (ftell(fp) != 7) {
+ warnx("failed seeking backward. (22)");
+ failures++;
+ }
+
free(buf);
return (failures);