bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gnulib] Re: New getlogin_r module


From: Bruno Haible
Subject: [bug-gnulib] Re: New getlogin_r module
Date: Wed, 25 May 2005 19:57:03 +0200
User-agent: KMail/1.5

Derek Price wrote:
> This is what I installed.

Note that lib/ and m4/ have ChangeLogs of their own. Only the top-level
and modules/* modifications go into the top-level ChangeLog. Including
the update of MODULES.html.sh (adding one line for each new module).

Three further remarks:

- In the include file, you use size_t without including <stddef.h>. Won't
  work on platforms where unistd.h doesn't exist.

- The documentation: When a programmer wants to know what the function does,
  he doesn't need/want to know how the function is implemented. Patch
  appended.

- The code in getlogin_r.c: Why do you save and restore errno? It's useless,
  since 1. POSIX doesn't say that errno is preserved (generally it's the
  caller's duty to save errno if he wants to), 2. you don't restore it
  before "return errno;".

Bruno


diff -c -3 -r1.1 getlogin_r.h
*** lib/getlogin_r.h    25 May 2005 14:21:20 -0000      1.1
--- lib/getlogin_r.h    25 May 2005 17:56:24 -0000
***************
*** 18,23 ****
--- 18,25 ----
  
  /* Written by Paul Eggert and Derek Price.  */
  
+ #include <stddef.h>
+ 
  #if HAVE_UNISTD_H
  # include <unistd.h>
  #endif
***************
*** 28,35 ****
  
     Returns 0 if successful.  Upon error, an error number is returned, or -1 in
     the case that the login name cannot be found but no specific error is
!    provided by getlogin (getlogin returned NULL and did not set errno - this
!    case is hopefully rare but is left open by the POSIX spec).
  
     See 
<http://www.opengroup.org/onlinepubs/009695399/functions/getlogin.html>.
   */
--- 30,36 ----
  
     Returns 0 if successful.  Upon error, an error number is returned, or -1 in
     the case that the login name cannot be found but no specific error is
!    provided (this case is hopefully rare but is left open by the POSIX spec).
  
     See 
<http://www.opengroup.org/onlinepubs/009695399/functions/getlogin.html>.
   */
diff -c -3 -r1.1 getlogin_r.c
*** lib/getlogin_r.c    25 May 2005 14:21:20 -0000      1.1
--- lib/getlogin_r.c    25 May 2005 17:56:24 -0000
***************
*** 38,44 ****
  getlogin_r (char *name, size_t size)
  {
    char *n;
-   int save_errno = errno;
  
    errno = 0;
    n = getlogin ();
--- 38,43 ----
***************
*** 53,59 ****
        errno = ERANGE;
      }
  
!   if (errno) return errno;
!   errno = save_errno;
!   return -1;
  }
--- 52,56 ----
        errno = ERANGE;
      }
  
!   return (errno ? errno : -1);
  }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]