aboutsummaryrefslogtreecommitdiffstats
path: root/tests/stdio_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-10-09 17:57:26 -0700
committerElliott Hughes <enh@google.com>2015-10-09 17:57:26 -0700
commit8ab433df132aa59db08b4548155d72574ad06421 (patch)
tree23708cbc794620a364626a65306b8f260048d506 /tests/stdio_test.cpp
parent1ab3f303d2e7c8cc498a28fc3c8d9ded1fc46994 (diff)
downloadandroid_bionic-8ab433df132aa59db08b4548155d72574ad06421.tar.gz
android_bionic-8ab433df132aa59db08b4548155d72574ad06421.tar.bz2
android_bionic-8ab433df132aa59db08b4548155d72574ad06421.zip
Fix stdio read after EOF behavior.
Bug: https://code.google.com/p/android/issues/detail?id=184847 Change-Id: Ia20ce94007c2a09649f0763b1dc7ba959f2f618d
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 62677cdff..afb1511fb 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -1012,3 +1012,39 @@ TEST(stdio, fread_after_fseek) {
fclose(fp);
}
+
+// https://code.google.com/p/android/issues/detail?id=184847
+TEST(stdio, fread_EOF_184847) {
+ TemporaryFile tf;
+ char buf[6] = {0};
+
+ FILE* fw = fopen(tf.filename, "w");
+ ASSERT_TRUE(fw != nullptr);
+
+ FILE* fr = fopen(tf.filename, "r");
+ ASSERT_TRUE(fr != nullptr);
+
+ fwrite("a", 1, 1, fw);
+ fflush(fw);
+ ASSERT_EQ(1U, fread(buf, 1, 1, fr));
+ ASSERT_STREQ("a", buf);
+
+ // 'fr' is now at EOF.
+ ASSERT_EQ(0U, fread(buf, 1, 1, fr));
+ ASSERT_TRUE(feof(fr));
+
+ // Write some more...
+ fwrite("z", 1, 1, fw);
+ fflush(fw);
+
+ // ...and check that we can read it back.
+ // (BSD thinks that once a stream has hit EOF, it must always return EOF. SysV disagrees.)
+ ASSERT_EQ(1U, fread(buf, 1, 1, fr));
+ ASSERT_STREQ("z", buf);
+
+ // But now we're done.
+ ASSERT_EQ(0U, fread(buf, 1, 1, fr));
+
+ fclose(fr);
+ fclose(fw);
+}