Mercurial > hg > octave-lojdl > gnulib-hg
changeset 5885:85592abdcf53
* lib/getlogin_r.c, lib/getlogin_r.h, m4/getlogin_r.m4,
modules/getlogin_r: New files.
author | Derek R. Price <derek@ximbiot.com> |
---|---|
date | Wed, 25 May 2005 14:21:20 +0000 |
parents | 04cd4acd6130 |
children | 775f86a9883a |
files | ChangeLog lib/getlogin_r.c lib/getlogin_r.h m4/getlogin_r.m4 modules/getlogin_r |
diffstat | 5 files changed, 158 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-05-25 Derek Price <derek@ximbiot.com> + Paul Eggert <eggert@cs.ucla.edu> + + * lib/getlogin_r.c, lib/getlogin_r.h, m4/getlogin_r.m4, + modules/getlogin_r: New files. + 2005-05-18 Derek Price <derek@ximbiot.com> * modules/minmax (Files): Add m4/minmax.m4.
new file mode 100644 --- /dev/null +++ b/lib/getlogin_r.c @@ -0,0 +1,59 @@ +/* Provide a working getlogin_r for systems which lack it. + + Copyright (C) 2005 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* written by Paul Eggert and Derek Price */ + +#include <config.h> + +#include "getlogin_r.h" + +#include <errno.h> +#include <string.h> + +#if HAVE_UNISTD_H +# include <unistd.h> +#endif + +#if !HAVE_DECL_GETLOGIN +char *getlogin (void); +#endif + +/* See getlogin_r.h for documentation. */ +int +getlogin_r (char *name, size_t size) +{ + char *n; + int save_errno = errno; + + errno = 0; + n = getlogin (); + if (n) + { + size_t nlen = strlen (n); + if (nlen < size) + { + memcpy (name, n, nlen + 1); + return 0; + } + errno = ERANGE; + } + + if (errno) return errno; + errno = save_errno; + return -1; +}
new file mode 100644 --- /dev/null +++ b/lib/getlogin_r.h @@ -0,0 +1,37 @@ +/* getlogin_r declaration + + Copyright (C) 2005 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert and Derek Price. */ + +#if HAVE_UNISTD_H +# include <unistd.h> +#endif + +#if !HAVE_DECL_GETLOGIN_R +/* Copies the user's login name to NAME. + The array pointed to by NAME has room for SIZE bytes. + + Returns 0 if successful. Upon error, an error number is returned, or -1 in + the case that the login name cannot be found but no specific error is + provided by getlogin (getlogin returned NULL and did not set errno - this + case is hopefully rare but is left open by the POSIX spec). + + See <http://www.opengroup.org/onlinepubs/009695399/functions/getlogin.html>. + */ +int getlogin_r (char *name, size_t size); +#endif
new file mode 100644 --- /dev/null +++ b/m4/getlogin_r.m4 @@ -0,0 +1,33 @@ +#serial 1 + +# Copyright (C) 2005 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +dnl From Derek Price +dnl +dnl Provide getlogin_r when the system lacks it. +dnl + +AC_DEFUN([gl_GETLOGIN_R_SUBSTITUTE], +[ + gl_PREREQ_GETLOGIN_R + AC_LIBSOURCE([getlogin_r.h]) + AC_LIBOBJ([getlogin_r]) +]) + +AC_DEFUN([gl_GETLOGIN_R], +[ + AC_REPLACE_FUNCS([getlogin_r]) + if test $ac_cv_func_strcasecmp = no; then + gl_GETLOGIN_R_SUBSTITUTE + fi +]) + +AC_DEFUN([gl_PREREQ_GETLOGIN_R], +[ + AC_CHECK_HEADERS_ONCE([unistd.h]) + AC_CHECK_DECLS_ONCE([getlogin getlogin_r]) +])
new file mode 100644 --- /dev/null +++ b/modules/getlogin_r @@ -0,0 +1,23 @@ +Description: +Get user name to a buffer allocated by the caller. + +Files: +lib/getlogin_r.h +lib/getlogin_r.c +m4/getlogin_r.m4 + +Depends-on: + +configure.ac: +gl_GETLOGIN_R + +Makefile.am: + +Include: +"getlogin_r.h" + +License: +LGPL + +Maintainer: +all