diff options
author | Bruno Haible <bruno@clisp.org> | 2010-12-22 19:25:34 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2010-12-22 19:25:34 +0100 |
commit | e53e23a012113952499a70115d2ca26b2a33e2bf (patch) | |
tree | c5bb164ee5ca5bfd8f95f3398aaf2a4c3f1a1406 /lib | |
parent | f7fecbfc47c114a633f1fa754a0d9e1ad6cfc868 (diff) | |
download | gnulib-e53e23a012113952499a70115d2ca26b2a33e2bf.tar.gz |
getlogin_r: Work around portability problem on OSF/1.
* m4/getlogin_r.m4 (gl_FUNC_GETLOGIN_R): Detect the OSF/1 problem.
* lib/unistd.in.h (getlogin_r): Replace if REPLACE_GETLOGIN_R is set.
* lib/getlogin_r.c (getlogin_r): When getlogin_r exists, invoke it and
test for a truncated result.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize REPLACE_GETLOGIN_R.
* modules/unistd (Makefile.am): Substitute REPLACE_GETLOGIN_R.
* modules/getlogin_r (Depends-on): Add memchr.
* doc/posix-functions/getlogin_r.texi: Mention the OSF/1 problem.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/getlogin_r.c | 11 | ||||
-rw-r--r-- | lib/unistd.in.h | 13 |
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/getlogin_r.c b/lib/getlogin_r.c index c1e7435876..27b84048d1 100644 --- a/lib/getlogin_r.c +++ b/lib/getlogin_r.c @@ -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 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 @@ -39,6 +39,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 +60,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; diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 40ac3781de..1dd06bfa61 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -712,13 +712,22 @@ _GL_WARN_ON_USE (getlogin, "getlogin is unportable - " ${LOGNAME-$USER} on Unix platforms, $USERNAME on native Windows platforms. */ -# if !@HAVE_DECL_GETLOGIN_R@ +# if @REPLACE_GETLOGIN_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define getlogin_r rpl_getlogin_r +# endif +_GL_FUNCDECL_RPL (getlogin_r, int, (char *name, size_t size) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (getlogin_r, int, (char *name, size_t size)); +# else +# if !@HAVE_DECL_GETLOGIN_R@ _GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size) _GL_ARG_NONNULL ((1))); -# endif +# endif /* Need to cast, because on Solaris 10 systems, the second argument is int size. */ _GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size)); +# endif _GL_CXXALIASWARN (getlogin_r); #elif defined GNULIB_POSIXCHECK # undef getlogin_r |