bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] Suggestion: new module link


From: Bruno Haible
Subject: Re: [PATCH] Suggestion: new module link
Date: Sun, 18 Jan 2009 19:33:50 +0100
User-agent: KMail/1.9.9

Hello,

Martin Lambers wrote:
> I'd like to suggest a new module 'link' that provides the link(2)
> function for MinGW.

Your patch looks quite fine. I have applied it with this ChangeLog entry

2009-01-18  Martin Lambers  <address@hidden>

        New module 'link'.
        * lib/unistd.in.h (link): New declaration.
        * lib/link.c: New file.
        * m4/link.m4: New file.
        * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_LINK,
        HAVE_LINK.
        * modules/unistd (Makefile.am): Substitute GNULIB_LINK, HAVE_LINK.
        * modules/link: New file.
        * doc/posix-functions/link.texi: Mention the new module.

and a couple of trivial modifications:
  - Don't initialize GNULIB_UNLINK or HAVE_UNLINK - this is unrelated.
  - Don't say that mingw is a "cross-compiler". This is wrong in multiple ways,
    see <http://lists.gnu.org/archive/html/bug-gnulib/2008-10/msg00018.html>.
  - Use the GPL copyright notice in the file; the real copyright term is in
    the module description.
  - Update copyright years and *.m4 serial numbers.
  - In the module description, write 'link()' not 'link(2)': The MODULES.html.sh
    recognizes only a special syntax when placing HTML hyperlinks.
  - In the module description, list you as maintainer.
  - Update the documentation.

Do you have already copyright assignment papers for the gnulib project on file
with the FSF, or is this your first significant contribution to gnulib? I don't
remember it, and I cannot look into the GNU registry.

Bruno


From d1ed8a817f5d07d4013cfa0988ee2da8b2937db6 Mon Sep 17 00:00:00 2001
From: Martin Lambers <address@hidden>
Date: Sun, 18 Jan 2009 19:28:53 +0100
Subject: [PATCH] New module 'link'.

---
 ChangeLog                     |   12 ++++++
 doc/posix-functions/link.texi |    8 ++--
 lib/link.c                    |   83 +++++++++++++++++++++++++++++++++++++++++
 lib/unistd.in.h               |   19 +++++++++-
 m4/link.m4                    |   19 +++++++++
 m4/unistd_h.m4                |    6 ++-
 modules/link                  |   24 ++++++++++++
 modules/unistd                |    2 +
 8 files changed, 166 insertions(+), 7 deletions(-)
 create mode 100644 lib/link.c
 create mode 100644 m4/link.m4
 create mode 100644 modules/link

diff --git a/ChangeLog b/ChangeLog
index 929dcfc..ca3059e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-01-18  Martin Lambers  <address@hidden>
+
+       New module 'link'.
+       * lib/unistd.in.h (link): New declaration.
+       * lib/link.c: New file.
+       * m4/link.m4: New file.
+       * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_LINK,
+       HAVE_LINK.
+       * modules/unistd (Makefile.am): Substitute GNULIB_LINK, HAVE_LINK.
+       * modules/link: New file.
+       * doc/posix-functions/link.texi: Mention the new module.
+
 2009-01-18  Bruno Haible  <address@hidden>
 
        * tests/test-avltree_list.c (main): Call set_program_name.
diff --git a/doc/posix-functions/link.texi b/doc/posix-functions/link.texi
index 004ee7c..ace07cd 100644
--- a/doc/posix-functions/link.texi
+++ b/doc/posix-functions/link.texi
@@ -4,15 +4,15 @@
 
 POSIX specification: 
