-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbufstat.c
49 lines (38 loc) · 849 Bytes
/
bufstat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void pr_stdio(const char *, FILE *);
int main(void)
{
FILE *fp;
fputs("enter any character\n", stdout);
if(getchar() == EOF)
{
perror("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)
{
printf("fopen error");
}
if(getc(fp) == EOF)
{
perror("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 - fp->_IO_buf_base);
}