现在的位置: 首页 > 综合 > 正文

APUE-3.1 测试能否对标准输入设置偏移量(测试stdin,重定向文件,管道,FIFO)

2013年07月17日 ⁄ 综合 ⁄ 共 430字 ⁄ 字号 评论关闭
/* 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
*/

抱歉!评论已关闭.