为什么linux内核linux read函数返回值出现错误,返回值是一个负数

本帖子已过去太久远了,不再提供回复功能。关注51Testing
谈谈Linux内核驱动的编码风格
发表于: 10:42 &作者:wwang & 来源:51Testing软件测试网原创
推荐标签:
  一些需要注意的Coding Style  缩进  1、除了注释、文档和Kconfig之外,使用Tab缩进,而不是空格,并且Tab的宽度为8个字符;  2、switch … case …语句中,switch和case具有相同的缩进(参考上文);  花括号  3、花括号的使用参考K&R风格。  如果是函数,左花括号另起一行:  int function(int x)  {  body of function  }  否则,花括号紧接在语句的最后:  if (x is true) {  we do y  }  如果只有一行语句,则不需要用花括号:  if (condition)  action();  但是,对于条件语句来说,如果一个分支是一行语句,另一个分支是多行,则需要保持一致,使用花括号:  if (condition) {  do_this();  do_that();  } else {  otherwise();  }  空格  4、在关键字“if, switch, case, for, do, while”之后需要加上空格,如:  if (something)  5、在关键字“sizeof, typeof, alignof, or __attribute__”之后不要加空格,如:  sizeof(struct file)  6、在括号里的表达式两边不要加空格,比如,下面是一个反面的例子:  sizeof( struct file )  7、大多说的二元和三元运算符两边需要空格,如“= + – & & * / % | & ^ &= &= == != ? :”;  8、一元运算符后面不要空格,如“& * + – ~ ! sizeof typeof alignof __attribute__ defined”;  9、在前缀自增自减运算符之后和后缀自增自减运算符之前不需要空格(“++”和“–”);  10、结构成员运算符(“.”和“-&”)的两边不需要空格;  11、行尾不需要空格;  注释  12、使用C89的“/* … */”风格而不是C99的“// …”风格;  13、对于多行注释,可以参考下例:  /*  * This is the preferred style for multi-line  * comments in the Linux kernel source code.  * Please use it consistently.  *  * Description: A column of asterisks on the left side,  * with beginning and ending almost-blank lines.  */  Kconfig  14、“config”定义下面的语句用Tab缩进,help下面的语句再额外缩进两个空格,如:  config AUDIT  bool "Auditing support"  depends on NET  help  Enable auditing infrastructure that can be used with another  kernel subsystem, such as SELinux (which requires this for  logging of avc messages output). Does not do system-call  auditing without CONFIG_AUDITSYSCALL.  宏  15、多行的宏定义需要用“do .. while”封装,如:  #define macrofun(a, b, c) \  do { \  if (a == 5) \  do_this(b, c); \  } while (0)  函数返回值  16、函数返回值的定义最好也要遵循一定的章法。  如果函数的名称是一种动作或者命令式的语句,应该以错误代码的形式返回(通常是0表示成功,-Exxx这种形式的负数表示错误),如:  do_something()  如果函数的名称是判断语句,则返回值应该类似与布尔值(通常1表示成功,0表示错误),如:  something_is_present()
java直播教学:
搜索风云榜
51Testing官方微信
51Testing官方微博
测试知识全知道温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(14119)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'Linux内核——open函数简介',
blogAbstract:'
1.表头文件 #include&sys/types.h&&&&&&&&&&&&&&& & &#include&sys/stat.h&&&&&&&&&&&&&&&&&& #include&fcntl.h&&
2.定义函数 int open( const char * pathname, int flags);&&&&&&&&&&&&&&&&& &int open( const char * pathname,int flags, mode_t mode);
&&&&&& 对于 open 函数来说,第三个参数(...)仅当创建新文件时才使用,用于指定文件的访问权限。pathname 是待打开/创建文件的路径名;oflag',
blogTag:'linux,open函数',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:1,
publishTime:6,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:true,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}linux中sys_open等内核函数的异常码怎么获得 - Linux/Unix当前位置:& &&&linux中sys_open等内核函数的异常码怎么获得linux中sys_open等内核函数的异常码怎么获得&&网友分享于:&&浏览:108次linux中sys_open等内核函数的错误码如何获得?syscalls.h中定义的比如sys_open等内核函数失败后返回值是-1但是错误码怎样获取呢?本来以为可以像上层应用一样包含errno.h直接取errno的值就行,结果驱动的errno.h根本没有这个变量用什么办法取得错误码呢?初学驱动开发,多多关照。------解决方案--------------------
SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, int, mode) // 这就是sys_open(){
ret = do_sys_open(AT_FDCWD, filename, flags, mode);}long do_sys_open(int dfd, const char __user *filename, int flags, int mode){
int fd = PTR_ERR(tmp);
if (!IS_ERR(tmp)) {
}}#define IS_ERR_VALUE(x) unlikely((x) &= (unsigned long)-MAX_ERRNO)由以上可知,错误值是直接返回的。
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有君,已阅读到文档的结尾了呢~~
广告剩余8秒
文档加载中
人力资源内核中各种出错函数处理的总结
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
人力资源内核中各种出错函数处理的总结
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer--144.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口}

我要回帖

更多关于 linux read函数返回值 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信