string test alignment fix by Mahesh Bodapati
[libc-test.git] / src / regression / fgets-eof.c
blob4b3e41f4ba9d71c108cffc72f4561e023a1f534d
1 // fgets must not modify the buffer on eof
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "test.h"
7 #define ASSERT(c) do { if (!(c)) t_error("%s failed\n", #c); } while(0)
9 int main(void)
11 char buf[] = "test";
12 char s[10];
13 FILE *f;
15 ASSERT((f = fmemopen(buf, sizeof buf, "r")) != 0);
16 ASSERT(fgets(s, sizeof s, f) == s);
17 ASSERT(strcmp(s, buf) == 0);
18 ASSERT(fgets(s, sizeof s, f) == 0);
19 if (s[0] != 't')
20 t_error("fgets modified the buffer after eof\n");
21 return t_status;