|
原型:
#include <stropts.h>
int isastream (int fildes);
isastream 函数确定文件描述符 fileds 是否表示 STREAMS 设备。如果是,则函数返回 1 ;如果不是,则返回 0 ;如果出错,返回 -1 。
测试代码:
#include <stdio.h>
#include <stropts.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
int fd;
int i;
if (argc < 2) {
printf ("Usages: isastreamm file ...");
exit (EXIT_FAILURE);
}
for (i = 0; i < argc; i++) {
if ((fd = open (argv [i], O_RDONLY)) == -1) {
printf ("Can't open %s", argv [i]);
continue;
}
printf ("%s %s a STREAMS device\n", argv [i], (isastream (fd)) ? "is" : "is not");
}
return (0);
} 运行及输出:[beyes@localhost STREAMS]$ ./isastream.exe /dev/tty /dev/null
./isastream.exe is not a STREAMS device
/dev/tty is not a STREAMS device
/dev/null is not a STREAMS device |
|