NEWS.stable: log cherry-pick [e446f25]->[c092018] relocatable-shell: Update suggested...
[gnulib.git] / lib / getlogin_r.c
index c1e7435..ac4f495 100644 (file)
@@ -1,6 +1,6 @@
 /* Provide a working getlogin_r for systems which lack it.
 
-   Copyright (C) 2005-2007, 2009-2010 Free Software Foundation, Inc.
+   Copyright (C) 2005-2007, 2010-2014 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
@@ -13,8 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
 
 /* Written by Paul Eggert, Derek Price, and Bruno Haible.  */
 
@@ -39,6 +38,7 @@ extern char *getlogin (void);
 int
 getlogin_r (char *name, size_t size)
 {
+#undef getlogin_r
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
   /* Native Windows platform.  */
   DWORD sz;
@@ -59,6 +59,14 @@ getlogin_r (char *name, size_t size)
         return ENOENT;
     }
   return 0;
+#elif HAVE_GETLOGIN_R
+  /* Platform with a getlogin_r() function.  */
+  int ret = getlogin_r (name, size);
+
+  if (ret == 0 && memchr (name, '\0', size) == NULL)
+    /* name contains a truncated result.  */
+    return ERANGE;
+  return ret;
 #else
   /* Platform with a getlogin() function.  */
   char *n;