diff options
| -rw-r--r-- | lib/at-func.c | 2 | ||||
| -rw-r--r-- | lib/canonicalize-lgpl.c | 2 | ||||
| -rw-r--r-- | lib/dosname.h | 38 | ||||
| -rw-r--r-- | lib/filename.h | 110 | ||||
| -rw-r--r-- | lib/gnulib.mk.in | 9 | ||||
| -rw-r--r-- | m4/gnulib-comp.m4 | 2 |
6 files changed, 125 insertions, 38 deletions
diff --git a/lib/at-func.c b/lib/at-func.c index 4a1c909d38e..90022e05787 100644 --- a/lib/at-func.c +++ b/lib/at-func.c | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | /* written by Jim Meyering */ | 17 | /* written by Jim Meyering */ |
| 18 | 18 | ||
| 19 | #include "dosname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ | 19 | #include "filename.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ |
| 20 | 20 | ||
| 21 | #ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD | 21 | #ifdef GNULIB_SUPPORT_ONLY_AT_FDCWD |
| 22 | # include <errno.h> | 22 | # include <errno.h> |
diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index 7d3c710f10f..9f990988393 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c | |||
| @@ -51,7 +51,7 @@ | |||
| 51 | # define __realpath realpath | 51 | # define __realpath realpath |
| 52 | # include "pathmax.h" | 52 | # include "pathmax.h" |
| 53 | # include "malloca.h" | 53 | # include "malloca.h" |
| 54 | # include "dosname.h" | 54 | # include "filename.h" |
| 55 | # if HAVE_GETCWD | 55 | # if HAVE_GETCWD |
| 56 | # if IN_RELOCWRAPPER | 56 | # if IN_RELOCWRAPPER |
| 57 | /* When building the relocatable program wrapper, use the system's getcwd | 57 | /* When building the relocatable program wrapper, use the system's getcwd |
diff --git a/lib/dosname.h b/lib/dosname.h index 57829600948..490e0c5a7dd 100644 --- a/lib/dosname.h +++ b/lib/dosname.h | |||
| @@ -13,40 +13,6 @@ | |||
| 13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
| 14 | 14 | ||
| 15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program. If not, see <https://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 17 | 17 | ||
| 18 | From Paul Eggert and Jim Meyering. */ | 18 | #include "filename.h" |
| 19 | |||
| 20 | #ifndef _DOSNAME_H | ||
| 21 | #define _DOSNAME_H | ||
| 22 | |||
| 23 | #if (defined _WIN32 || defined __CYGWIN__ \ | ||
| 24 | || defined __EMX__ || defined __MSDOS__ || defined __DJGPP__) | ||
| 25 | /* This internal macro assumes ASCII, but all hosts that support drive | ||
| 26 | letters use ASCII. */ | ||
| 27 | # define _IS_DRIVE_LETTER(C) (((unsigned int) (C) | ('a' - 'A')) - 'a' \ | ||
| 28 | <= 'z' - 'a') | ||
| 29 | # define FILE_SYSTEM_PREFIX_LEN(Filename) \ | ||
| 30 | (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':' ? 2 : 0) | ||
| 31 | # ifndef __CYGWIN__ | ||
| 32 | # define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1 | ||
| 33 | # endif | ||
| 34 | # define ISSLASH(C) ((C) == '/' || (C) == '\\') | ||
| 35 | #else | ||
| 36 | # define FILE_SYSTEM_PREFIX_LEN(Filename) 0 | ||
| 37 | # define ISSLASH(C) ((C) == '/') | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #ifndef FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE | ||
| 41 | # define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE | ||
| 45 | # define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) | ||
| 46 | # else | ||
| 47 | # define IS_ABSOLUTE_FILE_NAME(F) \ | ||
| 48 | (ISSLASH ((F)[0]) || FILE_SYSTEM_PREFIX_LEN (F) != 0) | ||
| 49 | #endif | ||
| 50 | #define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) | ||
| 51 | |||
| 52 | #endif /* DOSNAME_H_ */ | ||
diff --git a/lib/filename.h b/lib/filename.h new file mode 100644 index 00000000000..4598fb1d638 --- /dev/null +++ b/lib/filename.h | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | /* Basic filename support macros. | ||
| 2 | Copyright (C) 2001-2004, 2007-2020 Free Software Foundation, Inc. | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation; either version 3 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 16 | |||
| 17 | /* From Paul Eggert and Jim Meyering. */ | ||
| 18 | |||
| 19 | #ifndef _FILENAME_H | ||
| 20 | #define _FILENAME_H | ||
| 21 | |||
| 22 | #include <string.h> | ||
| 23 | |||
| 24 | #ifdef __cplusplus | ||
| 25 | extern "C" { | ||
| 26 | #endif | ||
| 27 | |||
| 28 | |||
| 29 | /* Filename support. | ||
| 30 | ISSLASH(C) tests whether C is a directory separator | ||
| 31 | character. | ||
| 32 | HAS_DEVICE(Filename) tests whether Filename contains a device | ||
| 33 | specification. | ||
| 34 | FILE_SYSTEM_PREFIX_LEN(Filename) length of the device specification | ||
| 35 | at the beginning of Filename, | ||
| 36 | index of the part consisting of | ||
| 37 | alternating components and slashes. | ||
| 38 | FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE | ||
| 39 | 1 when a non-empty device specification | ||
| 40 | can be followed by an empty or relative | ||
| 41 | part, | ||
| 42 | 0 when a non-empty device specification | ||
| 43 | must be followed by a slash, | ||
| 44 | 0 when device specification don't exist. | ||
| 45 | IS_ABSOLUTE_FILE_NAME(Filename) | ||
| 46 | tests whether Filename is independent of | ||
| 47 | any notion of "current directory". | ||
| 48 | IS_RELATIVE_FILE_NAME(Filename) | ||
| 49 | tests whether Filename may be concatenated | ||
| 50 | to a directory filename. | ||
| 51 | Note: On native Windows, OS/2, DOS, "c:" is neither an absolute nor a | ||
| 52 | relative file name! | ||
| 53 | IS_FILE_NAME_WITH_DIR(Filename) tests whether Filename contains a device | ||
| 54 | or directory specification. | ||
| 55 | */ | ||
| 56 | #if defined _WIN32 || defined __CYGWIN__ \ | ||
| 57 | || defined __EMX__ || defined __MSDOS__ || defined __DJGPP__ | ||
| 58 | /* Native Windows, Cygwin, OS/2, DOS */ | ||
| 59 | # define ISSLASH(C) ((C) == '/' || (C) == '\\') | ||
| 60 | /* Internal macro: Tests whether a character is a drive letter. */ | ||
| 61 | # define _IS_DRIVE_LETTER(C) \ | ||
| 62 | (((C) >= 'A' && (C) <= 'Z') || ((C) >= 'a' && (C) <= 'z')) | ||
| 63 | /* Help the compiler optimizing it. This assumes ASCII. */ | ||
| 64 | # undef _IS_DRIVE_LETTER | ||
| 65 | # define _IS_DRIVE_LETTER(C) \ | ||
| 66 | (((unsigned int) (C) | ('a' - 'A')) - 'a' <= 'z' - 'a') | ||
| 67 | # define HAS_DEVICE(Filename) \ | ||
| 68 | (_IS_DRIVE_LETTER ((Filename)[0]) && (Filename)[1] == ':') | ||
| 69 | # define FILE_SYSTEM_PREFIX_LEN(Filename) (HAS_DEVICE (Filename) ? 2 : 0) | ||
| 70 | # ifdef __CYGWIN__ | ||
| 71 | # define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 | ||
| 72 | # else | ||
| 73 | /* On native Windows, OS/2, DOS, the system has the notion of a | ||
| 74 | "current directory" on each drive. */ | ||
| 75 | # define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 1 | ||
| 76 | # endif | ||
| 77 | # if FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE | ||
| 78 | # define IS_ABSOLUTE_FILE_NAME(Filename) \ | ||
| 79 | ISSLASH ((Filename)[FILE_SYSTEM_PREFIX_LEN (Filename)]) | ||
| 80 | # else | ||
| 81 | # define IS_ABSOLUTE_FILE_NAME(Filename) \ | ||
| 82 | (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename)) | ||
| 83 | # endif | ||
| 84 | # define IS_RELATIVE_FILE_NAME(Filename) \ | ||
| 85 | (! (ISSLASH ((Filename)[0]) || HAS_DEVICE (Filename))) | ||
| 86 | # define IS_FILE_NAME_WITH_DIR(Filename) \ | ||
| 87 | (strchr ((Filename), '/') != NULL || strchr ((Filename), '\\') != NULL \ | ||
| 88 | || HAS_DEVICE (Filename)) | ||
| 89 | #else | ||
| 90 | /* Unix */ | ||
| 91 | # define ISSLASH(C) ((C) == '/') | ||
| 92 | # define HAS_DEVICE(Filename) ((void) (Filename), 0) | ||
| 93 | # define FILE_SYSTEM_PREFIX_LEN(Filename) ((void) (Filename), 0) | ||
| 94 | # define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0 | ||
| 95 | # define IS_ABSOLUTE_FILE_NAME(Filename) ISSLASH ((Filename)[0]) | ||
| 96 | # define IS_RELATIVE_FILE_NAME(Filename) (! ISSLASH ((Filename)[0])) | ||
| 97 | # define IS_FILE_NAME_WITH_DIR(Filename) (strchr ((Filename), '/') != NULL) | ||
| 98 | #endif | ||
| 99 | |||
| 100 | /* Deprecated macros. For backward compatibility with old users of the | ||
| 101 | 'filename' module. */ | ||
| 102 | #define IS_ABSOLUTE_PATH IS_ABSOLUTE_FILE_NAME | ||
| 103 | #define IS_PATH_WITH_DIR IS_FILE_NAME_WITH_DIR | ||
| 104 | |||
| 105 | |||
| 106 | #ifdef __cplusplus | ||
| 107 | } | ||
| 108 | #endif | ||
| 109 | |||
| 110 | #endif /* _FILENAME_H */ | ||
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index e90d2e39049..256bda7752e 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in | |||
| @@ -1672,6 +1672,15 @@ EXTRA_DIST += filemode.h | |||
| 1672 | endif | 1672 | endif |
| 1673 | ## end gnulib module filemode | 1673 | ## end gnulib module filemode |
| 1674 | 1674 | ||
| 1675 | ## begin gnulib module filename | ||
| 1676 | ifeq (,$(OMIT_GNULIB_MODULE_filename)) | ||
| 1677 | |||
| 1678 | |||
| 1679 | EXTRA_DIST += filename.h | ||
| 1680 | |||
| 1681 | endif | ||
| 1682 | ## end gnulib module filename | ||
| 1683 | |||
| 1675 | ## begin gnulib module filevercmp | 1684 | ## begin gnulib module filevercmp |
| 1676 | ifeq (,$(OMIT_GNULIB_MODULE_filevercmp)) | 1685 | ifeq (,$(OMIT_GNULIB_MODULE_filevercmp)) |
| 1677 | 1686 | ||
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 3228aa42b57..f92222dd771 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 | |||
| @@ -87,6 +87,7 @@ AC_DEFUN([gl_EARLY], | |||
| 87 | # Code from module fcntl-h: | 87 | # Code from module fcntl-h: |
| 88 | # Code from module fdopendir: | 88 | # Code from module fdopendir: |
| 89 | # Code from module filemode: | 89 | # Code from module filemode: |
| 90 | # Code from module filename: | ||
| 90 | # Code from module filevercmp: | 91 | # Code from module filevercmp: |
| 91 | # Code from module flexmember: | 92 | # Code from module flexmember: |
| 92 | # Code from module fpending: | 93 | # Code from module fpending: |
| @@ -977,6 +978,7 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 977 | lib/fdopendir.c | 978 | lib/fdopendir.c |
| 978 | lib/filemode.c | 979 | lib/filemode.c |
| 979 | lib/filemode.h | 980 | lib/filemode.h |
| 981 | lib/filename.h | ||
| 980 | lib/filevercmp.c | 982 | lib/filevercmp.c |
| 981 | lib/filevercmp.h | 983 | lib/filevercmp.h |
| 982 | lib/flexmember.h | 984 | lib/flexmember.h |