1 | #include <stdio.h> |
2 | #include <string.h> |
3 | |
4 | static int |
5 | do_test (void) |
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 (lineptr: &line, n: &linesz, stream: f) != 5) |
38 | { |
39 | perror ("getline" ); |
40 | return 1; |
41 | } |
42 | if (strcmp (line, "line\n" )) |
43 | { |
44 | puts (s: "Lines differ. Test FAILED!" ); |
45 | return 1; |
46 | } |
47 | |
48 | if (fread (ptr: ibuf, size: sizeof ibuf, n: 1, stream: f) != 1) |
49 | { |
50 | perror ("fread" ); |
51 | return 1; |
52 | } |
53 | |
54 | if (memcmp (ibuf, obuf, sizeof ibuf)) |
55 | { |
56 | puts (s: "Buffers differ. Test FAILED!" ); |
57 | return 1; |
58 | } |
59 | |
60 | asprintf (ptr: &line, fmt: "\ |
61 | GDB 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\ |
63 | There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\ |
64 | " ); |
65 | |
66 | puts (s: "Test succeeded." ); |
67 | return 0; |
68 | } |
69 | |
70 | #define TEST_FUNCTION do_test () |
71 | #include "../test-skeleton.c" |
72 | |