Created
March 2, 2015 14:17
-
-
Save Jerry-Fix/71d5ebd8686efdfb79af to your computer and use it in GitHub Desktop.
different streams test, works on 3.5.0-generic, 4.6.3 gcc
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" | |
#include <stdio.h> | |
#include <stdlib.h> | |
void pr_stdio(const char *name, FILE *fp); | |
int main(void){ | |
FILE *fp; | |
char c; | |
fputs("enter any character\n", stdout); | |
if((c = getchar()) == EOF) | |
err_sys("getchar err"); | |
printf("charcter is %c", c); | |
fputs("one line to stardard 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 err"); | |
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); | |
if (fp -> _IO_file_flags & _IO_UNBUFFERED) | |
printf("unbuffered"); | |
else if (fp -> _IO_file_flags & _IO_LINE_BUF) | |
printf("line buffered"); | |
else | |
printf("fully buffered"); | |
/* | |
printf(", buffer size = %d\n",fp -> _IO_buf_end - _IO_buf_base); | |
*/ | |
printf(" ,buffer size=%d\n", fp -> _IO_file_flags & _IO_BUFSIZ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment