曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 5705|回复: 0
打印 上一主题 下一主题

[文件I/O] isastream() | 确定 STREAMS 设备

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2009-10-14 17:36:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
原型
#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
       
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-4 01:04 , Processed in 0.138100 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表