如何知道“errno"是什么意思? [英] How to know what the 'errno' means?

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

问题描述

当调用 execl(...) 时,我得到一个 errno=2.这是什么意思?我怎么知道这个errno的含义?

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

推荐答案

您可以使用 strerror() 获取错误编号的人类可读字符串.这与 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
", strerror(errno));
}

Linux 还支持显式线程安全变体 strerror_r().

Linux also supports the explicitly-threadsafe variant strerror_r().

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

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