/* 3-1 测试能否对标准输入设置偏移量(测试stdin,重定向文件,管道,FIFO) */ #include <stdio.h> #include <unistd.h> #include <errno.h> #include <stdlib.h> int main() { if(lseek(STDIN_FILENO, 0, SEEK_CUR) == -1) { perror("cannot seek"); exit(1); } else { printf("seek ok\n"); } return 0; } /* some test [duyiwuer@localhost test]$ ./ffffffffff cannot seek: Illegal seek [duyiwuer@localhost test]$ ./ffffffffff < ./apue-3.1.c seek ok [duyiwuer@localhost test]$ cat < ./apue-3.1.c | ./ffffffffff cannot seek: Illegal seek */