This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "freadptr.h"
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26
27 #include "macros.h"
28
29 int
30 main (int argc, char **argv)
31 {
32 int nbytes = atoi (argv[1]);
33 {
34 void *buf = malloc (nbytes);
35 ASSERT (fread (buf, 1, nbytes, stdin) == nbytes);
36 free (buf);
37 }
38
39 if (lseek (0, 0, SEEK_CUR) == nbytes)
40 {
41
42
43 size_t size;
44 ASSERT (freadptr (stdin, &size) == NULL);
45 }
46 else
47 {
48
49 const char stdin_contents[] =
50 "#!/bin/sh\n\n${CHECKER} ./test-freadptr${EXEEXT} 5 < \"$srcdir/test-freadptr.sh\" || exit 1\ncat \"$srcdir/test-freadptr.sh\" | ${CHECKER} ./test-freadptr${EXEEXT} 5 || exit 1\nexit 0\n";
51 const char *expected = stdin_contents + nbytes;
52 size_t available1;
53 size_t available2;
54 size_t available3;
55
56
57 {
58 const char *ptr = freadptr (stdin, &available1);
59
60 ASSERT (ptr != NULL);
61 ASSERT (available1 != 0);
62 ASSERT (available1 <= strlen (expected));
63 ASSERT (memcmp (ptr, expected, available1) == 0);
64 }
65
66
67 ungetc (fgetc (stdin), stdin);
68 {
69 const char *ptr = freadptr (stdin, &available2);
70
71 if (ptr != NULL)
72 {
73 ASSERT (available2 == available1);
74 ASSERT (memcmp (ptr, expected, available2) == 0);
75 }
76 }
77
78
79 fgetc (stdin);
80 ungetc ('@', stdin);
81 {
82 const char *ptr = freadptr (stdin, &available3);
83
84 if (ptr != NULL)
85 {
86 ASSERT (available3 == 1 || available3 == available1);
87 ASSERT (ptr[0] == '@');
88 if (available3 > 1)
89 {
90 ASSERT (memcmp (ptr + 1, expected + 1, available3 - 1) == 0);
91 }
92 }
93 }
94 }
95
96
97 fclose (stdin);
98
99 return 0;
100 }