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: Paul Eggert
Subject: [bug-gnulib] Re: New getlogin_r module
Date: Fri, 27 May 2005 23:16:09 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Derek Price <address@hidden> writes:

> Section 7.1.4 of the C89 spec states, "The value of errno ... is never
> set to zero by any library function."  I am assuming that getlogin_r and
> probably most other GNULIB functions should act like library functions
> when possible?

It sounds reasonable to me to stick to the C convention for errno.
(Sorry, I'd forgotten that rule.)

On the other hand, there's no need to restore errno, and apps
shouldn't depend on its being preserved.

I installed this.  It should be enough to conform to the C convention,
right?

2005-05-27  Paul Eggert  <address@hidden>

        * getlogin_r.c (getlogin_r): Don't set errno to 0 on return.

Index: getlogin_r.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/getlogin_r.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -p -u -r1.2 -r1.3
--- getlogin_r.c        25 May 2005 19:14:06 -0000      1.2
+++ getlogin_r.c        28 May 2005 06:11:39 -0000      1.3
@@ -44,8 +44,15 @@ getlogin_r (char *name, size_t size)
 
   errno = 0;
   n = getlogin ();
+
+  /* A system function like getlogin_r is never supposed to set errno
+     to zero, so make sure errno is nonzero here.  ENOENT is a
+     reasonable errno value if getlogin returns NULL.  */
+  if (!errno)
+    errno = ENOENT;
+
   if (!n)
-    return errno ? errno : ENOENT;
+    return errno;
   nlen = strlen (n);
   if (size <= nlen)
     return ERANGE;




reply via email to

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