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


当前回答

这比在errno.h中查找代码要快,比这里发布的大多数解决方案都要短,并且不需要安装第三方工具:

perl -E 'say $!2 =转变'

收益率

没有这样的文件或目录

其他回答

可以使用strerror()为错误号获取一个人类可读的字符串。这与perror()打印的字符串相同,但如果要将错误消息格式化为标准错误输出以外的内容,则此字符串非常有用。

例如:

#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()。

您可以使用以下一行程序检索系统上的errno值的完整列表,而不是对所得到的任何错误代码运行perror:

cpp -dM /usr/include/errno.h | grep 'define E' | sort -n -k

它的意思是:

未找到文件或目录。

Call

perror("execl");

以防出错。

示例:

if(read(fd, buf, 1)==-1) {
    perror("read");
}

errno(3)和perror(3)的手册页也很有趣……

我在我的.bashrc文件中有以下函数-它从头文件中查找errno值(可以是/usr/include/errno.h, /usr/include/linux/errno.h,等等,等等)

如果头文件安装在机器上,它就可以工作;-)

通常头文件有一个错误+接下来是注释中的解释;以下内容:

./asm-generic/errno-base.h:#define EAGAIN 11 /*重试*/

function errno()
{
    local arg=$1

    if [[ "x$arg" == "x-h" ]]; then
        cat <<EOF
        Usage: errno <num>
        Prints text that describes errno error number
        EOF
    else
        pushd /usr/include
        find . -name "errno*.h" | xargs grep   "[[:space:]]${arg}[[:space:]]"
        popd
    fi
}