bug-gnulib
[Top][All Lists]
Advanced

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

mkdir vs. GPL


From: Eric Blake
Subject: mkdir vs. GPL
Date: Thu, 29 Oct 2009 18:27:29 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

The mkdir module is LGPLv2+, but dragged in some GPL stuff.  In addition to the 
licensing problems this represents, I'm also getting link failures on the 
gnulib-tests directory of coreutils on cygwin 1.5:

  CCLD   test-areadlink.exe
../lib/libcoreutils.a(xalloc-die.o): In function `xalloc_die':
/home/eblake/coreutils-tmp/lib/xalloc-die.c:34: undefined reference to 
`_libintl_gettext'
../lib/libcoreutils.a(error.o): In function `print_errno_message':
/home/eblake/coreutils-tmp/lib/error.c:127: undefined reference to 
`_libintl_gettext'
collect2: ld returned 1 exit status

test-areadlink.c pulled in rpl_mkdir, which in turn exploded into xalloc 
dependencies, all which seem rather extreme for a simple system call which 
shouldn't call exit() in the first place.  Here's what I'm proposing to fix 
it.  Jim, Paul - are you okay with weakening the license on portions of the 
dirname and filenamecat modules?  Meanwhile, the only reason the rename module 
was GPL was because of its use of dirname; it fits in the same category as 
mkdir of a low-level syscall that should be usable anywhere.

Eric Blake (5):
      [1/5] mkdir: make safe for libraries
Don't use xstrdup; it can exit().

      [2/5] dirname: split into dirname-lgpl
I've been threatening this for a while.  dirname.h seems like it should be 
usable in LGPL files (particularly since we now have a lot of syscall wrappers 
that want to manage trailing slash bugs), but dirname.c calls xalloc which 
implies GPL.  The split seems pretty straightforward, if everyone agrees.

      [3/5] dirname-lgpl: adjust clients that don't need full dirname
Fallout from the split.  In particular, test-mkdir and test-rename no longer 
need libintl.  Meanwhile, openat and friends no longer drag in dirname, but 
still drag in xalloc due to openat-die.

      [4/5] filenamecat: split into filenamecat-lgpl
filenamecat wasn't as pervasive as dirname, but the idea of the split is the 
same.

      [5/5] filenamecat-lgpl: adjust clients
Fallout from the split.

Still to go - LGPL argp still depends on the GPL dirname module, because it 
uses base_name (which xmallocs).  I can switch it to use last_component 
instead, but will have to audit all clients that used __argp_dir_name to ensure 
they are still correct.


>From edb6f303ff181d6a244a0e8d3fd0367b02260d7f Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 29 Oct 2009 09:37:42 -0600
Subject: [PATCH 1/5] mkdir: make safe for libraries

* modules/mkdir (Depends-on): Drop xalloc.
* lib/mkdir.c (rpl_mkdir): Fail with ENOMEM rather than calling
exit.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog     |    5 +++++
 lib/mkdir.c   |    8 +++++++-
 modules/mkdir |    1 -
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bda6fbb..27528cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-10-29  Eric Blake  <address@hidden>

+       mkdir: make safe for libraries
+       * modules/mkdir (Depends-on): Drop xalloc.
+       * lib/mkdir.c (rpl_mkdir): Fail with ENOMEM rather than calling
+       exit.
+
        tests: avoid some compiler warnings
        * tests/test-getaddrinfo.c (simple): Mark static, and allow string
        literals.
diff --git a/lib/mkdir.c b/lib/mkdir.c
index 3d9f043..e6dbc78 100644
--- a/lib/mkdir.c
+++ b/lib/mkdir.c
@@ -56,7 +56,13 @@ rpl_mkdir (char const *dir, mode_t mode maybe_unused)

   if (len && dir[len - 1] == '/')
     {
-      tmp_dir = xstrdup (dir);
+      tmp_dir = strdup (dir);
+      if (!tmp_dir)
+        {
+          /* Rather than rely on strdup-posix, we set errno ourselves.  */
+          errno = ENOMEM;
+          return -1;
+        }
       strip_trailing_slashes (tmp_dir);
     }
   else
diff --git a/modules/mkdir b/modules/mkdir
index 59d60fb..fa0931d 100644
--- a/modules/mkdir
+++ b/modules/mkdir
@@ -7,7 +7,6 @@ m4/mkdir.m4

 Depends-on:
 sys_stat
-xalloc
 dirname

 configure.ac:
-- 
1.6.4.2


>From fa022e7adcea017f5569261d04716dc00963db1d Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 29 Oct 2009 10:43:31 -0600
Subject: [PATCH 2/5] dirname: split into dirname-lgpl

