[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] new modules: getdomainname and xgetdomainname
From: |
Simon Josefsson |
Subject: |
[Bug-gnulib] new modules: getdomainname and xgetdomainname |
Date: |
Wed, 24 Sep 2003 02:59:11 +0200 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) |
What do you think? I noticed that I had been using getdomainname()
for a while, and never found a platform that complained, but it does
not seem to be part of POSIX or similar (help on checking that would
be appreciated). So I have not really tested this on a platform that
needs it, but it seems useful to have in case there is one.
Index: MODULES.html.sh
===================================================================
RCS file: /cvsroot/gnulib/gnulib/MODULES.html.sh,v
retrieving revision 1.38
diff -u -p -r1.38 MODULES.html.sh
--- MODULES.html.sh 17 Sep 2003 10:10:55 -0000 1.38
+++ MODULES.html.sh 24 Sep 2003 00:53:34 -0000
@@ -1822,6 +1822,8 @@ func_all_modules ()
func_begin_table
func_module gethostname
func_module xgethostname
+ func_module getdomainname
+ func_module xgetdomainname
func_module canon-host
func_end_table
Index: lib/getdomainname.c
===================================================================
RCS file: lib/getdomainname.c
diff -N lib/getdomainname.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/getdomainname.c 24 Sep 2003 00:53:34 -0000
@@ -0,0 +1,38 @@
+/* getdomainname emulation for systems that doesn't have it.
+ Copyright (C) 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* written by Simon Josefsson */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Get specification. */
+#include "getdomainname.h"
+
+/* Get strcpy. */
+#include <string.h>
+
+/* Put up to LEN chars of the domain name into NAME.
+ Null terminate it if the name is shorter than LEN.
+ Return 0 if ok, -1 if error. */
+int
+getdomainname (char *name, size_t len)
+{
+ strcpy (name, ""); /* Hardcode your domain name if you want. */
+ return 0;
+}
Index: lib/getdomainname.h
===================================================================
RCS file: lib/getdomainname.h
diff -N lib/getdomainname.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/getdomainname.h 24 Sep 2003 00:53:34 -0000
@@ -0,0 +1,35 @@
+/* getdomainname emulation for systems that doesn't have it.
+ Copyright (C) 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef _GETDOMAINNAME_H
+#define _GETDOMAINNAME_H
+
+#if HAVE_GETDOMAINNAME
+
+/* Get getdomainname() declarations. */
+# include <unistd.h>
+
+#else
+
+/* Put up to LEN chars of the domain name into NAME.
+ Null terminate it if the name is shorter than LEN.
+ Return 0 if ok, -1 if error. */
+extern int getdomainname(char *name, size_t len);
+
+#endif /* HAVE_GETDOMAINNAME */
+
+#endif /* _GETDOMAINNAME_H */
Index: lib/xgetdomainname.c
===================================================================
RCS file: lib/xgetdomainname.c
diff -N lib/xgetdomainname.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/xgetdomainname.c 24 Sep 2003 00:53:34 -0000
@@ -0,0 +1,72 @@
+/* xgetdomainname.c -- return current domain name with unlimited length
+ Copyright (C) 1992, 1996, 2000, 2001, 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* based on xgethostname.c written by Jim Meyering */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification. */
+#include "xgetdomainname.h"
+
+/* Get getdomainname. */
+#include "getdomainname.h"
+
+/* Get errno. */
+#include <errno.h>
+
+#include "xalloc.h"
+
+#ifndef INITIAL_DOMAINNAME_LENGTH
+# define INITIAL_DOMAINNAME_LENGTH 34
+#endif
+
+/* Return the current domain name in malloc'd storage.
+ If malloc fails, exit.
+ Upon any other failure, return NULL. */
+char *
+xgetdomainname (void)
+{
+ char *domainname;
+ size_t size;
+
+ size = INITIAL_DOMAINNAME_LENGTH;
+ domainname = xmalloc (size);
+ while (1)
+ {
+ int k = size - 1;
+ int err;
+
+ errno = 0;
+ domainname[k] = '\0';
+ err = getdomainname (domainname, size);
+ if (err >= 0 && domainname[k] == '\0')
+ break;
+ else if (err < 0 && errno != EINVAL)
+ {
+ int saved_errno = errno;
+ free (domainname);
+ errno = saved_errno;
+ return NULL;
+ }
+ size *= 2;
+ domainname = xrealloc (domainname, size);
+ }
+
+ return domainname;
+}
Index: lib/xgetdomainname.h
===================================================================
RCS file: lib/xgetdomainname.h
diff -N lib/xgetdomainname.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/xgetdomainname.h 24 Sep 2003 00:53:34 -0000
@@ -0,0 +1,26 @@
+/* xgetdomainname.h -- return current domain name with unlimited length
+ Copyright (C) 1992, 1996, 2000, 2001, 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef _XGETDOMAINNAME_H
+#define _XGETDOMAINNAME_H
+
+/* Return the current domain name in malloc'd storage.
+ If malloc fails, exit.
+ Upon any other failure, return NULL. */
+extern char *xgetdomainname (void);
+
+#endif /* _XGETDOMAINNAME_H */
Index: m4/getdomainname.m4
===================================================================
RCS file: m4/getdomainname.m4
diff -N m4/getdomainname.m4
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ m4/getdomainname.m4 24 Sep 2003 00:53:34 -0000
@@ -0,0 +1,23 @@
+# getdomainname.m4 serial 1
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_FUNC_GETDOMAINNAME],
+[
+ dnl Persuade glibc <unistd.h> to declare getdomainname().
+ AC_REQUIRE([AC_GNU_SOURCE])
+
+ AC_REPLACE_FUNCS(getdomainname)
+ if test $ac_cv_func_getdomainname = no; then
+ gl_PREREQ_GETDOMAINNAME
+ fi
+])
+
+# Prerequisites of lib/getdomainname.c.
+AC_DEFUN([gl_PREREQ_GETDOMAINNAME], [
+ :
+])
Index: modules/getdomainname
===================================================================
RCS file: modules/getdomainname
diff -N modules/getdomainname
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/getdomainname 24 Sep 2003 00:53:34 -0000
@@ -0,0 +1,21 @@
+Description:
+getdomainname() function: Return machine's NIS/YP domain name.
+
+Files:
+lib/getdomainname.h
+lib/getdomainname.c
+m4/getdomainname.m4
+
+Depends-on:
+
+configure.ac:
+gl_FUNC_GETDOMAINNAME
+
+Makefile.am:
+libfoo_la_SOURCES += getdomainname.h
+
+Include:
+
+Maintainer:
+all
+
Index: modules/xgetdomainname
===================================================================
RCS file: modules/xgetdomainname
diff -N modules/xgetdomainname
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/xgetdomainname 24 Sep 2003 00:53:34 -0000
@@ -0,0 +1,20 @@
+Description:
+Return machine's domainname, without size limitations.
+
+Files:
+lib/xgetdomainname.h
+lib/xgetdomainname.c
+
+Depends-on:
+getdomainname
+xalloc
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += xgetdomainname.h xgetdomainname.c
+
+Include:
+
+Maintainer:
+Simon Josefsson
- [Bug-gnulib] new modules: getdomainname and xgetdomainname,
Simon Josefsson <=