unix环境下测试 是否是流设备

goldbeef 2012-08-10 10:04:30
我在虚拟机上使用ubuntu操作系统,用下面的代码测试/dev/tty ,发现不是 流设备 ,最近在看unix环境下高级编程,上面的怎么测得 /dev/tty 是流设备。。

#include <stdio.h>; 
#include <stdlib.h>;


int main(int argc, char *argv[])
{
int fds;
int i;
if((fds = open("/dev/tty","r")) < 0)
printf("open error\n");
if(isastream(fds) == 1)
printf("this dev is a stream dev\n");
else
printf("no\n");
return 0;
}
...全文
101 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
goldbeef 2012-08-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

楼主的代码不对吧, open的第二个参数是int型
if((fds = open("/dev/tty",O_RDONLY)) < 0)


另外我机子上测的也是打印 no
[/Quote]对着呢,O_RDONLY是在头文件中定义的常量吧。。我刚才看了下书,好像linux没有STREAMS子系统,Solaris支持。。难道是这方面的问题?
帅得不敢出门 2012-08-10
  • 打赏
  • 举报
回复
楼主的代码不对吧, open的第二个参数是int型
if((fds = open("/dev/tty",O_RDONLY)) < 0)


另外我机子上测的也是打印 no

goldbeef 2012-08-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

首先O_RDONLY的确是在头文件中定义的常量,但是它是00,不是"r",所以LZ的参数是错误的,细节很重要,"r"是fopen需要的参数。

其次
C/C++ code

UNIMPLEMENTED(2) Linux Programmer’s Manual UNIMPLEMENTED(2)

NAME
afs_syscall, br……
[/Quote]搜噶,多谢了
ForestDB 2012-08-10
  • 打赏
  • 举报
回复
首先O_RDONLY的确是在头文件中定义的常量,但是它是00,不是"r",所以LZ的参数是错误的,细节很重要,"r"是fopen需要的参数。

其次

UNIMPLEMENTED(2) Linux Programmer’s Manual UNIMPLEMENTED(2)

NAME
afs_syscall, break, fattach, fdetach, ftime, getmsg, getpmsg, gtty, isastream, lock, mpx, multiplexer,
prof, profil, putmsg, putpmsg, security, stty, ulimit, vserver - unimplemented system calls

SYNOPSIS
Unimplemented system calls.

DESCRIPTION
These system calls are not implemented in the Linux 2.4 kernel.

RETURN VALUE
These system calls always return -1 and set errno to ENOSYS.

NOTES
Note that ftime(3), profil(3) and ulimit(3) are implemented as library functions.

Some system calls, like alloc_hugepages(2), free_hugepages(2), ioperm(2), iopl(2), and vm86(2) only exist
on certain architectures.

Some system calls, like ipc(2), create_module(2), init_module(2), and delete_module(2) only exist when
the Linux kernel was built with support for them.

SEE ALSO
obsolete(2)

Linux 2.4 2003-02-28 UNIMPLEMENTED(2)


所以注定是“no”。

69,380

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