summaryrefslogtreecommitdiff
path: root/tests/stdio_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-01-20 17:14:53 -0800
committerElliott Hughes <enh@google.com>2016-01-21 10:34:35 -0800
commit2704bd13409a77237147f861c43796148326b2e3 (patch)
treec2433fa289edb2a7654a3c1caa2ad3c21c60e23d /tests/stdio_test.cpp
parent5f1ff279ea6aa4c35c59a81018131810e35b2bff (diff)
Simplify fseek/ftell.
Another step towards _FILE_OFFSET_BITS=64 support. Bug: http://b/24807045 Change-Id: I00b83c81a7b108176c4d9437bc32611f73b7e967
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index d054bf59d..31acfec90 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -1068,3 +1068,28 @@ TEST(STDIO_TEST, fclose_invalidates_fd) {
ASSERT_EQ(-1, fileno(stdin));
ASSERT_EQ(EBADF, errno);
}
+
+TEST(STDIO_TEST, fseek_ftell_unseekable) {
+#if defined(__BIONIC__) // glibc has fopencookie instead.
+ auto read_fn = [](void*, char*, int) { return -1; };
+ FILE* fp = funopen(nullptr, read_fn, nullptr, nullptr, nullptr);
+ ASSERT_TRUE(fp != nullptr);
+
+ // Check that ftell balks on an unseekable FILE*.
+ errno = 0;
+ ASSERT_EQ(-1, ftell(fp));
+ ASSERT_EQ(ESPIPE, errno);
+
+ // SEEK_CUR is rewritten as SEEK_SET internally...
+ errno = 0;
+ ASSERT_EQ(-1, fseek(fp, 0, SEEK_CUR));
+ ASSERT_EQ(ESPIPE, errno);
+
+ // ...so it's worth testing the direct seek path too.
+ errno = 0;
+ ASSERT_EQ(-1, fseek(fp, 0, SEEK_SET));
+ ASSERT_EQ(ESPIPE, errno);
+
+ fclose(fp);
+#endif
+}