[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
new module 'getlogin'
From: |
Bruno Haible |
Subject: |
new module 'getlogin' |
Date: |
Sat, 9 Jan 2010 16:21:46 +0100 |
User-agent: |
KMail/1.9.9 |
John W. Eaton wrote:
> getlogin doesn't exist on Windows systems.
>
> What would be the preferred way of fixing this problem? Should there
> be a separate getlogin module?
Even though getlogin_r does not require a 'getlogin' module, it is indeed
fairly easy to add:
2010-01-09 Bruno Haible <address@hidden>
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 <address@hidden>.
=============================== lib/getlogin.c ===============================
/* 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 <http://www.gnu.org/licenses/>. */
/* Written by Bruno Haible, 2010. */
#include <config.h>
/* Specification. */
#include <unistd.h>
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#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;
}
=============================== m4/getlogin.m4 ===============================
# 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
])
============================== modules/getlogin ==============================
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:
<unistd.h>
License:
LGPLv2+
Maintainer:
all
===============================================================================
--- doc/posix-functions/getlogin.texi.orig Sat Jan 9 16:12:51 2010
+++ doc/posix-functions/getlogin.texi Sat Jan 9 15:15:18 2010
@@ -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
address@hidden
+This function is missing on some platforms:
+mingw.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
address@hidden
-This function is missing on some platforms:
-mingw.
@end itemize
--- lib/unistd.in.h.orig Sat Jan 9 16:12:51 2010
+++ lib/unistd.in.h Sat Jan 9 15:15:18 2010
@@ -476,6 +476,29 @@
#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 <http://www.opengroup.org/susv3xsh/getlogin.html>.
+
+ 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 address@hidden@
+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.
--- m4/unistd_h.m4.orig Sat Jan 9 16:12:51 2010
+++ m4/unistd_h.m4 Sat Jan 9 15:15:18 2010
@@ -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 @@
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 @@
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])
--- modules/unistd.orig Sat Jan 9 16:12:51 2010
+++ modules/unistd Sat Jan 9 15:15:18 2010
@@ -42,6 +42,7 @@
-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 @@
-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' \