* modules/dirname-lgpl: New module.
* modules/dirname (Files): Move library-safe files into
dirname-lgpl.
(Depends-on): Add dirname-lgpl.
(configure.ac): Declare witness.
* modules/double-slash-root (License): Relax license.
* lib/dirname.h (base_name, dir_name): Only declare when using GPL
module.
* lib/dirname.c (dir_len, mdir_name): Move...
* lib/dirname-lgpl.c: ...into new file.
* lib/basename.c (last_component, base_len): Move...
* lib/basename-lgpl.c: ...into new file.
* m4/dirname.m4 (gl_DIRNAME_LGPL): New macro.
(gl_DIRNAME): Use it.
* MODULES.html.sh (Enhancements for POSIX:2008 functions):
Mention new module.
* modules/dirname-tests (Depends-on): Add progname.
* tests/test-dirname.c (program_name): Delete.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog                         |   20 ++++++++++
 MODULES.html.sh                   |    1 +
 lib/basename-lgpl.c               |   75 +++++++++++++++++++++++++++++++++++++
 lib/basename.c                    |   74 +-----------------------------------
 lib/{dirname.c => dirname-lgpl.c} |   34 +++++------------
 lib/dirname.c                     |   64 +-------------------------------
 lib/dirname.h                     |    5 ++-
 m4/dirname.m4                     |   14 +++++-
 modules/dirname                   |    9 +---
 modules/{dirname => dirname-lgpl} |   13 +++---
 modules/dirname-tests             |    1 +
 modules/double-slash-root         |    2 +-
 tests/test-dirname.c              |    2 -
 13 files changed, 135 insertions(+), 179 deletions(-)
 create mode 100644 lib/basename-lgpl.c
 copy lib/{dirname.c => dirname-lgpl.c} (78%)
 copy modules/{dirname => dirname-lgpl} (69%)

diff --git a/ChangeLog b/ChangeLog
index 27528cb..26a0abf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
 2009-10-29  Eric Blake  <address@hidden>

+       dirname: split into dirname-lgpl
+       * modules/dirname-lgpl: New module.
+       * modules/dirname (Files): Move library-safe files into
+       dirname-lgpl.
+       (Depends-on): Add dirname-lgpl.
+       (configure.ac): Declare witness.
+       * modules/double-slash-root (License): Relax license.
+       * lib/dirname.h (base_name, dir_name): Only declare when using GPL
+       module.
+       * lib/dirname.c (dir_len, mdir_name): Move...
+       * lib/dirname-lgpl.c: ...into new file.
+       * lib/basename.c (last_component, base_len): Move...
+       * lib/basename-lgpl.c: ...into new file.
+       * m4/dirname.m4 (gl_DIRNAME_LGPL): New macro.
+       (gl_DIRNAME): Use it.
+       * MODULES.html.sh (Enhancements for POSIX:2008 functions):
+       Mention new module.
+       * modules/dirname-tests (Depends-on): Add progname.
+       * tests/test-dirname.c (program_name): Delete.
+
        mkdir: make safe for libraries
        * modules/mkdir (Depends-on): Drop xalloc.
        * lib/mkdir.c (rpl_mkdir): Fail with ENOMEM rather than calling
diff --git a/MODULES.html.sh b/MODULES.html.sh
index 62abf0f..d8677e0 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2404,6 +2404,7 @@ func_all_modules ()
   func_module chdir-long
   func_module dirent-safer
   func_module dirname
+  func_module dirname-lgpl
   func_module getopt
   func_module iconv_open-utf
   func_module unistd-safer
diff --git a/lib/basename-lgpl.c b/lib/basename-lgpl.c
new file mode 100644
index 0000000..444f042
--- /dev/null
+++ b/lib/basename-lgpl.c
@@ -0,0 +1,75 @@
+/* basename.c -- return the last element in a file name
+
+   Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006,
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include "dirname.h"
+
+#include <string.h>
+
+/* Return the address of the last file name component of NAME.  If
+   NAME has no relative file name components because it is a file
+   system root, return the empty string.  */
+
+char *
+last_component (char const *name)
+{
+  char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
+  char const *p;
+  bool saw_slash = false;
+
+  while (ISSLASH (*base))
+    base++;
+
+  for (p = base; *p; p++)
+    {
+      if (ISSLASH (*p))
+        saw_slash = true;
+      else if (saw_slash)
+        {
+          base = p;
+          saw_slash = false;
+        }
+    }
+
+  return (char *) base;
+}
+
+/* Return the length of the basename NAME.  Typically NAME is the
+   value returned by base_name or last_component.  Act like strlen
+   (NAME), except omit all trailing slashes.  */
+
+size_t
+base_len (char const *name)
+{
+  size_t len;
+  size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
+
+  for (len = strlen (name);  1 < len && ISSLASH (name[len - 1]);  len--)
+    continue;
+
+  if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
+      && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
+    return 2;
+
+  if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
+      && len == prefix_len && ISSLASH (name[prefix_len]))
+    return prefix_len + 1;
+
+  return len;
+}
diff --git a/lib/basename.c b/lib/basename.c
index 426ed40..a6403f5 100644
--- a/lib/basename.c
+++ b/lib/basename.c
@@ -1,7 +1,7 @@
 /* basename.c -- return the last element in a file name

-   Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free
-   Software Foundation, Inc.
+   Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006,
+   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
@@ -24,52 +24,6 @@
 #include "xalloc.h"
 #include "xstrndup.h"

-/* Return the address of the last file name component of NAME.  If
-   NAME has no relative file name components because it is a file
-   system root, return the empty string.  */
-
-char *
-last_component (char const *name)
-{
-  char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
-  char const *p;
-  bool saw_slash = false;
-
-  while (ISSLASH (*base))
-    base++;
-
-  for (p = base; *p; p++)
-    {
-      if (ISSLASH (*p))
-       saw_slash = true;
-      else if (saw_slash)
-       {
-         base = p;
-         saw_slash = false;
-       }
-    }
-
-  return (char *) base;
-}
-
-
-/* In general, we can't use the builtin `basename' function if available,
-   since it has different meanings in different environments.
-   In some environments the builtin `basename' modifies its argument.
-
-   Return the last file name component of NAME, allocated with
-   xmalloc.  On systems with drive letters, a leading "./"
-   distinguishes relative names that would otherwise look like a drive
-   letter.  Unlike POSIX basename(), NAME cannot be NULL,
-   base_name("") returns "", and the first trailing slash is not
-   stripped.
-
-   If lstat (NAME) would succeed, then { chdir (dir_name (NAME));
-   lstat (base_name (NAME)); } will access the same file.  Likewise,
-   if the sequence { chdir (dir_name (NAME));
-   rename (base_name (NAME), "foo"); } succeeds, you have renamed NAME
-   to "foo" in the same directory NAME was in.  */
-
 char *
 base_name (char const *name)
 {
@@ -102,27 +56,3 @@ base_name (char const *name)
   /* Finally, copy the basename.  */
   return xstrndup (base, length);
 }
