[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gnulib] [bug-gnulib] New getlogin_r module
From: |
Bruno Haible |
Subject: |
Re: [bug-gnulib] [bug-gnulib] New getlogin_r module |
Date: |
Wed, 25 May 2005 12:51:25 +0200 |
User-agent: |
KMail/1.5 |
Derek Price wrote:
> +int
> +getlogin_r (char *name, size_t size)
> +{
> + char *n = getlogin ();
> + if (n)
> + {
> + size_t nlen = strlen (n);
> + if (nlen < size)
> + {
> + memcpy (name, n, nlen + 1);
> + return 0;
> + }
> + errno = ERANGE;
> + }
> + return -1;
> +}
The return value is incorrect, and the getlogin () return conventions are
ignored.
http://www.opengroup.org/onlinepubs/009695399/functions/getlogin.html
says:
"Upon successful completion, getlogin() shall return a pointer to the login
name or a null pointer if the user's login name cannot be found.
Otherwise, it shall return a null pointer and set errno to indicate the
error."
Which means, you need to set errno = 0 before calling getlogin(), to
distinguish two of the three cases.
And
"If successful, the getlogin_r() function shall return zero; otherwise,
an error number shall be returned to indicate the error."
So, instead of "errno = ERANGE; return -1; " you need to do "return ERANGE;".
Bruno