【问题标题】:getpwuid doesn't set errnogetpwuid 没有设置 errno
【发布时间】:2011-04-24 06:58:18
【问题描述】:
uid_t userId = getuid(); 用户 ID = 999; // 导致错误 错误号 = 0; passwd* pw = getpwuid(userId); int n = 错误号; // pw = NULL, n = 0

在 Linux 中运行此代码,我得到 pw = NULL(预期)和 errno = 0。根据 Linux 文档http://linuxmanpages.com/man3/getpwuid.3.php,getpwuid 必须设置 errno。怎么了?

【问题讨论】:

    标签: c++ linux errno


    【解决方案1】:

    来自文档:

    ERRORS
             0 or ENOENT or ESRCH or EBADF or EPERM or ...
                    The given name or uid was not found.
    

    我没有发现问题。

    【讨论】:

      【解决方案2】:

      根据您链接的文档:

         0 or ENOENT or ESRCH or EBADF or EPERM or ...
                The given name or uid was not found.
      

      所以 errno == 0 对于未找到的 uid 完全有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-29
        • 2014-05-01
        • 2012-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-09
        • 2017-05-29
        相关资源
        最近更新 更多