-
-/* Return the length of the basename NAME.  Typically NAME is the
-   value returned by base_name or last_component.  Act like strlen
-   (NAME), except omit all trailing slashes.  */
-
-size_t
-base_len (char const *name)
-{
-  size_t len;
-  size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
-
-  for (len = strlen (name);  1 < len && ISSLASH (name[len - 1]);  len--)
-    continue;
-
-  if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
-      && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
-    return 2;
-
-  if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
-      && len == prefix_len && ISSLASH (name[prefix_len]))
-    return prefix_len + 1;
-
-  return len;
-}
diff --git a/lib/dirname.c b/lib/dirname-lgpl.c
similarity index 78%
copy from lib/dirname.c
copy to lib/dirname-lgpl.c
index 20dcaf5..79ee0b5 100644
--- a/lib/dirname.c
+++ b/lib/dirname-lgpl.c
@@ -22,7 +22,6 @@

 #include <stdlib.h>
 #include <string.h>
-#include "xalloc.h"

 /* Return the length of the prefix of FILE that will be used by
    dir_name.  If FILE is in the working directory, this returns zero
@@ -37,13 +36,13 @@ dir_len (char const *file)

   /* Advance prefix_length beyond important leading slashes.  */
   prefix_length += (prefix_length != 0
-                   ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
-                      && ISSLASH (file[prefix_length]))
-                   : (ISSLASH (file[0])
-                      ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
-                          && ISSLASH (file[1]) && ! ISSLASH (file[2])
-                          ? 2 : 1))
-                      : 0));
+                    ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+                       && ISSLASH (file[prefix_length]))
+                    : (ISSLASH (file[0])
+                       ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
+                           && ISSLASH (file[1]) && ! ISSLASH (file[2])
+                           ? 2 : 1))
+                       : 0));

   /* Strip the basename and any redundant slashes before it.  */
   for (length = last_component (file) - file;
@@ -73,9 +72,9 @@ mdir_name (char const *file)
 {
   size_t length = dir_len (file);
   bool append_dot = (length == 0
-                    || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
-                        && length == FILE_SYSTEM_PREFIX_LEN (file)
-                        && file[2] != '\0' && ! ISSLASH (file[2])));
+                     || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
+                         && length == FILE_SYSTEM_PREFIX_LEN (file)
+                         && file[2] != '\0' && ! ISSLASH (file[2])));
   char *dir = malloc (length + append_dot + 1);
   if (!dir)
     return NULL;
@@ -85,16 +84,3 @@ mdir_name (char const *file)
   dir[length] = '\0';
   return dir;
 }
-
-/* Just like mdir_name, above, except, rather than
-   returning NULL upon malloc failure, here, we report the
-   "memory exhausted" condition and exit.  */
-
-char *
-dir_name (char const *file)
-{
-  char *result = mdir_name (file);
-  if (!result)
-    xalloc_die ();
-  return result;
-}
diff --git a/lib/dirname.c b/lib/dirname.c
index 20dcaf5..d032270 100644
--- a/lib/dirname.c
+++ b/lib/dirname.c
@@ -24,69 +24,7 @@
 #include <string.h>
 #include "xalloc.h"

