10 const char teststring
[] = "hello world";
19 if (setvbuf (fp
, buf
, _IOFBF
, sizeof buf
) == EOF
)
21 printf ("setvbuf failed: %m\n");
25 /* Get the buffer size. */
26 if (__fbufsize (fp
) != sizeof buf
)
28 printf ("__fbusize() reported a buffer size of %zd bytes;"
29 " we installed a buffer with %zd bytes\n",
30 __fbufsize (fp
), sizeof buf
);
34 /* Write something and read it back. */
35 if (fputs (teststring
, fp
) == EOF
)
37 printf ("writing to new stream failed: %m\n");
41 if (fgets (readbuf
, sizeof readbuf
, fp
) == NULL
)
43 printf ("reading from new stream failed: %m\n");
46 if (strcmp (readbuf
, teststring
) != 0)
48 puts ("not the correct string read");
52 /* The file must be opened for reading and writing. */
53 if (__freading (fp
) == 0)
55 puts ("__freading() reported stream is not last read from");
58 if (__fwriting (fp
) != 0)
60 puts ("__fwriting() reported stream is write-only or last written to");
64 if (fputs (teststring
, fp
) == EOF
)
66 printf ("writing(2) to new stream failed: %m\n");
69 if (__fwriting (fp
) == 0)
71 puts ("__fwriting() doe snot reported stream is last written to");
74 if (__freading (fp
) != 0)
76 puts ("__freading() reported stream is last read from");
80 if (__freadable (fp
) == 0)
82 puts ("__freading() reported stream is last readable");
85 if (__fwritable (fp
) == 0)
87 puts ("__freading() reported stream is last writable");
91 /* The string we wrote above should still be in the buffer. */
92 if (__fpending (fp
) != strlen (teststring
))
94 printf ("__fpending() returned %zd; expected %zd\n",
95 __fpending (fp
), strlen (teststring
));
98 /* Discard all the output. */
100 /* And check again. */
101 if (__fpending (fp
) != 0)
103 printf ("__fpending() returned %zd; expected 0\n",
109 /* Find out whether buffer is line buffered. */
110 if (__flbf (fp
) != 0)
112 puts ("__flbf() reports line buffered but it is fully buffered");
116 if (setvbuf (fp
, buf
, _IOLBF
, sizeof buf
) == EOF
)
118 printf ("setvbuf(2) failed: %m\n");
121 if (__flbf (fp
) == 0)
123 puts ("__flbf() reports file is not line buffered");
127 if (setvbuf (fp
, NULL
, _IONBF
, 0) == EOF
)
129 printf ("setvbuf(3) failed: %m\n");
132 if (__flbf (fp
) != 0)
134 puts ("__flbf() reports line buffered but it is not buffered");