linux: Decorate __libc_fatal error buffer
[glibc.git] / stdio-common / test-fwrite.c
blob7f383921ca7838483bcc5f5b0e3a32a850c723c4
1 #include <stdio.h>
2 #include <string.h>
4 #include <support/support.h>
6 static int
7 do_test (void)
9 FILE *f = tmpfile ();
10 char obuf[99999], ibuf[sizeof obuf];
11 char *line;
12 size_t linesz;
14 if (! f)
16 perror ("tmpfile");
17 return 1;
20 if (fputs ("line\n", f) == EOF)
22 perror ("fputs");
23 return 1;
26 memset (obuf, 'z', sizeof obuf);
27 memset (ibuf, 'y', sizeof ibuf);
29 if (fwrite (obuf, sizeof obuf, 1, f) != 1)
31 perror ("fwrite");
32 return 1;
35 rewind (f);
37 line = NULL;
38 linesz = 0;
39 if (getline (&line, &linesz, f) != 5)
41 perror ("getline");
42 return 1;
44 if (strcmp (line, "line\n"))
46 puts ("Lines differ. Test FAILED!");
47 return 1;
50 if (fread (ibuf, sizeof ibuf, 1, f) != 1)
52 perror ("fread");
53 return 1;
56 if (memcmp (ibuf, obuf, sizeof ibuf))
58 puts ("Buffers differ. Test FAILED!");
59 return 1;
62 line = xasprintf ("\
63 GDB is free software and you are welcome to distribute copies of it\n\
64 under certain conditions; type \"show copying\" to see the conditions.\n\
65 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
66 ");
68 puts ("Test succeeded.");
69 return 0;
72 #define TEST_FUNCTION do_test ()
73 #include "../test-skeleton.c"