getpwuid doesn't set errno
uid_t userId = getuid(); userId = 999; // cause error errno = 0; passwd* pw = getpwuid(userId); int n = errno; // pw = NULL, n = 0
Runn开发者_开发技巧ing this code in Linux, I get pw = NULL (expected), and errno = 0. According to Linux documentation http://linuxmanpages.com/man3/getpwuid.3.php, getpwuid must set errno. What is wrong?
From the documentation:
ERRORS 0 or ENOENT or ESRCH or EBADF or EPERM or ... The given name or uid was not found.
I fail to see a problem.
According to the documentation you linked:
0 or ENOENT or ESRCH or EBADF or EPERM or ...
The given name or uid was not found.
So errno == 0 is perfectly valid for a uid not found.
精彩评论