]> git.wh0rd.org Git - ICEs.git/blob - 182288/test.c
initial import
[ICEs.git] / 182288 / test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 int main(void)
6 {
7         FILE *f;
8         char buf[1]; /* Change 256 to 1, and you can see the wierd behaviour
9                         * of fgets if run against glibc-2.3.5 */
10         unsigned lines = 0;
11
12         system("touch null_file");
13
14         /* Create this file before starting! */
15         f = fopen("null_file", "r");
16         if (!f) {
17                 perror("fopen");
18                 return EXIT_FAILURE;
19         }
20
21         while (1) {
22 puts("reading");
23                 if (!fgets(buf, sizeof buf, f)) {
24 puts("error");
25                         if (feof(f))
26                                 puts("End of File");
27                         else if (ferror(f))
28                                 puts("Error");
29                         else
30                                 puts("Wierd behaviour");
31                         break;
32                 }
33
34                 if (strchr(buf, '\n')) {
35                         printf("Read %u lines.\n", ++lines);
36                 }
37         }
38
39         fclose(f);
40         return 0;
41 }