在我的代码中,
open()
返回-1,但一些原因导致errno
没有被设置。int fd;
int errno=0;
fd = open("/dev/tty0", O_RDWR | O_SYNC);
printf("errno is %d and fd is %d",errno,fd);
输出结果为:
errno is 0 and fd is -1
为什么 errno 没有被设置?我该如何确定 open()
失败的原因?
errno = 0
。open
函数本身会正确设置它。 - ArjunShankartty
设备,通常与控制台相关联。我怀疑错误消息是EPERM。 - cnicutar