fig5.11
来自「unix环境编程」· 11 代码 · 共 52 行
11
52 行
#include "apue.h"#if defined(MACOS)#define _IO_UNBUFFERED __SNBF#define _IO_LINE_BUF __SLBF#define _IO_file_flags _flags#define BUFFERSZ(fp) (fp)->_bf._size#else#define BUFFERSZ(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)#endifvoid pr_stdio(const char *, FILE *);intmain(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);}voidpr_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", BUFFERSZ(fp));}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?