OK, here's that promised patch for review. I've tested it with Emacs and with coreutils, but I haven't pushed it into gnulib yet.
--- ChangeLog | 35 ++++++++++++++++++++++++ lib/at-func.c | 2 +- lib/at-func2.c | 2 +- lib/dirname.h | 30 +-------------------- lib/dosname.h | 53 +++++++++++++++++++++++++++++++++++++ lib/openat.c | 2 +- lib/rmdir.c | 2 + lib/savewd.c | 2 +- lib/stat.c | 1 + lib/unlink.c | 2 + lib/unlinkat.c | 1 + m4/dirname.m4 | 3 +- m4/dos.m4 | 71 -------------------------------------------------- m4/rmdir.m4 | 3 +- m4/stat.m4 | 3 +- m4/unlink.m4 | 3 +- modules/dirname-lgpl | 2 +- modules/lstat | 1 + modules/openat | 2 +- modules/rmdir | 2 +- modules/savewd | 2 +- modules/stat | 2 +- modules/unlink | 2 +- tests/test-dirname.c | 6 ++-- 24 files changed, 113 insertions(+), 121 deletions(-) create mode 100644 lib/dosname.h delete mode 100644 m4/dos.m4 diff --git a/ChangeLog b/ChangeLog index e40fe97..3ac3cf1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,40 @@ 2011-02-24 Paul Eggert <egg...@cs.ucla.edu> + dirname: move m4/dos.m4 functionality into lib/dosname.h + + m4/dos.m4 needs to go. It laboriously invokes the C compiler, and + extracts symbols from it, puts them into config.h; but it's much + easier to use the symbols directly. filename.h already does this, + but it disagrees with dos.m4 in some respects. This patch + introduces a different include file dosname.h that packages up + dos.m4, and then later we can work on merging filename.h and + dosname.h. + * lib/dosname.h: New file. + * lib/dirname.h (ISSLASH, FILE_SYSTEM_PREFIX_LEN): + (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE): + (IS_ABSOLUTE_FILE_NAME, IS_RELATIVE_FILE_NAME): Move to lib/dosname.h. + * lib/at-func.c, lib/at-func2.c, lib/openat.c, lib/savewd.c: + Include dosname.h, not dirname.h. + * lib/rmdir.c, lib/stat.c, lib/unlink.c, lib/unlinkat.c: + Include dosname.h, for definitions of symbols like ISSLASH + that used to be in config.h. + * m4/dirname.m4 (gl_DIRNAME_LGPL): Do not require gl_AC_DOS. + * m4/rmdir.m4 (gl_FUNC_RMDIR): Likewise. + * m4/stat.m4 (gl_FUNC_STAT): Likewise. + * m4/unlink.m4 (gl_FUNC_UNLINK): Likewise. + * modules/dirname-lgpl (Files): Replace m4/dos.m4 with lib/dosname.h. + * modules/rmdir (Files): Likewise. + * modules/stat (Files): Likewise. + * modules/unlink (Files): Likewise. + * modules/lstat (Files): Add lib/dosname.h. + * modules/openat (Files): Likewise. + * modules/savewd (Files): Likewise. + * modules/openat (Depends-on): Remove dirname-lgpl. + * modules/savewd (Depends-on): Likewise. + * tests/test-dirname.c: Do not use removed symbols like + FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR. Instead, use + the remaining symbols, e.g., ISSLASH ('\\'). + filenamecat: remove unnecessary dependency on dirname-lgpl * modules/filenamecat (Depends-on): Remove dirname-lgpl, as there is no direct dependency, just an indirect one via filenamecat-lgpl. diff --git a/lib/at-func.c b/lib/at-func.c index 31a75f1..52868bc 100644 --- a/lib/at-func.c +++ b/lib/at-func.c @@ -16,7 +16,7 @@ /* written by Jim Meyering */ -#include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ +#include "dosname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ #include "openat.h" #include "openat-priv.h" #include "save-cwd.h" diff --git a/lib/at-func2.c b/lib/at-func2.c index 29e6772..da691fe 100644 --- a/lib/at-func2.c +++ b/lib/at-func2.c @@ -25,7 +25,7 @@ #include <string.h> #include <unistd.h> -#include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ +#include "dosname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ #include "filenamecat.h" #include "openat.h" #include "same-inode.h" diff --git a/lib/dirname.h b/lib/dirname.h index f089955..2ef9882 100644 --- a/lib/dirname.h +++ b/lib/dirname.h @@ -21,44 +21,16 @@ # include <stdbool.h> # include <stddef.h> +# include "dosname.h" # ifndef DIRECTORY_SEPARATOR # define DIRECTORY_SEPARATOR '/' # endif -# ifndef ISSLASH -# define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR) -# endif - -# ifndef FILE_SYSTEM_PREFIX_LEN -# if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX - /* This internal macro assumes ASCII, but all hosts that support drive - letters use ASCII. */ -# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' \ - <= 'z' - 'a') -# define FILE_SYSTEM_PREFIX_LEN(Filename) \ - (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) -# else -# define FILE_SYSTEM_PREFIX_LEN(Filename) 0 -# endif -# endif - -# ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE -# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 -# endif - # ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT # define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 # endif -# if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE -# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) -# else -# define IS_ABSOLUTE_FILE_NAME(F) \ - (ISSLASH ((F)[0]) || 0 < FILE_SYSTEM_PREFIX_LEN (F)) -# endif -# define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) - # if GNULIB_DIRNAME char *base_name (char const *file); char *dir_name (char const *file); diff --git a/lib/dosname.h b/lib/dosname.h new file mode 100644 index 0000000..acdd03b --- /dev/null +++ b/lib/dosname.h @@ -0,0 +1,53 @@ +/* File names on MS-DOS/Windows systems. + + Copyright (C) 2000-2001, 2004-2006, 2009-2011 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/>. + + From Paul Eggert and Jim Meyering. */ + +#ifndef _DOSNAME_H +#define _DOSNAME_H + +#if (defined _WIN32 || defined __WIN32__ || \ + defined __MSDOS__ || defined __CYGWIN__ || \ + defined __EMX__ || defined __DJGPP__) + /* This internal macro assumes ASCII, but all hosts that support drive + letters use ASCII. */ +# define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a' \ + <= 'z' - 'a') +# define FILE_SYSTEM_PREFIX_LEN(Filename) \ + (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) +# ifndef __CYGWIN__ +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1 +# endif +# define ISSLASH(C) ((C) == '/' || (C) == '\\') +#else +# define FILE_SYSTEM_PREFIX_LEN(Filename) 0 +# define ISSLASH(C) ((C) == '/') +#endif + +#ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE +# define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 +#endif + +#if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE +# define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) +# else +# define IS_ABSOLUTE_FILE_NAME(F) \ + (ISSLASH ((F)[0]) || FILE_SYSTEM_PREFIX_LEN (F) != 0) +#endif +#define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) + +#endif /* DOSNAME_H_ */ diff --git a/lib/openat.c b/lib/openat.c index 939e3c7..18491a6 100644 --- a/lib/openat.c +++ b/lib/openat.c @@ -25,7 +25,7 @@ #include <string.h> #include <sys/stat.h> -#include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ +#include "dosname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ #include "openat-priv.h" #include "save-cwd.h" diff --git a/lib/rmdir.c b/lib/rmdir.c index 8e02c37..d7395a5 100644 --- a/lib/rmdir.c +++ b/lib/rmdir.c @@ -23,6 +23,8 @@ #include <errno.h> #include <string.h> +#include "dosname.h" + #undef rmdir /* Remove directory DIR. diff --git a/lib/savewd.c b/lib/savewd.c index 982e73f..f19e98e 100644 --- a/lib/savewd.c +++ b/lib/savewd.c @@ -31,7 +31,7 @@ #include <sys/wait.h> #include <unistd.h> -#include "dirname.h" +#include "dosname.h" #include "fcntl-safer.h" /* Save the working directory into *WD, if it hasn't been saved diff --git a/lib/stat.c b/lib/stat.c index f16d914..cbc9100 100644 --- a/lib/stat.c +++ b/lib/stat.c @@ -37,6 +37,7 @@ orig_stat (const char *filename, struct stat *buf) #include <limits.h> #include <stdbool.h> #include <string.h> +#include "dosname.h" /* Store information about NAME into ST. Work around bugs with trailing slashes. Mingw has other bugs (such as st_ino always diff --git a/lib/unlink.c b/lib/unlink.c index 7b14d80..677d584 100644 --- a/lib/unlink.c +++ b/lib/unlink.c @@ -24,6 +24,8 @@ #include <string.h> #include <sys/stat.h> +#include "dosname.h" + #undef unlink /* Remove file NAME. diff --git a/lib/unlinkat.c b/lib/unlinkat.c index 9f1894a..fd1c69e 100644 --- a/lib/unlinkat.c +++ b/lib/unlinkat.c @@ -26,6 +26,7 @@ #include <string.h> #include <sys/stat.h> +#include "dosname.h" #include "openat.h" #if HAVE_UNLINKAT diff --git a/m4/dirname.m4 b/m4/dirname.m4 index d0b439f..9d5f40d 100644 --- a/m4/dirname.m4 +++ b/m4/dirname.m4 @@ -1,4 +1,4 @@ -#serial 8 -*- autoconf -*- +#serial 9 -*- autoconf -*- dnl Copyright (C) 2002-2006, 2009-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -18,7 +18,6 @@ AC_DEFUN([gl_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-lgpl.c, lib/dirname-lgpl.c, diff --git a/m4/dos.m4 b/m4/dos.m4 deleted file mode 100644 index ed9c4ce..0000000 --- a/m4/dos.m4 +++ /dev/null @@ -1,71 +0,0 @@ -#serial 11 -*- autoconf -*- - -# Define some macros required for proper operation of code in lib/*.c -# on MSDOS/Windows systems. - -# Copyright (C) 2000-2001, 2004-2006, 2009-2011 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. - -# From Jim Meyering. - -AC_DEFUN([gl_AC_DOS], - [ - AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos], - [ - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ -#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__ -neither MSDOS nor Windows -#endif]])], - [ac_cv_win_or_dos=yes], - [ac_cv_win_or_dos=no]) - ]) - - if test x"$ac_cv_win_or_dos" = xyes; then - ac_fs_accepts_drive_letter_prefix=1 - ac_fs_backslash_is_file_name_separator=1 - AC_CACHE_CHECK([whether drive letter can start relative path], - [ac_cv_drive_letter_can_be_relative], - [ - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ -#if defined __CYGWIN__ -drive letters are always absolute -#endif]])], - [ac_cv_drive_letter_can_be_relative=yes], - [ac_cv_drive_letter_can_be_relative=no]) - ]) - if test x"$ac_cv_drive_letter_can_be_relative" = xyes; then - ac_fs_drive_letter_can_be_relative=1 - else - ac_fs_drive_letter_can_be_relative=0 - fi - else - ac_fs_accepts_drive_letter_prefix=0 - ac_fs_backslash_is_file_name_separator=0 - ac_fs_drive_letter_can_be_relative=0 - fi - - AC_DEFINE_UNQUOTED([FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX], - $ac_fs_accepts_drive_letter_prefix, - [Define on systems for which file names may have a so-called - `drive letter' prefix, define this to compute the length of that - prefix, including the colon.]) - - AH_VERBATIM(ISSLASH, - [#if FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR -# define ISSLASH(C) ((C) == '/' || (C) == '\\') -#else -# define ISSLASH(C) ((C) == '/') -#endif]) - - AC_DEFINE_UNQUOTED([FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR], - $ac_fs_backslash_is_file_name_separator, - [Define if the backslash character may also serve as a file name - component separator.]) - - AC_DEFINE_UNQUOTED([FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE], - $ac_fs_drive_letter_can_be_relative, - [Define if a drive letter prefix denotes a relative path if it is - not followed by a file name component separator.]) - ]) diff --git a/m4/rmdir.m4 b/m4/rmdir.m4 index 16402a5..41705a1 100644 --- a/m4/rmdir.m4 +++ b/m4/rmdir.m4 @@ -1,4 +1,4 @@ -# rmdir.m4 serial 9 +# rmdir.m4 serial 10 dnl Copyright (C) 2002, 2005, 2009-2011 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,7 +6,6 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_RMDIR], [ - AC_REQUIRE([gl_AC_DOS]) AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl Detect cygwin 1.5.x bug. AC_CACHE_CHECK([whether rmdir works], [gl_cv_func_rmdir_works], diff --git a/m4/stat.m4 b/m4/stat.m4 index 4883fe2..27f82d5 100644 --- a/m4/stat.m4 +++ b/m4/stat.m4 @@ -1,4 +1,4 @@ -# serial 6 +# serial 7 # Copyright (C) 2009-2011 Free Software Foundation, Inc. # @@ -9,7 +9,6 @@ AC_DEFUN([gl_FUNC_STAT], [ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - AC_REQUIRE([gl_AC_DOS]) AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) AC_CHECK_FUNCS_ONCE([lstat]) dnl mingw is the only known platform where stat(".") and stat("./") differ diff --git a/m4/unlink.m4 b/m4/unlink.m4 index 6d5d3d3..a49a692 100644 --- a/m4/unlink.m4 +++ b/m4/unlink.m4 @@ -1,4 +1,4 @@ -# unlink.m4 serial 6 +# unlink.m4 serial 7 dnl Copyright (C) 2009-2011 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,7 +6,6 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_UNLINK], [ - AC_REQUIRE([gl_AC_DOS]) AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) AC_REQUIRE([AC_CANONICAL_HOST]) dnl Detect FreeBSD 7.2, AIX 7.1, Solaris 9 bug. diff --git a/modules/dirname-lgpl b/modules/dirname-lgpl index 38f779a..6faaf33 100644 --- a/modules/dirname-lgpl +++ b/modules/dirname-lgpl @@ -5,9 +5,9 @@ Files: lib/dirname.h lib/dirname-lgpl.c lib/basename-lgpl.c +lib/dosname.h lib/stripslash.c m4/dirname.m4 -m4/dos.m4 Depends-on: double-slash-root diff --git a/modules/lstat b/modules/lstat index e4eabb5..a23fa91 100644 --- a/modules/lstat +++ b/modules/lstat @@ -2,6 +2,7 @@ Description: lstat() function: return information about a file or symbolic link. Files: +lib/dosname.h lib/lstat.c m4/lstat.m4 diff --git a/modules/openat b/modules/openat index 37cae80..4a6564d 100644 --- a/modules/openat +++ b/modules/openat @@ -3,6 +3,7 @@ Open a file at a directory. Files: lib/at-func.c +lib/dosname.h lib/fchmodat.c lib/fchownat.c lib/fstatat.c @@ -16,7 +17,6 @@ m4/openat.m4 m4/mode_t.m4 Depends-on: -dirname-lgpl errno extensions fchdir diff --git a/modules/rmdir b/modules/rmdir index d047e4c..15d53d6 100644 --- a/modules/rmdir +++ b/modules/rmdir @@ -2,8 +2,8 @@ Description: rmdir() function: delete a directory. Files: +lib/dosname.h lib/rmdir.c -m4/dos.m4 m4/rmdir.m4 Depends-on: diff --git a/modules/savewd b/modules/savewd index 41f51e3..623d6a5 100644 --- a/modules/savewd +++ b/modules/savewd @@ -2,12 +2,12 @@ Description: Save and restore the working directory, possibly using a child process. Files: +lib/dosname.h lib/savewd.h lib/savewd.c m4/savewd.m4 Depends-on: -dirname-lgpl errno exit fchdir diff --git a/modules/stat b/modules/stat index 1ad5e90..150d876 100644 --- a/modules/stat +++ b/modules/stat @@ -2,8 +2,8 @@ Description: stat() function: query file information Files: +lib/dosname.h lib/stat.c -m4/dos.m4 m4/stat.m4 Depends-on: diff --git a/modules/unlink b/modules/unlink index 4c8c649..c79b9c2 100644 --- a/modules/unlink +++ b/modules/unlink @@ -2,8 +2,8 @@ Description: unlink() function: remove a file. Files: +lib/dosname.h lib/unlink.c -m4/dos.m4 m4/unlink.m4 Depends-on: diff --git a/tests/test-dirname.c b/tests/test-dirname.c index bda1ee8..1ddf229 100644 --- a/tests/test-dirname.c +++ b/tests/test-dirname.c @@ -54,7 +54,7 @@ static struct test tests[] = { {"", ".", "", "", "", false, false}, {".", ".", ".", ".", ".", false, false}, {"..", ".", "..", "..", "..", false, false}, -#if FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR +#if ISSLASH ('\\') {"a\\", ".", "a\\", "a\\", "a", true, false}, {"a\\b", "a", "b", "b", "a\\b", false, false}, {"\\", "\\", "", "\\", "\\", false, true}, @@ -75,7 +75,7 @@ static struct test tests[] = { {"//\\", "/", "\\", "\\", "//\\", false, true}, # endif #endif -#if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX +#if ISSLASH ('\\') # if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE {"c:", "c:", "", "c:", "c:", false, false}, {"c:/", "c:/", "", "c:/", "c:/", false, true}, @@ -105,7 +105,7 @@ static struct test tests[] = { {"a/b:c", "a", "b:c", "./b:c","a/b:c",false, false}, {"a/b:c/", "a", "b:c/", "./b:c/","a/b:c",true, false}, # endif -#else /* ! FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX */ +#else /* ! ISSLASH ('\\') */ {"c:", ".", "c:", "c:", "c:", false, false}, {"c:/", ".", "c:/", "c:/", "c:", true, false}, {"c://", ".", "c://", "c:/", "c:", true, false}, -- 1.7.4