getpwuid 未设置 errno

getpwuid doesn't set errno

本文关键字:errno 设置 getpwuid      更新时间:2023-10-16
uid_t userId=getuid((;userId=999;//原因错误errno=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。怎么了?

来自文档:

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

我看不出有什么问题。

根据您链接的文档:

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

因此,errno==0对于未找到的uid完全有效。