开发者

getpwuid doesn't set errno

开发者 https://www.devze.com 2023-02-28 03:23 出处:网络
uid_t userId = getuid(); userId = 999;// cause error errno = 0; passwd* pw = getpwuid(userId); int n = errno;// pw = NULL, n = 0
    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.

0

精彩评论

暂无评论...
验证码 换一张
取 消