O_RDWR未申报终端

时间:2015-12-16 05:05:24

标签: c ubuntu terminal ubuntu-14.04

我正在使用更新和升级的ubuntu 14.0.4LTS。

我已经编写了一个串行通信代码。

 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 #include <time.h>
 #include <errno.h>
 #include <sys/stat.h>
 #include <termios.h>

以上文件已包含在代码中。

当我编译代码时,它会返回错误&#34; O_RDWR未声明&#34; 如果我包含fcntl.h,则编译器返回错误&#34;参数1&#34;的不兼容类型,这意味着open函数需要const char *类型的参数。

struct termios TtyN;
open( TtyN, O_RDWR );
类型转换不合适。什么是正确的解决方案?

3 个答案:

答案 0 :(得分:2)

open采用路径字符串(char *),而不是随机structstruct termios用于specific terminal control APIs,而不是任意文件操作函数。

也许您想open "/dev/tty#"之类的内容(#替换为tty)?

答案 1 :(得分:2)

man 2 open将显示open()所需的标头文件。即,

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

接下来我建议查看man 3 termios

答案 2 :(得分:1)

open的第一个参数是char * pathname,而不是struct termios类型。 不要那样打开它。

相关问题