如何知道什么是'错误号'的意思? [英] How to know what the 'errno' means?

查看:129
本文介绍了如何知道什么是'错误号'的意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当调用 EXECL(...),我得到一个错误号= 2 。这是什么意思?我怎么能知道这是什么意思错误号

When calling execl(...), I get an errno=2. What does it mean? How can I know the meaning of this errno?

推荐答案

您可以使用 字符串错误() 以获取错误编号的人类可读的字符串。这是 PERROR() 但如果你格式化错误信息比标准错误输出以外的东西是有用的。

You can use strerror() to get a human-readable string for the error number. This is the same string printed by perror() but it's useful if you're formatting the error message for something other than standard error output.

例如:

#include <errno.h>
#include <string.h>

/* ... */

if(read(fd, buf, 1)==-1) {
    printf("Oh dear, something went wrong with read()! %s\n", strerror(errno));
}

Linux还支持明确线程安全的变体 strerror_r()

这篇关于如何知道什么是'错误号'的意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