@url{http://www.opengroup.org/onlinepubs/9699919799/functions/link.html}
 
-Gnulib module: ---
+Gnulib module: link
 
 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
diff --git a/lib/link.c b/lib/link.c
new file mode 100644
index 0000000..6737d37
--- /dev/null
+++ b/lib/link.c
@@ -0,0 +1,83 @@
+/* Emulate link on platforms that lack it, namely native Windows platforms.
+
+   Copyright (C) 2009 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.  */
+
+#include <config.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+#define WIN32_LEAN_AND_MEAN
+#define _WIN32_WINNT 0x0500
+#include <unistd.h>
+#include <windows.h>
+
+#include <errno.h>
+
+int
+link (const char *path1, const char *path2)
+{
+  if (CreateHardLink (path2, path1, NULL) == 0)
+    {
+      /* It is not documented which errors CreateHardLink() can produce.
+       * The following conversions are based on tests on a Windows XP SP2
+       * system. */
+      DWORD err = GetLastError ();
+      switch (err)
+       {
+       case ERROR_ACCESS_DENIED:
+         errno = EACCES;
+         break;
+
+       case ERROR_INVALID_FUNCTION:    /* fs does not support hard links */
+         errno = EPERM;
+         break;
+
+       case ERROR_NOT_SAME_DEVICE:
+         errno = EXDEV;
+         break;
+
+       case ERROR_PATH_NOT_FOUND:
+       case ERROR_FILE_NOT_FOUND:
+         errno = ENOENT;
+         break;
+
+       case ERROR_INVALID_PARAMETER:
+         errno = ENAMETOOLONG;
+         break;
+
+       case ERROR_TOO_MANY_LINKS:
+         errno = EMLINK;
+         break;
+
+       case ERROR_ALREADY_EXISTS:
+         errno = EEXIST;
+         break;
+
+       default:
+         errno = EIO;
+       }
+      return -1;
+    }
+
+  return 0;
+}
+
+#else /* !Windows */
+
+#error "This platform lacks a link function, and Gnulib doesn't provide a 
replacement. This is a bug in Gnulib."
+
+#endif /* !Windows */
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 05778f9..52db71c 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -1,5 +1,5 @@
 /* Substitute for and wrapper around <unistd.h>.
-   Copyright (C) 2003-2008 Free Software Foundation, Inc.
+   Copyright (C) 2003-2009 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
@@ -475,6 +475,23 @@ extern int lchown (char const *file, uid_t owner, gid_t 
group);
 #endif
 
 
+#if @GNULIB_LINK@
+/* Create a new hard link for an existing file.
+   Return 0 if successful, otherwise -1 and errno set.
+   See POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/link.html>.  */
+# if address@hidden@
+extern int link (const char *path1, const char *path2);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef link
+# define link(path1,path2) \
+    (GL_LINK_WARNING ("link is unportable - " \
+                      "use gnulib module link for portability"), \
+     link (path1, path2))
+#endif
+
+
 #if @GNULIB_LSEEK@
 # if @REPLACE_LSEEK@
 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
diff --git a/m4/link.m4 b/m4/link.m4
new file mode 100644
index 0000000..349d537
--- /dev/null
+++ b/m4/link.m4
@@ -0,0 +1,19 @@
+# link.m4 serial 1
+dnl Copyright (C) 2009 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_FUNC_LINK],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_CHECK_FUNCS_ONCE([link])
+  if test $ac_cv_func_link = no; then
+    HAVE_LINK=0
+    AC_LIBOBJ([link])
+    gl_PREREQ_LINK
+  fi
+])
+
+# Prerequisites of lib/link.c.
+AC_DEFUN([gl_PREREQ_LINK], [:])
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
index 5685273..ff9a4ea 100644
--- a/m4/unistd_h.m4
+++ b/m4/unistd_h.m4
@@ -1,5 +1,5 @@
-# unistd_h.m4 serial 16
-dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
+# unistd_h.m4 serial 17
+dnl Copyright (C) 2006-2009 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.
@@ -48,6 +48,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   GNULIB_GETPAGESIZE=0;      AC_SUBST([GNULIB_GETPAGESIZE])
   GNULIB_GETUSERSHELL=0;     AC_SUBST([GNULIB_GETUSERSHELL])
   GNULIB_LCHOWN=0;           AC_SUBST([GNULIB_LCHOWN])
+  GNULIB_LINK=0;             AC_SUBST([GNULIB_LINK])
   GNULIB_LSEEK=0;            AC_SUBST([GNULIB_LSEEK])
   GNULIB_READLINK=0;         AC_SUBST([GNULIB_READLINK])
   GNULIB_SLEEP=0;            AC_SUBST([GNULIB_SLEEP])
@@ -63,6 +64,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   HAVE_GETHOSTNAME=1;     AC_SUBST([HAVE_GETHOSTNAME])
   HAVE_GETPAGESIZE=1;     AC_SUBST([HAVE_GETPAGESIZE])
   HAVE_GETUSERSHELL=1;    AC_SUBST([HAVE_GETUSERSHELL])
+  HAVE_LINK=1;            AC_SUBST([HAVE_LINK])
   HAVE_READLINK=1;        AC_SUBST([HAVE_READLINK])
   HAVE_SLEEP=1;           AC_SUBST([HAVE_SLEEP])
   HAVE_DECL_ENVIRON=1;    AC_SUBST([HAVE_DECL_ENVIRON])
diff --git a/modules/link b/modules/link
new file mode 100644
index 0000000..31d1af4
--- /dev/null
+++ b/modules/link
@@ -0,0 +1,24 @@
+Description:
+link() function: create a new link for an existing file
+
+Files:
+lib/link.c
+m4/link.m4
+
+Depends-on:
+unistd
+
+configure.ac:
+gl_FUNC_LINK
+gl_UNISTD_MODULE_INDICATOR([link])
+
+Makefile.am:
+
+Include:
+<unistd.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Martin Lambers
diff --git a/modules/unistd b/modules/unistd
index 225abf9..1359c52 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -40,6 +40,7 @@ unistd.h: unistd.in.h
              -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
              -e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \
              -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \
+             -e 's|@''GNULIB_LINK''@|$(GNULIB_LINK)|g' \
              -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
              -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
              -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
@@ -54,6 +55,7 @@ unistd.h: unistd.in.h
              -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
              -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
              -e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \
+             -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
              -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
              -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
              -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
-- 
1.5.6.3





reply via email to

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