summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1993-03-28 19:25:12 +0000
committerJim Meyering <jim@meyering.net>1993-03-28 19:25:12 +0000
commit07fc05974df6ec335447f994e9b1df774ab364c3 (patch)
tree0fac6bec40ea7e6402659d50a726e76ba4ec4b49
parentd204e1f6e1b40214c4e4a2f858ad7c99a3ef610d (diff)
downloadgnulib-07fc05974df6ec335447f994e9b1df774ab364c3.tar.gz
GNU file utilitiesFILEUTILS-3_4_1
-rw-r--r--lib/backupfile.c29
-rw-r--r--lib/dirname.c4
-rw-r--r--lib/fnmatch.c58
-rw-r--r--lib/fnmatch.h26
-rw-r--r--lib/idcache.c2
-rw-r--r--lib/makepath.c4
-rw-r--r--lib/mountlist.c2
-rw-r--r--lib/savedir.c32
-rw-r--r--lib/strdup.c4
-rw-r--r--lib/stripslash.c2
-rw-r--r--lib/userspec.c2
-rw-r--r--lib/xstrdup.c2
12 files changed, 85 insertions, 82 deletions
diff --git a/lib/backupfile.c b/lib/backupfile.c
index c6d7914a67..94bb55a269 100644
--- a/lib/backupfile.c
+++ b/lib/backupfile.c
@@ -15,14 +15,14 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-/* David MacKenzie <djm@ai.mit.edu>.
+/* David MacKenzie <djm@gnu.ai.mit.edu>.
Some algorithms adapted from GNU Emacs. */
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include "backupfile.h"
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#define index strchr
#define rindex strrchr
@@ -30,25 +30,22 @@
#include <strings.h>
#endif
-#ifdef DIRENT
+#if defined(DIRENT) || defined(_POSIX_VERSION)
#include <dirent.h>
-#ifdef direct
-#undef direct
-#endif
-#define direct dirent
#define NLENGTH(direct) (strlen((direct)->d_name))
-#else /* !DIRENT */
+#else /* not (DIRENT or _POSIX_VERSION) */
+#define dirent direct
#define NLENGTH(direct) ((direct)->d_namlen)
-#ifdef USG
#ifdef SYSNDIR
#include <sys/ndir.h>
-#else /* !SYSNDIR */
-#include <ndir.h>
-#endif /* !SYSNDIR */
-#else /* !USG */
+#endif /* SYSNDIR */
+#ifdef SYSDIR
#include <sys/dir.h>
-#endif /* !USG */
-#endif /* !DIRENT */
+#endif /* SYSDIR */
+#ifdef NDIR
+#include <ndir.h>
+#endif /* NDIR */
+#endif /* DIRENT or _POSIX_VERSION */
#ifdef VOID_CLOSEDIR
/* Fake a return value. */
@@ -138,7 +135,7 @@ max_backup_version (file, dir)
char *file, *dir;
{
DIR *dirp;
- struct direct *dp;
+ struct dirent *dp;
int highest_version;
int this_version;
int file_name_length;
diff --git a/lib/dirname.c b/lib/dirname.c
index 82deea7b4a..5a92ce557f 100644
--- a/lib/dirname.c
+++ b/lib/dirname.c
@@ -20,9 +20,11 @@
#else
char *malloc ();
#endif
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
+#ifndef rindex
#define rindex strrchr
+#endif
#else
#include <strings.h>
#endif
diff --git a/lib/fnmatch.c b/lib/fnmatch.c
index 525e6a85e8..be662d9d25 100644
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -16,16 +16,13 @@ not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <errno.h>
-#include "fnmatch.h"
+#include <fnmatch.h>
+#include <ctype.h>
#if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
extern int errno;
#endif
-#if !__STDC__
-#define const
-#endif
-
/* Match STRING against the filename pattern PATTERN, returning zero if
it matches, nonzero if not. */
int
@@ -37,40 +34,42 @@ fnmatch (pattern, string, flags)
register const char *p = pattern, *n = string;
register char c;
- if ((flags & ~__FNM_FLAGS) != 0)
- {
- errno = EINVAL;
- return -1;
- }
+/* Note that this evalutes C many times. */
+#define FOLD(c) ((flags & FNM_CASEFOLD) && isupper (c) ? tolower (c) : (c))
while ((c = *p++) != '\0')
{
+ c = FOLD (c);
+
switch (c)
{
case '?':
if (*n == '\0')
return FNM_NOMATCH;
- else if ((flags & FNM_PATHNAME) && *n == '/')
+ else if ((flags & FNM_FILE_NAME) && *n == '/')
return FNM_NOMATCH;
else if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
break;
case '\\':
if (!(flags & FNM_NOESCAPE))
- c = *p++;
- if (*n != c)
+ {
+ c = *p++;
+ c = FOLD (c);
+ }
+ if (FOLD (*n) != c)
return FNM_NOMATCH;
break;
case '*':
if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
for (c = *p++; c == '?' || c == '*'; c = *p++, ++n)
- if (((flags & FNM_PATHNAME) && *n == '/') ||
+ if (((flags & FNM_FILE_NAME) && *n == '/') ||
(c == '?' && *n == '\0'))
return FNM_NOMATCH;
@@ -78,9 +77,9 @@ fnmatch (pattern, string, flags)
return 0;
{
- char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
+ char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? FOLD (*p) : c;
for (--p; *n != '\0'; ++n)
- if ((c == '[' || *n == c1) &&
+ if ((c == '[' || FOLD (*n) == c1) &&
fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
return 0;
return FNM_NOMATCH;
@@ -95,7 +94,7 @@ fnmatch (pattern, string, flags)
return FNM_NOMATCH;
if ((flags & FNM_PERIOD) && *n == '.' &&
- (n == string || ((flags & FNM_PATHNAME) && n[-1] == '/')))
+ (n == string || ((flags & FNM_FILE_NAME) && n[-1] == '/')))
return FNM_NOMATCH;
not = (*p == '!' || *p == '^');
@@ -110,13 +109,16 @@ fnmatch (pattern, string, flags)
if (!(flags & FNM_NOESCAPE) && c == '\\')
cstart = cend = *p++;
+ cstart = cend = FOLD (cstart);
+
if (c == '\0')
/* [ (unterminated) loses. */
return FNM_NOMATCH;
c = *p++;
+ c = FOLD (c);
- if ((flags & FNM_PATHNAME) && c == '/')
+ if ((flags & FNM_FILE_NAME) && c == '/')
/* [/] can never match. */
return FNM_NOMATCH;
@@ -127,10 +129,12 @@ fnmatch (pattern, string, flags)
cend = *p++;
if (cend == '\0')
return FNM_NOMATCH;
+ cend = FOLD (cend);
+
c = *p++;
}
- if (*n >= cstart && *n <= cend)
+ if (FOLD (*n) >= cstart && FOLD (*n) <= cend)
goto matched;
if (c == ']')
@@ -150,7 +154,7 @@ fnmatch (pattern, string, flags)
c = *p++;
if (!(flags & FNM_NOESCAPE) && c == '\\')
- /* 1003.2d11 is unclear if this is right. %%% */
+ /* XXX 1003.2d11 is unclear if this is right. */
++p;
}
if (not)
@@ -159,14 +163,18 @@ fnmatch (pattern, string, flags)
break;
default:
- if (c != *n)
+ if (c != FOLD (*n))
return FNM_NOMATCH;
}
++n;
}
- if (*n == '\0' || ((flags & FNM_TARPATH) && *n == '/'))
+ if (*n == '\0')
+ return 0;
+
+ if ((flags & FNM_LEADING_DIR) && *n == '/')
+ /* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
return 0;
return FNM_NOMATCH;
diff --git a/lib/fnmatch.h b/lib/fnmatch.h
index 0b3588a6e0..2289f6345d 100644
--- a/lib/fnmatch.h
+++ b/lib/fnmatch.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
@@ -20,8 +20,7 @@ Cambridge, MA 02139, USA. */
#define _FNMATCH_H 1
#ifdef __cplusplus
-extern "C"
-{
+extern "C" {
#endif
#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
@@ -35,14 +34,14 @@ extern "C"
#endif /* C++ or ANSI C. */
/* Bits set in the FLAGS argument to `fnmatch'. */
-#define FNM_PATHNAME (1 << 0)/* No wildcard can ever match `/'. */
-#define FNM_NOESCAPE (1 << 1)/* Backslashes don't quote special chars. */
-#define FNM_PERIOD (1 << 2)/* Leading `.' is matched only explicitly. */
-#define FNM_TARPATH (1 << 4)/* Ignore `/...' after a match. */
-#define __FNM_FLAGS (FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD|FNM_TARPATH)
-
-#if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_BSD_SOURCE)
-#define FNM_FILE_NAME FNM_PATHNAME
+#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
+#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
+#define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */
+
+#if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_GNU_SOURCE)
+#define FNM_FILE_NAME FNM_PATHNAME /* Preferred GNU name. */
+#define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */
+#define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */
#endif
/* Value returned by `fnmatch' if STRING does not match PATTERN. */
@@ -50,12 +49,11 @@ extern "C"
/* Match STRING against the filename pattern PATTERN,
returning zero if it matches, FNM_NOMATCH if not. */
- extern int fnmatch __P ((const char *__pattern, const char *__string,
- int __flags));
+extern int fnmatch __P ((const char *__pattern, const char *__string,
+ int __flags));
#ifdef __cplusplus
}
-
#endif
#endif /* fnmatch.h */
diff --git a/lib/idcache.c b/lib/idcache.c
index 3e5f134ae7..dd9c366b16 100644
--- a/lib/idcache.c
+++ b/lib/idcache.c
@@ -20,7 +20,7 @@
#include <pwd.h>
#include <grp.h>
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#else
#include <strings.h>
diff --git a/lib/makepath.c b/lib/makepath.c
index 5c6112414c..12da458cf2 100644
--- a/lib/makepath.c
+++ b/lib/makepath.c
@@ -49,7 +49,7 @@ char *alloca ();
extern int errno;
#endif
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#define index strchr
#else
@@ -127,7 +127,7 @@ make_path (argpath, mode, parent_mode, owner, group, verbose_fmt_string)
slash = dirpath;
while (*slash == '/')
slash++;
- while (slash = index (slash, '/'))
+ while ((slash = index (slash, '/')))
{
*slash = '\0';
if (stat (dirpath, &stats))
diff --git a/lib/mountlist.c b/lib/mountlist.c
index 78955f709d..88fda7a615 100644
--- a/lib/mountlist.c
+++ b/lib/mountlist.c
@@ -24,7 +24,7 @@
#else
void free ();
#endif
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#else
#include <strings.h>
diff --git a/lib/savedir.c b/lib/savedir.c
index fce61da0d6..d89adc0a09 100644
--- a/lib/savedir.c
+++ b/lib/savedir.c
@@ -15,28 +15,30 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-/* Written by David MacKenzie <djm@ai.mit.edu>. */
+/* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */
#include <sys/types.h>
-#ifdef DIRENT
-#include <dirent.h>
-#ifdef direct
-#undef direct
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
#endif
-#define direct dirent
+
+#if defined(DIRENT) || defined(_POSIX_VERSION)
+#include <dirent.h>
#define NLENGTH(direct) (strlen((direct)->d_name))
-#else
+#else /* not (DIRENT or _POSIX_VERSION) */
+#define dirent direct
#define NLENGTH(direct) ((direct)->d_namlen)
-#ifdef USG
#ifdef SYSNDIR
#include <sys/ndir.h>
-#else
-#include <ndir.h>
-#endif
-#else
+#endif /* SYSNDIR */
+#ifdef SYSDIR
#include <sys/dir.h>
-#endif
-#endif
+#endif /* SYSDIR */
+#ifdef NDIR
+#include <ndir.h>
+#endif /* NDIR */
+#endif /* DIRENT or _POSIX_VERSION */
#ifdef VOID_CLOSEDIR
/* Fake a return value. */
@@ -71,7 +73,7 @@ savedir (dir, name_size)
unsigned name_size;
{
DIR *dirp;
- struct direct *dp;
+ struct dirent *dp;
char *name_space;
char *namep;
diff --git a/lib/strdup.c b/lib/strdup.c
index 078c69b6eb..b137db2d95 100644
--- a/lib/strdup.c
+++ b/lib/strdup.c
@@ -23,10 +23,6 @@ char *malloc ();
char *strcpy ();
#endif
-#if !__STDC__
-#define const
-#endif
-
/* Return a newly allocated copy of STR,
or 0 if out of memory. */
diff --git a/lib/stripslash.c b/lib/stripslash.c
index 802204f25f..2971d4ced0 100644
--- a/lib/stripslash.c
+++ b/lib/stripslash.c
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#if defined(STDC_HEADERS) || defined(USG)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#else
#include <strings.h>
diff --git a/lib/userspec.c b/lib/userspec.c
index 60c6ecc1aa..a417cca4ce 100644
--- a/lib/userspec.c
+++ b/lib/userspec.c
@@ -22,7 +22,7 @@
#include <pwd.h>
#include <grp.h>
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#define index strchr
#else
diff --git a/lib/xstrdup.c b/lib/xstrdup.c
index da39db3e37..9588bc78d1 100644
--- a/lib/xstrdup.c
+++ b/lib/xstrdup.c
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#if defined(USG) || defined(STDC_HEADERS)
+#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#else
#include <strings.h>