Alex F
Alex F

Reputation: 43321

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

Running 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?

Upvotes: 3

Views: 730

Answers (2)

Douglas Leeder
Douglas Leeder

Reputation: 53320

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.

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799082

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.

Upvotes: 4

Related Questions