今天在看一些关于LINUX下编程的电子书籍,把所学到的一些知识列一下:好记性不如烂笔头嘛
无缓冲I/O
Open,read,write,lseek和close函数提供无缓冲I/O。这些函数都对文件奏效。
句子比较简单就不翻译了,免得闹笑话,以下是原文。
The constants STDIN_FILENO and STDOUT_FILENO are defined in <unistd.h> and specify the file descriptors for standard input and standard output. These values are typically 0 and 1, respectively, but we'll use the new names for portability.
EXAMPLE
#include "apue.h"
#define BUFFSIZE 4096
int
main(void)
{
int n;
char buf[BUFFSIZE];
while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
if (write(STDOUT_FILENO, buf, n) != n)
err_sys("write error");
if (n < 0)
err_sys("read error");
exit(0);
}
If we compile the program into the standard name (a.out) and execute it as
./a.out > data
标准I/O
标准I/O函数提供给一个无buffer I/O函数一个带buffer 的接口,这样就不要担心如何选择最佳的buffer大小
标准I/O用常量stdin,stdou来指定标准输入和标准输出
附上小例子一个
#include "apue.h"
int
main(void)
{
int c;
while ((c = getc(stdin)) != EOF)
if (putc(c, stdout) == EOF)
err_sys("output error");
if (ferror(stdin))
err_sys("input error");
exit(0);
}
都是一些比较初级的东西,不过也不是所有人都知道,例如我。哈哈,惭愧,惭愧