-/* Return the length of the prefix of FILE that will be used by
-   dir_name.  If FILE is in the working directory, this returns zero
-   even though `dir_name (FILE)' will return ".".  Works properly even
-   if there are trailing slashes (by effectively ignoring them).  */
-
-size_t
-dir_len (char const *file)
-{
-  size_t prefix_length = FILE_SYSTEM_PREFIX_LEN (file);
-  size_t length;
-
-  /* Advance prefix_length beyond important leading slashes.  */
-  prefix_length += (prefix_length != 0
-                   ? (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
-                      && ISSLASH (file[prefix_length]))
-                   : (ISSLASH (file[0])
-                      ? ((DOUBLE_SLASH_IS_DISTINCT_ROOT
-                          && ISSLASH (file[1]) && ! ISSLASH (file[2])
-                          ? 2 : 1))
-                      : 0));
-
-  /* Strip the basename and any redundant slashes before it.  */
-  for (length = last_component (file) - file;
-       prefix_length < length; length--)
-    if (! ISSLASH (file[length - 1]))
-      break;
-  return length;
-}
-
-
-/* In general, we can't use the builtin `dirname' function if available,
-   since it has different meanings in different environments.
-   In some environments the builtin `dirname' modifies its argument.
-
-   Return the leading directories part of FILE, allocated with malloc.
-   Works properly even if there are trailing slashes (by effectively
-   ignoring them).  Return NULL on failure.
-
-   If lstat (FILE) would succeed, then { chdir (dir_name (FILE));
-   lstat (base_name (FILE)); } will access the same file.  Likewise,
-   if the sequence { chdir (dir_name (FILE));
-   rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE
-   to "foo" in the same directory FILE was in.  */
-
-char *
-mdir_name (char const *file)
-{
-  size_t length = dir_len (file);
-  bool append_dot = (length == 0
-                    || (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
-                        && length == FILE_SYSTEM_PREFIX_LEN (file)
-                        && file[2] != '\0' && ! ISSLASH (file[2])));
-  char *dir = malloc (length + append_dot + 1);
-  if (!dir)
-    return NULL;
-  memcpy (dir, file, length);
-  if (append_dot)
-    dir[length++] = '.';
-  dir[length] = '\0';
-  return dir;
-}
-
-/* Just like mdir_name, above, except, rather than
+/* Just like mdir_name (dirname-lgpl.c), except, rather than
    returning NULL upon malloc failure, here, we report the
    "memory exhausted" condition and exit.  */

diff --git a/lib/dirname.h b/lib/dirname.h
index 90a1f0c..df12cca 100644
--- a/lib/dirname.h
+++ b/lib/dirname.h
@@ -58,9 +58,12 @@
 # endif
 # define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F))

+# if GNULIB_DIRNAME
 char *base_name (char const *file);
-char *mdir_name (char const *file);
 char *dir_name (char const *file);
+# endif
+
+char *mdir_name (char const *file);
 size_t base_len (char const *file);
 size_t dir_len (char const *file);
 char *last_component (char const *file);
diff --git a/m4/dirname.m4 b/m4/dirname.m4
index e35da96..4252b62 100644
--- a/m4/dirname.m4
+++ b/m4/dirname.m4
@@ -1,18 +1,26 @@
-#serial 7   -*- autoconf -*-
-dnl Copyright (C) 2002-2006 Free Software Foundation, Inc.
+#serial 8   -*- autoconf -*-
+dnl Copyright (C) 2002-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.

 AC_DEFUN([gl_DIRNAME],
 [
+  AC_REQUIRE([gl_DIRNAME_LGPL])
   AC_LIBOBJ([basename])
   AC_LIBOBJ([dirname])
+])
+
+AC_DEFUN([gl_DIRNAME_LGPL],
+[
+  AC_LIBOBJ([basename-lgpl])
+  AC_LIBOBJ([dirname-lgpl])
   AC_LIBOBJ([stripslash])

   dnl Prerequisites of lib/dirname.h.
   AC_REQUIRE([gl_AC_DOS])
   AC_REQUIRE([gl_DOUBLE_SLASH_ROOT])

-  dnl No prerequisites of lib/basename.c, lib/dirname.c, lib/stripslash.c.
+  dnl No prerequisites of lib/basename-lgpl.c, lib/dirname-lgpl.c,
+  dnl lib/stripslash.c.
 ])
diff --git a/modules/dirname b/modules/dirname
index 7c405c2..888c8ba 100644
--- a/modules/dirname
+++ b/modules/dirname
@@ -2,21 +2,18 @@ Description:
 Extract specific portions of filenames.

 Files:
-lib/dirname.h
 lib/dirname.c
 lib/basename.c
 lib/stripslash.c
-m4/dirname.m4
-m4/dos.m4

 Depends-on:
-double-slash-root
-stdbool
+dirname-lgpl
 xalloc
 xstrndup

 configure.ac:
 gl_DIRNAME
+gl_MODULE_INDICATOR([dirname])

 Makefile.am:

@@ -27,4 +24,4 @@ License:
 GPL

 Maintainer:
-Jim Meyering
+Jim Meyering, Eric Blake
diff --git a/modules/dirname b/modules/dirname-lgpl
similarity index 69%
copy from modules/dirname
copy to modules/dirname-lgpl
index 7c405c2..38f779a 100644
--- a/modules/dirname
+++ b/modules/dirname-lgpl
@@ -3,20 +3,19 @@ Extract specific portions of filenames.

 Files:
 lib/dirname.h
