getpwuid函数不会设置errno变量。

3
uid_t userId = getuid();
userId = 999;               // 引起错误
errno = 0; passwd* pw = getpwuid(userId);
int n = errno; // pw = NULL, n = 0

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

2个回答

4

根据文档:

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

我看不出有什么问题。


3
根据您提供的文档:

根据您提供的文档:

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

因此,errno == 0 在未找到 uid 的情况下是完全有效的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接