1 | #include <stdio.h> |
2 | #include <string.h> |
3 | |
4 | #include <support/support.h> |
5 | |
6 | static int |
7 | do_test (void) |
8 | { |
9 | FILE *f = tmpfile (); |
10 | char obuf[99999], ibuf[sizeof obuf]; |
11 | char *line; |
12 | size_t linesz; |
13 | |
14 | if (! f) |
15 | { |
16 | perror ("tmpfile" ); |
17 | return 1; |
18 | } |
19 | |
20 | if (fputs ("line\n" , f) == EOF) |
21 | { |
22 | perror ("fputs" ); |
23 | return 1; |
24 | } |
25 | |
26 | memset (obuf, 'z', sizeof obuf); |
27 | memset (ibuf, 'y', sizeof ibuf); |
28 | |
29 | if (fwrite (obuf, sizeof obuf, 1, f) != 1) |
30 | { |
31 | perror ("fwrite" ); |
32 | return 1; |
33 | } |
34 | |
35 | rewind (f); |
36 | |
37 | line = NULL; |
38 | linesz = 0; |
39 | if (getline (lineptr: &line, n: &linesz, stream: f) != 5) |
40 | { |
41 | perror ("getline" ); |
42 | return 1; |
43 | } |
44 | if (strcmp (line, "line\n" )) |
45 | { |
46 | puts (s: "Lines differ. Test FAILED!" ); |
47 | return 1; |
48 | } |
49 | |
50 | if (fread (ptr: ibuf, size: sizeof ibuf, n: 1, stream: f) != 1) |
51 | { |
52 | perror ("fread" ); |
53 | return 1; |
54 | } |
55 | |
56 | if (memcmp (ibuf, obuf, sizeof ibuf)) |
57 | { |
58 | puts (s: "Buffers differ. Test FAILED!" ); |
59 | return 1; |
60 | } |
61 | |
62 | line = xasprintf (format: "\ |
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 | " ); |
67 | |
68 | puts (s: "Test succeeded." ); |
69 | return 0; |
70 | } |
71 | |
72 | #define TEST_FUNCTION do_test () |
73 | #include "../test-skeleton.c" |
74 | |