-lib/dirname.c
-lib/basename.c
+lib/dirname-lgpl.c
+lib/basename-lgpl.c
 lib/stripslash.c
 m4/dirname.m4
 m4/dos.m4

 Depends-on:
 double-slash-root
+malloc-posix
 stdbool
-xalloc
-xstrndup

 configure.ac:
-gl_DIRNAME
+gl_DIRNAME_LGPL

 Makefile.am:

@@ -24,7 +23,7 @@ Include:
 "dirname.h"

 License:
-GPL
+LGPLv2+

 Maintainer:
-Jim Meyering
+Jim Meyering, Eric Blake
diff --git a/modules/dirname-tests b/modules/dirname-tests
index e2e86e6..49eeb59 100644
--- a/modules/dirname-tests
+++ b/modules/dirname-tests
@@ -2,6 +2,7 @@ Files:
 tests/test-dirname.c

 Depends-on:
+progname
 strdup

 configure.ac:
diff --git a/modules/double-slash-root b/modules/double-slash-root
index 6b809d0..af78f26 100644
--- a/modules/double-slash-root
+++ b/modules/double-slash-root
@@ -14,7 +14,7 @@ Makefile.am:
 Include:

 License:
-LGPL
+LGPLv2+

 Maintainer:
 Eric Blake, Paul Eggert, Jim Meyering
diff --git a/tests/test-dirname.c b/tests/test-dirname.c
index bd75020..debda3f 100644
--- a/tests/test-dirname.c
+++ b/tests/test-dirname.c
@@ -23,8 +23,6 @@
 #include <stdlib.h>
 #include <string.h>

