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" 6 7 #define ASSERT(c) do { if (!(c)) t_error("%s failed\n", #c); } while(0) 8 main(void)9int main(void) 10 { 11 char buf[] = "test"; 12 char s[10]; 13 FILE *f; 14 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; 22 } 23