From: Bruno Haible Date: Sat, 9 Jan 2010 15:17:50 +0000 (+0100) Subject: New module 'getlogin'. X-Git-Tag: v0.1~4874 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=907734847df6aad325f2d43f5d37367ef1fb6e19;p=gnulib.git New module 'getlogin'. --- diff --git a/ChangeLog b/ChangeLog index 8f2227384..fa51e1428 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2010-01-09 Bruno Haible + New module 'getlogin'. + * lib/unistd.in.h (getlogin): New declaration. + * lib/getlogin.c: New file. + * m4/getlogin.m4: New file. + * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_GETLOGIN, + HAVE_GETLOGIN. + * modules/unistd (Makefile.am): Substitute GNULIB_GETLOGIN, + HAVE_GETLOGIN. + * modules/getlogin: New file. + * doc/posix-functions/getlogin.texi: Mention the new module. + Reported by John W. Eaton . + +2010-01-09 Bruno Haible + getlogin_r: Support for native Windows. * lib/getlogin_r.c: Include (getlogin_r): Implement for native Windows. diff --git a/doc/posix-functions/getlogin.texi b/doc/posix-functions/getlogin.texi index 1c422c077..b7aebedad 100644 --- a/doc/posix-functions/getlogin.texi +++ b/doc/posix-functions/getlogin.texi @@ -4,15 +4,15 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/getlogin.html} -Gnulib module: --- +Gnulib module: getlogin Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +mingw. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -mingw. @end itemize diff --git a/lib/getlogin.c b/lib/getlogin.c new file mode 100644 index 000000000..6c79de64e --- /dev/null +++ b/lib/getlogin.c @@ -0,0 +1,41 @@ +/* Provide a working getlogin for systems which lack it. + + Copyright (C) 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 + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + 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, see . */ + +/* Written by Bruno Haible, 2010. */ + +#include + +/* Specification. */ +#include + +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +# define WIN32_LEAN_AND_MEAN +# include +#endif + +char * +getlogin (void) +{ +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + static char login_name[1024]; + DWORD sz = sizeof (login_name); + + if (GetUserName (login_name, &sz)) + return login_name; +#endif + return NULL; +} diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 3e22d8def..a353b0c08 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -476,6 +476,29 @@ extern int gethostname(char *name, size_t len) _GL_ARG_NONNULL ((1)); #endif +#if @GNULIB_GETLOGIN@ +/* Returns the user's login name, or NULL if it cannot be found. Upon error, + returns NULL with errno set. + + See . + + Most programs don't need to use this function, because the information is + available through environment variables: + ${LOGNAME-$USER} on Unix platforms, + $USERNAME on native Windows platforms. + */ +# if !@HAVE_GETLOGIN@ +extern char *getlogin (void); +# endif +#elif defined GNULIB_POSIXCHECK +# undef getlogin +# define getlogin() \ + (GL_LINK_WARNING ("getlogin is unportable - " \ + "use gnulib module getlogin for portability"), \ + getlogin ()) +#endif + + #if @GNULIB_GETLOGIN_R@ /* Copies the user's login name to NAME. The array pointed to by NAME has room for SIZE bytes. diff --git a/m4/getlogin.m4 b/m4/getlogin.m4 new file mode 100644 index 000000000..e47967d05 --- /dev/null +++ b/m4/getlogin.m4 @@ -0,0 +1,15 @@ +# getlogin.m4 serial 1 +dnl Copyright (C) 2010 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_GETLOGIN], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_CHECK_FUNCS_ONCE([getlogin]) + if test $ac_cv_func_getlogin = no; then + AC_LIBOBJ([getlogin]) + HAVE_GETLOGIN=0 + fi +]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index ff522b0b0..f3074ea8a 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 36 +# unistd_h.m4 serial 37 dnl Copyright (C) 2006-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -48,6 +48,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], GNULIB_GETDTABLESIZE=0; AC_SUBST([GNULIB_GETDTABLESIZE]) GNULIB_GETGROUPS=0; AC_SUBST([GNULIB_GETGROUPS]) GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME]) + GNULIB_GETLOGIN=0; AC_SUBST([GNULIB_GETLOGIN]) GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R]) GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE]) GNULIB_GETUSERSHELL=0; AC_SUBST([GNULIB_GETUSERSHELL]) @@ -82,6 +83,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE]) HAVE_GETGROUPS=1; AC_SUBST([HAVE_GETGROUPS]) HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME]) + HAVE_GETLOGIN=1; AC_SUBST([HAVE_GETLOGIN]) HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE]) HAVE_GETUSERSHELL=1; AC_SUBST([HAVE_GETUSERSHELL]) HAVE_LCHOWN=1; AC_SUBST([HAVE_LCHOWN]) diff --git a/modules/getlogin b/modules/getlogin new file mode 100644 index 000000000..1e0c77abd --- /dev/null +++ b/modules/getlogin @@ -0,0 +1,24 @@ +Description: +getlogin() function: Get user name. + +Files: +lib/getlogin.c +m4/getlogin.m4 + +Depends-on: +unistd + +configure.ac: +gl_GETLOGIN +gl_UNISTD_MODULE_INDICATOR([getlogin]) + +Makefile.am: + +Include: + + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/unistd b/modules/unistd index 3ee8f3144..f55783745 100644 --- a/modules/unistd +++ b/modules/unistd @@ -42,6 +42,7 @@ unistd.h: unistd.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \ -e 's|@''GNULIB_GETGROUPS''@|$(GNULIB_GETGROUPS)|g' \ -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \ + -e 's|@''GNULIB_GETLOGIN''@|$(GNULIB_GETLOGIN)|g' \ -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \ -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \ -e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \ @@ -75,6 +76,7 @@ unistd.h: unistd.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H) -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \ -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \ -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \ + -e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \ -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ -e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \ -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \