uid_t userId = getuid(); userId = 999; // cause error 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。有什么问题?
答案 0 :(得分:4)
来自文档:
ERRORS 0 or ENOENT or ESRCH or EBADF or EPERM or ... The given name or uid was not found.
我没有看到问题。
答案 1 :(得分:3)
根据您链接的文档:
0 or ENOENT or ESRCH or EBADF or EPERM or ...
The given name or uid was not found.
所以errno == 0对于找不到的uid完全有效。