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; +}