bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gnulib] New getlogin_r module


From: Derek Price
Subject: [bug-gnulib] New getlogin_r module
Date: Tue, 24 May 2005 22:51:34 -0400
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Per your suggestion, Paul, I've attached a getlogin_r module for
review.  It compiles and works here as gl_GETLOGIN_R or
gl_GETLOGIN_R_SUBSTITUTE.

Regards,

Derek
Index: lib/getlogin_r.c
===================================================================
RCS file: lib/getlogin_r.c
diff -N lib/getlogin_r.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/getlogin_r.c    25 May 2005 02:52:04 -0000
@@ -0,0 +1,51 @@
+/* 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
+
+int
+getlogin_r (char *name, size_t size)
+{
+  char *n = getlogin ();
+  if (n)
+    {
+      size_t nlen = strlen (n);
+      if (nlen < size)
+        {
+          memcpy (name, n, nlen + 1);
+          return 0;
+        }
+      errno = ERANGE;
+    }
+  return -1;
+}
Index: lib/getlogin_r.h
===================================================================
RCS file: lib/getlogin_r.h
diff -N lib/getlogin_r.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/getlogin_r.h    25 May 2005 02:52:04 -0000
@@ -0,0 +1,27 @@
+/* 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
+int getlogin_r (char *name, size_t size);
+#endif
Index: m4/getlogin_r.m4
===================================================================
RCS file: m4/getlogin_r.m4
diff -N m4/getlogin_r.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ m4/getlogin_r.m4    25 May 2005 02:52:04 -0000
@@ -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])
+])
Index: modules/getlogin_r
===================================================================
RCS file: modules/getlogin_r
diff -N modules/getlogin_r
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ modules/getlogin_r  25 May 2005 02:52:04 -0000
@@ -0,0 +1,24 @@
+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:
+memcpy
+
+configure.ac:
+gl_GETLOGIN_R
+
+Makefile.am:
+
+Include:
+"getlogin_r.h"
+
+License:
+LGPL
+
+Maintainer:
+all

reply via email to

[Prev in Thread] Current Thread [Next in Thread]