update from main archive 960919
[platform/upstream/linaro-glibc.git] / stdio-common / bug4.c
1 #ifdef _LIBC
2 #include <ansidecl.h>
3 #endif
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <string.h>
7
8 int stdio_block_read = 1, stdio_block_write = 1;
9
10 int
11 DEFUN(main, (argc, argv),
12       int argc AND char **argv)
13 {
14   FILE *f;
15   int i;
16   char buffer[31];
17   const char filename[] = "/tmp/bugtest";
18
19   while ((i = getopt (argc, argv, "rw")) != EOF)
20     switch (i)
21       {
22       case 'r':
23         stdio_block_read = 0;
24         break;
25       case 'w':
26         stdio_block_write = 0;
27         break;
28       }
29
30   f = fopen(filename, "w+");
31   for (i=0; i<9000; i++) {
32     putc('x', f);
33   }
34   fseek(f, 8180L, 0);
35   fwrite("Where does this text come from?", 1, 31, f);
36   fseek(f, 8180L, 0);
37   fread(buffer, 1, 31, f);
38   fwrite(buffer, 1, 31, stdout);
39   fclose(f);
40   remove(filename);
41
42   if (!memcmp (buffer, "Where does this text come from?", 31))
43     {
44       puts ("\nTest succeeded.");
45       return 0;
46     }
47   else
48     {
49       puts ("\nTest FAILED!");
50       return 1;
51     }
52 }