source: vendor/glibc-tests/glibc/stdio-common/test-fwrite.c

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.2 KB
Line 
1#include <stdio.h>
2#include <string.h>
3
4int
5main (int argc, char *argv[])
6{
7 FILE *f = tmpfile ();
8 char obuf[99999], ibuf[sizeof obuf];
9 char *line;
10 size_t linesz;
11
12 if (! f)
13 {
14 perror ("tmpfile");
15 return 1;
16 }
17
18 if (fputs ("line\n", f) == EOF)
19 {
20 perror ("fputs");
21 return 1;
22 }
23
24 memset (obuf, 'z', sizeof obuf);
25 memset (ibuf, 'y', sizeof ibuf);
26
27 if (fwrite (obuf, sizeof obuf, 1, f) != 1)
28 {
29 perror ("fwrite");
30 return 1;
31 }
32
33 rewind (f);
34
35 line = NULL;
36 linesz = 0;
37 if (getline (&line, &linesz, f) != 5)
38 {
39 perror ("getline");
40 return 1;
41 }
42 if (strcmp (line, "line\n"))
43 {
44 puts ("Lines differ. Test FAILED!");
45 return 1;
46 }
47
48 if (fread (ibuf, sizeof ibuf, 1, f) != 1)
49 {
50 perror ("fread");
51 return 1;
52 }
53
54 if (memcmp (ibuf, obuf, sizeof ibuf))
55 {
56 puts ("Buffers differ. Test FAILED!");
57 return 1;
58 }
59
60 asprintf (&line, "\
61GDB is free software and you are welcome to distribute copies of it\n\
62 under certain conditions; type \"show copying\" to see the conditions.\n\
63There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
64");
65
66 puts ("Test succeeded.");
67 return 0;
68}
Note: See TracBrowser for help on using the repository browser.