1 /* 2 * FILE: p659_stdio.c 3 * DATE: 20180124 4 * ================== 5 * DESCRIPTION: stdin stdout stderr 6 */ 7 8 #include <stdio.h> 9 10 int main(void) 11 { 12 /* 标准输入stdin */ 13 printf("=== stdin ===\n"); 14 // 宏 _IO_UNBUFFERED 无缓冲 15 if(stdin->_flags & _IO_UNBUFFERED) 16 printf("unbuffered 无缓冲\n"); 17 // 宏 _IO_LINE_BUF 行缓冲 18 else if(stdin->_flags & _IO_LINE_BUF) 19 printf("line-buffered 行缓冲\n"); 20 // 宏 _IO_FULL_BUF 全缓冲 21 else // if(stdin->_flags & _IO_FULL_BUF) 22 printf("fully-buffered 全缓冲\n"); 23 printf("buff size is %d 缓冲区大小\n", stdin->_IO_buf_end-stdin->_IO_buf_base); 24 printf("discriptior is %d 文件描述符\n\n", fileno(stdin)); 25 26 27 /* 标准输出 stdout */ 28 printf("=== stdout ===\n"); 29 if(stdout->_flags & _IO_UNBUFFERED) 30 printf("unbuffered\n"); 31 else if(stdout->_flags & _IO_LINE_BUF) 32 printf("line-buffered 行缓冲\n"); 33 else 34 printf("fully-buffered\n"); 35 printf("buffer size is %d\n", stdout->_IO_buf_end-stdout->_IO_buf_base); 36 printf("descriptior si %d\n\n", fileno(stdout)); 37 38 39 /* 标准出错 stderr */ 40 printf("=== stderr ===\n"); 41 if(stderr->_flags & _IO_UNBUFFERED) 42 printf("unbuffered 无缓冲\n"); 43 else if(stderr->_flags & _IO_LINE_BUF) 44 printf("line buffered\n"); 45 else 46 printf("fully-buffered\n"); 47 printf("buffer size is %d\n", stderr->_IO_buf_end-stderr->_IO_buf_base); 48 printf("descriptior si %d\n\n", fileno(stderr)); 49 return 0; 50 }