update from main archive 960919
[platform/upstream/linaro-glibc.git] / stdio-common / bug3.c
1 #include <ansidecl.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 int
6 DEFUN_VOID(main)
7 {
8   FILE *f;
9   int i;
10   const char filename[] = "/tmp/bugtest";
11
12   f = fopen(filename, "w+");
13   for (i=0; i<9000; i++)
14     putc ('x', f);
15   fseek (f, 8180L, 0);
16   fwrite ("Where does this text go?", 1, 24, f);
17   fflush (f);
18
19   rewind (f);
20   for (i=0; i<9000; i++)
21     {
22       int j;
23
24       if ((j = getc(f)) != 'x')
25         {
26           if (i != 8180)
27             {
28               printf ("Test FAILED!");
29               return 1;
30             }
31           else
32             {
33               char buf[25];
34
35               buf[0] = j;
36               fread (buf + 1, 1, 23, f);
37               buf[24] = '\0';
38               if (strcmp (buf, "Where does this text go?") != 0)
39                 {
40                   printf ("%s\nTest FAILED!\n", buf);
41                   return 1;
42                 }
43               i += 23;
44             }
45         }
46     }
47
48   fclose(f);
49   remove(filename);
50
51   puts ("Test succeeded.");
52
53   return 0;
54 }