source: branches/libc-0.6/src/libctests/glibc/stdio-common/test-fwrite.c

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

testcase adjustments.

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.4 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#ifdef HAVE_GETLINE
38 if (getline (&line, &linesz, f) != 5)
39 {
40 perror ("getline");
41 return 1;
42 }
43#else
44 char fgetbuf [80];
45 line = fgets (fgetbuf, sizeof(fgetbuf), f);
46 if (!line)
47 {
48 perror ("gets");
49 return 1;
50 }
51#endif
52 if (strcmp (line, "line\n"))
53 {
54 puts ("Lines differ. Test FAILED!");
55 return 1;
56 }
57
58 if (fread (ibuf, sizeof ibuf, 1, f) != 1)
59 {
60 perror ("fread");
61 return 1;
62 }
63
64 if (memcmp (ibuf, obuf, sizeof ibuf))
65 {
66 puts ("Buffers differ. Test FAILED!");
67 return 1;
68 }
69
70#ifdef HAVE_ASPRINTF
71 asprintf (&line, "\
72GDB is free software and you are welcome to distribute copies of it\n\
73 under certain conditions; type \"show copying\" to see the conditions.\n\
74There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
75");
76#endif
77
78 puts ("Test succeeded.");
79 return 0;
80}
Note: See TracBrowser for help on using the repository browser.