/* written by Paul Eggert and Derek Price */
-#if HAVE_CONFIG_H
+#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <string.h>
-
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
+#include <unistd.h>
#if !HAVE_DECL_GETLOGIN
char *getlogin (void);
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;