Derek Price <[EMAIL PROTECTED]> 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  <[EMAIL PROTECTED]>

        * 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;


_______________________________________________
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib

Reply via email to