LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 805|回复: 0

linux下流设备的问题

[复制链接]
发表于 2011-1-22 20:25:44 | 显示全部楼层 |阅读模式
apue第二版14章关于流式设备的问题,请高手解惑!
1 程序14-7代码如下:
#include <stropts.h>
#include <unistd.h>

int isastream(int fd)
{
        return(ioctl(fd, I_CANPUT, 0) != -1);
}

然后14-8调用了这个程序:
#include <apue.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{
        int i, fd;

        for (i = 1; i < argc; i++) {
                if ((fd = open(argv, O_RDONLY)) < 0) {
                        err_ret("%s: can't open", argv);
                        continue;
                }
                if (isastream(fd) == 0)
                        err_ret("%s: not a stream", argv);
                else
                        err_msg("%s: streams device", argv);
        }
        exit(0);
}

但是在我电脑上的输出结果却不对。测试如下:
#./a.out /dev/tty /dev/null(必须使用root权限才能打开设备文件)
输出结果如下:
/dev/tty: not a stream: Invalid argument
/dev/null: not a stream: Inappropriate ioctl for device
而书中tty是一个streams device
貌似对所有的文件都是这两种结果,要么Invalid argument,要么Inappropriate ioctl for device。为什么和书上不一样呢?


2 程序14-9中的sys/conf.h头文件不存在。


3 程序14-10中的getmsg和getpmsg貌似都不存在。

请大家解惑,顺便请介绍一些关于linux下流式文件的一些资料,apue看样子偏向unix多些。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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