getpwuid return values and errno?

getpwuid return values and errno?

Post by Dragan Cvetkovi » Sun, 11 Nov 2001 05:13:51



                Hi,

If getpwuid() function can't find an entry with a given uid (and therefore
function returns NULL pointer) what should the value of errno be?

If I clear errno and call getpwuid() with uid that doesn't exist on my
system I notice the following behaviour:

On Solaris 8 errno remains 0, on Linux it is set to 2 (ENOENT), on AIX it is
set to 2 (ENOENT) on AIX 4.2 and to 3 (ESRCH) on AIX 4.3.

POSIX itself says the following: "A null pointer shall be returned if the
requested entry is not found, or an error occurs. On error, errno shall be
set to indicate the error."

Since POSIX (at least in latest draft) doesn't mention ENOENT or ESRCH as
possible errors, I assume that Solaris comes closest to POSIX, but am not
really sure if that is indeed the best behaviour (since it means that user
doesn't exists if function returns NULL _and_ errno is 0).

Bye, Dragan

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole

 
 
 

getpwuid return values and errno?

Post by Casper H.S. Dik - Network Security Engine » Sun, 11 Nov 2001 21:39:06


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>If getpwuid() function can't find an entry with a given uid (and therefore
>function returns NULL pointer) what should the value of errno be?

It should not be touched.

Quote:>POSIX itself says the following: "A null pointer shall be returned if the
>requested entry is not found, or an error occurs. On error, errno shall be
>set to indicate the error."

It seems that that wording isn't even ambiguous: an entry that is not
found shall result in NULL, but it is *NOT* an error.

Quote:>Since POSIX (at least in latest draft) doesn't mention ENOENT or ESRCH as
>possible errors, I assume that Solaris comes closest to POSIX, but am not
>really sure if that is indeed the best behaviour (since it means that user
>doesn't exists if function returns NULL _and_ errno is 0).

Well, it's the *only* standard conforming behaviour; clearly if errno needs
to distinguish between "error" (errno is set) and "no such user"
(errno is not set), errno MUST NOT BE CHANGED unless one of the actual
error condition arises.  That is the general rule for functions that
can have non-error return values that overlap error return values.

And that's what the common Unix specification says:

    Applications wishing to check for error situations should set errno to
    0 before calling getpwnam(). If getpwnam() returns a null pointer and
    errno is non-zero, an error occurred.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

getpwuid return values and errno?

Post by Dragan Cvetkov » Wed, 14 Nov 2001 00:11:01



> [[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


> >POSIX itself says the following: "A null pointer shall be returned if the
> >requested entry is not found, or an error occurs. On error, errno shall be
> >set to indicate the error."

> It seems that that wording isn't even ambiguous: an entry that is not
> found shall result in NULL, but it is *NOT* an error.

As always Caspar is right. The more I read POSIX wording the more I
agree with Casper.

Thanks, Dragan

 
 
 

1. Default return value for when return() is not explicitly used on SC5.0

I wrote the routine below to test some code in one of our
applications. This snippet exactly mirrors what is happening in our
real code. It was compiled on a sun-4 ultra platfrom using SC5.0 under
Solaris 5.6. If I pass the integer value of 2 as the first arguement
then control falls through the switch statement, and out of the
routine without explicitly returning any value. The compiler does not
report this as either a warning or an error. So far I have not been
unable to find anywhere in the documentation that specifies what the
return value from a routine will be if it is not explicitly given a
value to return. In my test, I wrote a short main to pass the values
(1,1), (1,2), and(2,1) to switchTest(int, int). The first 2 calls
returned the predictable results of TRUE and FALSE. The third call
also returned a FALSE, but that does not satisfy me that the return
value will always be FALSE.

bool switchTest(int num, int num2)
{
  switch(num) {
    case 1:
      switch(num2) {
      case 1:
        printf("CASE 1: Num = %d, Num2 = %d\n", num, num2);
        return(TRUE);
        break;
      default:
        printf("DEFAULT CASE: Num = %d, Num2 = %d\n", num, num2);
        return(FALSE);
      }
  }

Does anybody have the precise information on what the behaviour for
this compiler is defined to be for this situation?

Nick

2. Question: Video adjustment Problen On my Sun monitor

3. getpwuid() returning NULL?

4. HP694c

5. What include file has values of errno

6. Lost with UPD checksumming functions

7. Q: errno values of read/write/send/recv

8. Nasty console messages

9. mmap sets errno to strange value

10. How do threads do with errno values?

11. : What the hack is "ERESTART" errno value???

12. realloc() returns NULL, errno == 0

13. Q: TCP/IP accept returns -1, errno == ENOBUFS