Created
July 15, 2016 05:27
-
-
Save philippkeller/20f293f669efbd192ffa0da91f6ea1b5 to your computer and use it in GitHub Desktop.
apue figure 5.11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "apue.h" | |
void pr_stdio(const char *, FILE *); | |
int | |
main(void) | |
{ | |
FILE *fp; | |
fputs("enter any character\n", stdout); | |
if (getchar() == EOF) | |
err_sys("getchar error"); | |
fputs("one line to standard error\n", stderr); | |
pr_stdio("stdin", stdin); | |
pr_stdio("stdout", stdout); | |
pr_stdio("stderr", stderr); | |
if ((fp = fopen("/etc/motd", "r")) == NULL) | |
err_sys("fopen error"); | |
if (getc(fp) == EOF) | |
err_sys("getc error"); | |
pr_stdio("/etc/motd", fp); | |
exit(0); | |
} | |
void | |
pr_stdio(const char *name, FILE *fp) | |
{ | |
printf("stream = %s, ", name); | |
/* | |
* The following is nonportable. | |
*/ | |
if (fp->_IO_file_flags & _IO_UNBUFFERED) | |
printf("unbuffered"); | |
else if (fp->_IO_file_flags & _IO_LINE_BUF) | |
printf("line buffered"); | |
else /* if neither of above */ | |
printf("fully buffered"); | |
printf(", buffer size = %d\n", fp->_IO_buf_end - fp->_IO_buf_base); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment