open返回值-1是什么原因
来源:互联网 发布:美元指数数据下载 编辑:程序博客网 时间:2024/04/27 00:56
今天在调试代码的时候出现了一个问题
给出代码的例子来说明这个问题
代码如下:
#define DEV_NAME "/dev/sunxi-reg"
g_alloc_context->fd = open(DEV_NAME, O_RDWR,0);
if (g_alloc_context->fd <= 0){LOGE("open %s failed g_alloc_context->fd = %d\n", DEV_NAME,g_alloc_context->fd);goto ERROR_OUT;}
于是用这种方式进行调试
代码如下:
#include <stdio.h>#include <fcntl.h>#include <string.h>#include <errno.h>#define DEV_NAME "/dev/sunxi-reg"int main(void){ int flag=0; flag = open(DEV_NAME,O_RDWR,0); printf("%d %s\n",flag,strerror(errno)); return 0;}
可以看到这个没有这个设备 当open返回值为-1.
那么看看例外一种情况 成功打开的时候
#include <stdio.h>#include <fcntl.h>#include <string.h>#include <errno.h>#define DEV_NAME "/dev/disp"int main(void){ int flag=0; flag = open(DEV_NAME,O_RDWR,0); printf("%d %s\n",flag,strerror(errno)); return 0;}
运行的效果如图:
但是在系统下面确实有
这个里面到底是哪里的问题,那么可以判断应该是 linux设备驱动没有做好。
调试的时候能用strerror这种系统函数是非常方便快捷查到哪里出了问题。
所以后面要从驱动上入手。
0 0
- open返回值-1是什么原因
- window.open返回值
- window.open返回值
- OPEN()函数及返回值
- Window.Open参数、返回值
- Window.Open参数、返回值
- Window.Open参数、返回值
- Window.Open参数、返回值
- 是什么原因???
- evc 中提示:cannot open input file Ddraw.lib,是什么原因?
- open函数参数及返回值
- javascript 弹出窗口返回值 (open, showModalDialog)
- open函数参数及返回值
- open函数参数及返回值
- open函数参数以及返回值详解
- 【javascript】Window.Open参数、返回值
- window.open向父窗口返回值
- open函数参数及返回值
- HTML标签归类
- JavaSE_52th_正则表达式
- Unity 右键快捷进行SVN操作
- Dom引用
- 详解Virtual Box配置CentOS7网络
- open返回值-1是什么原因
- TCP/IP协议
- CLR查找和加载程序集的方式
- 定位流、z-index属性
- 判段1000-2000之间的闰年
- 多线程求π
- map 的用法
- Referer字段丢失问题
- SDWebImage使用,图片加载和缓存