add fgets-eof regression test
authorSzabolcs Nagy <nsz@port70.net>
Wed, 27 Aug 2014 12:59:18 +0000 (14:59 +0200)
committerSzabolcs Nagy <nsz@port70.net>
Wed, 27 Aug 2014 12:59:18 +0000 (14:59 +0200)
src/regression/fgets-eof.c [new file with mode: 0644]

diff --git a/src/regression/fgets-eof.c b/src/regression/fgets-eof.c
new file mode 100644 (file)
index 0000000..4b3e41f
--- /dev/null
@@ -0,0 +1,22 @@
+// fgets must not modify the buffer on eof
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "test.h"
+
+#define ASSERT(c) do { if (!(c)) t_error("%s failed\n", #c); } while(0)
+
+int main(void)
+{
+       char buf[] = "test";
+       char s[10];
+       FILE *f;
+
+       ASSERT((f = fmemopen(buf, sizeof buf, "r")) != 0);
+       ASSERT(fgets(s, sizeof s, f) == s);
+       ASSERT(strcmp(s, buf) == 0);
+       ASSERT(fgets(s, sizeof s, f) == 0);
+       if (s[0] != 't')
+               t_error("fgets modified the buffer after eof\n");
+       return t_status;
+}