程序清单 3-1“ 测试能否对标准输入设置偏移量
/**
* 程序清单 3-1“ 测试能否对标准输入设置偏移量 P51
*
* zy:
* 对lseek函数加深认识。
*
* 书中第一个例子/etc/motd是进入tty的一段文字,所以可以随意调整
* 书中第二个例子表示对管道进行lseek,但是不可以的
* 书中第三个例子,我相应的目录下没有找到该文件,我使用mkfifo创建了一个,
* 但是对其使用我们的程序是无效的,就是什么也不会出现。所以不知道我用mkfifo创建的东西
* 和书中是不是一个东西。
*
*/
#include "apue.h"
#include <stdlib.h>
#include "error.c"
int main(void) {
if(lseek(STDIN_FILENO,0,SEEK_CUR)==-1){//必须测试其是否等于-1,因为某些设备的偏移量可以是负的
printf("cannot seek \n ");
}else{
printf("seek ok\n ");
}
exit(0);
}
asd@asd-desktop:~/workspace/test/src$ !1029
./a.out </etc/motd
seek ok
asd@asd-desktop:~/workspace/test/src$ !1030
cat </etc/motd | ./a.out
cannot seek
asd@asd-desktop:~/workspace/test/src$ !1034
mkfifo fifo
mkfifo: cannot crea