|
|
#include <stropts.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/fcntl.h>
#include <stdio.h>
int isastream (int fd)
{
return ( ioctl(fd, I_CANPUT,0) !=-1) ;
}
int main(int argc, char *argv[])
{
int i,fd;
if (argc <=1 )
{
perror ("argc too few");
exit (1);
}
for (i=1; i<argc; i++)
{
printf("%s:\t", argv);
if ( (fd =open(argv,O_RDONLY))<0 )
{
printf("%s:can't open\n", argv);
continue;
}
if ( isastream(fd) ==0 )
printf("%s:not a stream\n", argv);
else
printf("%s: is a stream\n", argv);
}
exit (0);
}
运行后 ./isastream /dev/null /dev/tty
结果却都是/dev/tty: /dev/tty:not a stream
/dev/null: /dev/null:not a stream
这时怎么回事?
按AUPE book上写的, 请问结果跟系统有关系吗?我的是FC2 |
|