From: Derek R. Price Date: Wed, 25 May 2005 14:21:20 +0000 (+0000) Subject: * lib/getlogin_r.c, lib/getlogin_r.h, m4/getlogin_r.m4, X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=118ba24d049832db7affcd30bed4209cb37b2b30;p=pspp * lib/getlogin_r.c, lib/getlogin_r.h, m4/getlogin_r.m4, modules/getlogin_r: New files. --- diff --git a/ChangeLog b/ChangeLog index 40eb5a4aa3..7d6aca4955 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-05-25 Derek Price + Paul Eggert + + * lib/getlogin_r.c, lib/getlogin_r.h, m4/getlogin_r.m4, + modules/getlogin_r: New files. + 2005-05-18 Derek Price * modules/minmax (Files): Add m4/minmax.m4. diff --git a/lib/getlogin_r.c b/lib/getlogin_r.c new file mode 100644 index 0000000000..5683504c7d --- /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 + +#include "getlogin_r.h" + +#include +#include + +#if HAVE_UNISTD_H +# include +#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; +} diff --git a/lib/getlogin_r.h b/lib/getlogin_r.h new file mode 100644 index 0000000000..d6f31beb2e --- /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 +#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 . + */ +int getlogin_r (char *name, size_t size); +#endif diff --git a/m4/getlogin_r.m4 b/m4/getlogin_r.m4 new file mode 100644 index 0000000000..b1d9c59ba3 --- /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]) +]) diff --git a/modules/getlogin_r b/modules/getlogin_r new file mode 100644 index 0000000000..7a6f6515a7 --- /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