我可以用strerror()
获取文本表示errno使用 CRT 函数后的值,例如fopen()
。如果我使用open()
Linux系统调用代替CRT函数,它还设置errno失败时的价值。申请是否正确strerror()
对此errno价值?如果没有,是否有一些 Linux 系统调用,其作用与strerror()
?
是的,您的代码可能类似于(未经测试):
#include <stdio.h>
#include <errno.h>
#include <string.h> // declares: char *strerror(int errnum);
FILE *
my_fopen ( char *path_to_file, char *mode ) {
FILE *fp;
char *errmsg;
if ( fp = fopen( path_to_file, mode )) {
errmsg = strerror( errno ); // fopen( ) failed, fp is set to NULL
printf( "%s %s\n", errmsg, path_to_file );
}
else { // fopen( ) succeeded
...
}
return fp; // return NULL (failed) or open file * on success
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)