projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tests for module 'atexit'.
[gnulib.git]
/
lib
/
getlogin_r.c
diff --git
a/lib/getlogin_r.c
b/lib/getlogin_r.c
index
c02db2f
..
bb89f6e
100644
(file)
--- a/
lib/getlogin_r.c
+++ b/
lib/getlogin_r.c
@@
-1,6
+1,6
@@
/* Provide a working getlogin_r for systems which lack it.
/* Provide a working getlogin_r for systems which lack it.
- Copyright (C) 2005 Free Software Foundation, Inc.
+ Copyright (C) 2005
, 2006, 2007
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-18,24
+18,19
@@
/* written by Paul Eggert and Derek Price */
/* written by Paul Eggert and Derek Price */
-#if HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
-#include "getlogin_r.h"
+/* Specification. */
+#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <errno.h>
#include <string.h>
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
#if !HAVE_DECL_GETLOGIN
char *getlogin (void);
#endif
#if !HAVE_DECL_GETLOGIN
char *getlogin (void);
#endif
-/* See
getlogin_r
.h for documentation. */
+/* See
unistd_
.h for documentation. */
int
getlogin_r (char *name, size_t size)
{
int
getlogin_r (char *name, size_t size)
{
@@
-44,8
+39,15
@@
getlogin_r (char *name, size_t size)
errno = 0;
n = getlogin ();
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)
if (!n)
- return errno
? errno : ENOENT
;
+ return errno;
nlen = strlen (n);
if (size <= nlen)
return ERANGE;
nlen = strlen (n);
if (size <= nlen)
return ERANGE;