From: Szabolcs Nagy Date: Wed, 27 Aug 2014 12:59:18 +0000 (+0200) Subject: add fgets-eof regression test X-Git-Url: http://nsz.repo.hu/git/?p=libc-test;a=commitdiff_plain;h=baa9bfe1879e3f1e717b8e1e11e9412ac9f91424 add fgets-eof regression test --- diff --git a/src/regression/fgets-eof.c b/src/regression/fgets-eof.c new file mode 100644 index 0000000..4b3e41f --- /dev/null +++ b/src/regression/fgets-eof.c @@ -0,0 +1,22 @@ +// fgets must not modify the buffer on eof +#include +#include +#include +#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; +}