-const char *program_name = "test-dirname";
-
 struct test {
   const char *name;    /* Name under test.  */
   const char *dir;     /* dir_name (name).  */
-- 
1.6.4.2


>From 76cc537225364be7ba4ae775866f9e7f0be82fc4 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 29 Oct 2009 11:44:12 -0600
Subject: [PATCH 3/5] dirname-lgpl: adjust clients that don't need full dirname

* modules/backupfile (Depends-on): Use dirname-lgpl, not dirname.
* modules/filenamecat (Depends-on): Likewise.
* modules/linkat (Depends-on): Likewise.
* modules/mkancesdirs (Depends-on): Likewise.
* modules/mkdir (Depends-on): Likewise.
* modules/openat (Depends-on): Likewise.
* modules/savewd (Depends-on): Likewise.
* modules/rename (Depends-on): Likewise.
(License): Relax license.
* modules/mkdir-tests (Depends-on): Drop progname.
(Makefile.am): Delete unneeded LDADD.
* modules/rename-tests (Depends-on, Makefile.am): Likewise.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog            |   14 ++++++++++++++
 modules/backupfile   |    2 +-
 modules/filenamecat  |    2 +-
 modules/linkat       |    2 +-
 modules/mkancesdirs  |    2 +-
 modules/mkdir        |    2 +-
 modules/mkdir-tests  |    2 --
 modules/openat       |    2 +-
 modules/rename       |    4 ++--
 modules/rename-tests |    2 --
 modules/savewd       |    2 +-
 11 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 26a0abf..73d4a06 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2009-10-29  Eric Blake  <address@hidden>

+       dirname-lgpl: adjust clients that don't need full dirname
+       * modules/backupfile (Depends-on): Use dirname-lgpl, not dirname.
+       * modules/filenamecat (Depends-on): Likewise.
+       * modules/linkat (Depends-on): Likewise.
+       * modules/mkancesdirs (Depends-on): Likewise.
+       * modules/mkdir (Depends-on): Likewise.
+       * modules/openat (Depends-on): Likewise.
+       * modules/savewd (Depends-on): Likewise.
+       * modules/rename (Depends-on): Likewise.
+       (License): Relax license.
+       * modules/mkdir-tests (Depends-on): Drop progname.
+       (Makefile.am): Delete unneeded LDADD.
+       * modules/rename-tests (Depends-on, Makefile.am): Likewise.
+
        dirname: split into dirname-lgpl
        * modules/dirname-lgpl: New module.
        * modules/dirname (Files): Move library-safe files into
diff --git a/modules/backupfile b/modules/backupfile
index aaf20f3..fcfcce6 100644
--- a/modules/backupfile
+++ b/modules/backupfile
@@ -12,7 +12,7 @@ Depends-on:
 argmatch
 d-ino
 dirent-safer
-dirname
+dirname-lgpl
 memcmp
 stdbool

diff --git a/modules/filenamecat b/modules/filenamecat
index fb1786b..3008f35 100644
--- a/modules/filenamecat
+++ b/modules/filenamecat
@@ -9,7 +9,7 @@ m4/filenamecat.m4

 Depends-on:
 xalloc
-dirname
+dirname-lgpl

 configure.ac:
 gl_FILE_NAME_CONCAT
diff --git a/modules/linkat b/modules/linkat
index 0c94227..7affdbf 100644
--- a/modules/linkat
+++ b/modules/linkat
@@ -9,7 +9,7 @@ m4/linkat.m4
 Depends-on:
 areadlink
 areadlinkat
-dirname
+dirname-lgpl
 errno
 extensions
 fcntl-h
diff --git a/modules/mkancesdirs b/modules/mkancesdirs
index 5a5c66a..bff63e1 100644
--- a/modules/mkancesdirs
+++ b/modules/mkancesdirs
@@ -7,7 +7,7 @@ lib/mkancesdirs.h
 m4/mkancesdirs.m4

 Depends-on:
-dirname
+dirname-lgpl
 fcntl-h
 savewd
 stat-macros
diff --git a/modules/mkdir b/modules/mkdir
index fa0931d..08089d0 100644
--- a/modules/mkdir
+++ b/modules/mkdir
@@ -6,8 +6,8 @@ lib/mkdir.c
 m4/mkdir.m4

 Depends-on:
+dirname-lgpl
 sys_stat
-dirname

 configure.ac:
 gl_FUNC_MKDIR
diff --git a/modules/mkdir-tests b/modules/mkdir-tests
index cff0a5b..4d5a9c2 100644
--- a/modules/mkdir-tests
+++ b/modules/mkdir-tests
@@ -3,7 +3,6 @@ tests/test-mkdir.h
 tests/test-mkdir.c

 Depends-on:
-progname
 stdbool
 symlink

@@ -12,4 +11,3 @@ configure.ac:
 Makefile.am:
 TESTS += test-mkdir
 check_PROGRAMS += test-mkdir
-test_mkdir_LDADD = $(LDADD) @LIBINTL@
diff --git a/modules/openat b/modules/openat
index 77a7870..fc21367 100644
--- a/modules/openat
+++ b/modules/openat
@@ -16,7 +16,7 @@ m4/openat.m4
 m4/mode_t.m4

 Depends-on:
-dirname
+dirname-lgpl
 errno
 extensions
 fchdir
diff --git a/modules/rename b/modules/rename
index fbd081c..e553a12 100644
--- a/modules/rename
+++ b/modules/rename
@@ -7,7 +7,7 @@ m4/rename.m4

 Depends-on:
 canonicalize-lgpl
-dirname
+dirname-lgpl
 lstat
 rmdir
 same-inode
@@ -25,7 +25,7 @@ Include:
 <stdio.h>

 License:
-GPL
+LGPL

 Maintainer:
 Jim Meyering
diff --git a/modules/rename-tests b/modules/rename-tests
index 9929faf..be1b423 100644
--- a/modules/rename-tests
+++ b/modules/rename-tests
@@ -5,7 +5,6 @@ tests/test-rename.c
 Depends-on:
 errno
 link
-progname
 stdbool
 symlink
 sys_stat
@@ -15,4 +14,3 @@ configure.ac:
 Makefile.am:
 TESTS += test-rename
 check_PROGRAMS += test-rename
-test_rename_LDADD = $(LDADD) @LIBINTL@
diff --git a/modules/savewd b/modules/savewd
index 6d655c1..41f51e3 100644
--- a/modules/savewd
+++ b/modules/savewd
@@ -7,7 +7,7 @@ lib/savewd.c
 m4/savewd.m4

 Depends-on:
-dirname
+dirname-lgpl
 errno
 exit
 fchdir
-- 
1.6.4.2


>From 7f1e8a89884b8dc79c5f4fd75473b10b20e5ed40 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 29 Oct 2009 12:00:03 -0600
Subject: [PATCH 4/5] filenamecat: split into filenamecat-lgpl

* modules/filenamecat-lgpl: New module.
* modules/filenamecat (Files): Move library-safe files into
filenamecat-lgpl.
(Depends-on): Add filenamecat-lgpl.
(configure.ac): Declare witness.
* lib/filenamecat.h (file_name_concat): Only declare when using
GPL module.
* lib/filenamecat.c (longest_relative_suffix, mfile_name_concat):
Move...
* lib/filenamecat-lgpl.c: ...into new file.
* m4/filenamecat.m4 (gl_FILE_NAME_CONCAT_LGPL): New macro.
(gl_FILE_NAME_CONCAT): Use it.
* MODULES.html.sh (File system functions): Mention new module.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog                                 |   15 +++++++
 MODULES.html.sh                           |    1 +
 lib/{filenamecat.c => filenamecat-lgpl.c} |   16 +-------
 lib/filenamecat.c                         |   65 +----------------------------
 lib/filenamecat.h                         |    5 ++-
 m4/filenamecat.m4                         |   10 ++++-
 modules/filenamecat                       |    6 +-
 modules/{filenamecat => filenamecat-lgpl} |    6 +--
 8 files changed, 36 insertions(+), 88 deletions(-)
 copy lib/{filenamecat.c => filenamecat-lgpl.c} (86%)
 copy modules/{filenamecat => filenamecat-lgpl} (79%)

diff --git a/ChangeLog b/ChangeLog
index 73d4a06..a10acdc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2009-10-29  Eric Blake  <address@hidden>

+       filenamecat: split into filenamecat-lgpl
+       * modules/filenamecat-lgpl: New module.
+       * modules/filenamecat (Files): Move library-safe files into
+       filenamecat-lgpl.
+       (Depends-on): Add filenamecat-lgpl.
+       (configure.ac): Declare witness.
+       * lib/filenamecat.h (file_name_concat): Only declare when using
+       GPL module.
+       * lib/filenamecat.c (longest_relative_suffix, mfile_name_concat):
+       Move...
+       * lib/filenamecat-lgpl.c: ...into new file.
+       * m4/filenamecat.m4 (gl_FILE_NAME_CONCAT_LGPL): New macro.
+       (gl_FILE_NAME_CONCAT): Use it.
+       * MODULES.html.sh (File system functions): Mention new module.
+
        dirname-lgpl: adjust clients that don't need full dirname
        * modules/backupfile (Depends-on): Use dirname-lgpl, not dirname.
        * modules/filenamecat (Depends-on): Likewise.
diff --git a/MODULES.html.sh b/MODULES.html.sh
index d8677e0..2908890 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2471,6 +2471,7 @@ func_all_modules ()
   func_module filemode
   func_module filename
   func_module filenamecat
+  func_module filenamecat-lgpl
   func_module fts
   func_module fts-lgpl
   func_module isdir
diff --git a/lib/filenamecat.c b/lib/filenamecat-lgpl.c
similarity index 86%
copy from lib/filenamecat.c
copy to lib/filenamecat-lgpl.c
index ef46de2..b22f0f7 100644
--- a/lib/filenamecat.c
+++ b/lib/filenamecat-lgpl.c
@@ -1,6 +1,6 @@
 /* Concatenate two arbitrary file names.

-   Copyright (C) 1996-2007 Free Software Foundation, Inc.
+   Copyright (C) 1996-2007, 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
@@ -26,7 +26,6 @@
 #include <string.h>

 #include "dirname.h"
-#include "xalloc.h"

 #if ! HAVE_MEMPCPY && ! defined mempcpy
 # define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
@@ -87,16 +86,3 @@ mfile_name_concat (char const *dir, char const *abase, char 
**base_in_result)

   return p_concat;
 }
-
-/* Just like mfile_name_concat, above, except, rather than
-   returning NULL upon malloc failure, here, we report the
-   "memory exhausted" condition and exit.  */
-
-char *
-file_name_concat (char const *dir, char const *abase, char **base_in_result)
-{
-  char *p = mfile_name_concat (dir, abase, base_in_result);
-  if (p == NULL)
-    xalloc_die ();
-  return p;
-}
diff --git a/lib/filenamecat.c b/lib/filenamecat.c
index ef46de2..eed4a2c 100644
--- a/lib/filenamecat.c
+++ b/lib/filenamecat.c
@@ -1,6 +1,6 @@
 /* Concatenate two arbitrary file names.

-   Copyright (C) 1996-2007 Free Software Foundation, Inc.
+   Copyright (C) 1996-2007, 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
@@ -25,70 +25,9 @@
 #include <stdlib.h>
 #include <string.h>

-#include "dirname.h"
 #include "xalloc.h"

-#if ! HAVE_MEMPCPY && ! defined mempcpy
-# define mempcpy(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
-#endif
-
-/* Return the longest suffix of F that is a relative file name.
-   If it has no such suffix, return the empty string.  */
-
-static char const *
-longest_relative_suffix (char const *f)
-{
-  for (f += FILE_SYSTEM_PREFIX_LEN (f); ISSLASH (*f); f++)
-    continue;
-  return f;
-}
-
-/* Concatenate two file name components, DIR and ABASE, in
-   newly-allocated storage and return the result.
-   The resulting file name F is such that the commands "ls F" and "(cd
-   DIR; ls BASE)" refer to the same file, where BASE is ABASE with any
-   file system prefixes and leading separators removed.
-   Arrange for a directory separator if necessary between DIR and BASE
-   in the result, removing any redundant separators.
-   In any case, if BASE_IN_RESULT is non-NULL, set
-   *BASE_IN_RESULT to point to the copy of ABASE in the returned
-   concatenation.  However, if ABASE begins with more than one slash,
-   set *BASE_IN_RESULT to point to the sole corresponding slash that
-   is copied into the result buffer.
-
-   Return NULL if malloc fails.  */
-
-char *
-mfile_name_concat (char const *dir, char const *abase, char **base_in_result)
-{
-  char const *dirbase = last_component (dir);
-  size_t dirbaselen = base_len (dirbase);
-  size_t dirlen = dirbase - dir + dirbaselen;
-  size_t needs_separator = (dirbaselen && ! ISSLASH (dirbase[dirbaselen - 1]));
-
-  char const *base = longest_relative_suffix (abase);
-  size_t baselen = strlen (base);
-
-  char *p_concat = malloc (dirlen + needs_separator + baselen + 1);
-  char *p;
-
-  if (p_concat == NULL)
-    return NULL;
-
-  p = mempcpy (p_concat, dir, dirlen);
-  *p = DIRECTORY_SEPARATOR;
-  p += needs_separator;
-
-  if (base_in_result)
-    *base_in_result = p - IS_ABSOLUTE_FILE_NAME (abase);
-
-  p = mempcpy (p, base, baselen);
-  *p = '\0';
-
-  return p_concat;
-}
-
-/* Just like mfile_name_concat, above, except, rather than
+/* Just like mfile_name_concat (filenamecat-lgpl.c), except, rather than
    returning NULL upon malloc failure, here, we report the
    "memory exhausted" condition and exit.  */

diff --git a/lib/filenamecat.h b/lib/filenamecat.h
index 334c887..df5360b 100644
--- a/lib/filenamecat.h
+++ b/lib/filenamecat.h
@@ -1,6 +1,7 @@
 /* Concatenate two arbitrary file names.

-   Copyright (C) 1996, 1997, 2003, 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 2003, 2005, 2007, 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
@@ -17,8 +18,10 @@

 /* Written by Jim Meyering.  */

+#if GNULIB_FILENAMECAT
 char *file_name_concat (char const *dir, char const *base,
                        char **base_in_result);
+#endif

 char *mfile_name_concat (char const *dir, char const *base,
                         char **base_in_result);
diff --git a/m4/filenamecat.m4 b/m4/filenamecat.m4
index 77a3b6a..c32283c 100644
--- a/m4/filenamecat.m4
+++ b/m4/filenamecat.m4
@@ -1,4 +1,4 @@
-# filenamecat.m4 serial 9
+# filenamecat.m4 serial 10
 dnl Copyright (C) 2002-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,
@@ -6,8 +6,14 @@ dnl with or without modifications, as long as this notice is 
preserved.

 AC_DEFUN([gl_FILE_NAME_CONCAT],
 [
+  AC_REQUIRE([gl_FILE_NAME_CONCAT_LGPL])
   AC_LIBOBJ([filenamecat])
+])
+
+AC_DEFUN([gl_FILE_NAME_CONCAT_LGPL],
+[
+  AC_LIBOBJ([filenamecat-lgpl])

-  dnl Prerequisites of lib/filenamecat.c.
+  dnl Prerequisites of lib/filenamecat-lgpl.c.
   AC_CHECK_FUNCS_ONCE([mempcpy])
 ])
diff --git a/modules/filenamecat b/modules/filenamecat
index 3008f35..df90c2f 100644
--- a/modules/filenamecat
+++ b/modules/filenamecat
@@ -2,17 +2,17 @@ Description:
 Concatenate two arbitrary file names.

 Files:
-lib/filenamecat.h
 lib/filenamecat.c
-m4/dos.m4
 m4/filenamecat.m4

 Depends-on:
-xalloc
 dirname-lgpl
+filenamecat-lgpl
+xalloc

 configure.ac:
 gl_FILE_NAME_CONCAT
+gl_MODULE_INDICATOR([filenamecat])

 Makefile.am:

diff --git a/modules/filenamecat b/modules/filenamecat-lgpl
similarity index 79%
copy from modules/filenamecat
copy to modules/filenamecat-lgpl
index 3008f35..a744933 100644
--- a/modules/filenamecat
+++ b/modules/filenamecat-lgpl
@@ -3,16 +3,14 @@ Concatenate two arbitrary file names.

 Files:
 lib/filenamecat.h
-lib/filenamecat.c
-m4/dos.m4
+lib/filenamecat-lgpl.c
 m4/filenamecat.m4

 Depends-on:
-xalloc
 dirname-lgpl

 configure.ac:
-gl_FILE_NAME_CONCAT
+gl_FILE_NAME_CONCAT_LGPL

 Makefile.am:

-- 
1.6.4.2


>From 5675e68a5fa2bad2e8d3a589768dcb9f0abb66ac Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 29 Oct 2009 12:09:48 -0600
Subject: [PATCH 5/5] filenamecat-lgpl: adjust clients

* modules/linkat (Depends-on): Use filenamecat-lgpl, not
filenamecat.
* modules/renameat (Depends-on): Likewise.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog        |    5 +++++
 modules/linkat   |    2 +-
 modules/renameat |    2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a10acdc..4396617 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-10-29  Eric Blake  <address@hidden>

+       filenamecat-lgpl: adjust clients
+       * modules/linkat (Depends-on): Use filenamecat-lgpl, not
+       filenamecat.
+       * modules/renameat (Depends-on): Likewise.
+
        filenamecat: split into filenamecat-lgpl
        * modules/filenamecat-lgpl: New module.
        * modules/filenamecat (Files): Move library-safe files into
diff --git a/modules/linkat b/modules/linkat
index 7affdbf..d0e4771 100644
--- a/modules/linkat
+++ b/modules/linkat
@@ -13,7 +13,7 @@ dirname-lgpl
 errno
 extensions
 fcntl-h
-filenamecat
+filenamecat-lgpl
 openat
 link
 link-follow
diff --git a/modules/renameat b/modules/renameat
index efe4a0f..d370279 100644
--- a/modules/renameat
+++ b/modules/renameat
@@ -9,7 +9,7 @@ m4/renameat.m4
 Depends-on:
 extensions
 fcntl-h
-filenamecat
+filenamecat-lgpl
 openat
 rename
 same-inode
-- 
1.6.4.2







reply via email to

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