Source-Changes-HG archive

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

[src/trunk]: src implement FNM_LEADING_DIR; matches Linux and other *BSDs; ap...



details:   https://anonhg.NetBSD.org/src/rev/97a43c9dc93a
branches:  trunk
changeset: 537818:97a43c9dc93a
user:      provos <provos%NetBSD.org@localhost>
date:      Sun Oct 06 03:15:45 2002 +0000

description:
implement FNM_LEADING_DIR; matches Linux and other *BSDs; approved thorpej

diffstat:

 include/fnmatch.h      |  3 ++-
 lib/libc/gen/fnmatch.3 |  8 +++++++-
 lib/libc/gen/fnmatch.c |  9 ++++++---
 3 files changed, 15 insertions(+), 5 deletions(-)

diffs (76 lines):

diff -r 045cc72889d0 -r 97a43c9dc93a include/fnmatch.h
--- a/include/fnmatch.h Sun Oct 06 03:00:02 2002 +0000
+++ b/include/fnmatch.h Sun Oct 06 03:15:45 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fnmatch.h,v 1.8 2001/10/27 15:41:18 kleink Exp $       */
+/*     $NetBSD: fnmatch.h,v 1.9 2002/10/06 03:15:45 provos Exp $       */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -48,6 +48,7 @@
 #define        FNM_PERIOD      0x04    /* Period must be matched by period. */
 #if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
 #define        FNM_CASEFOLD    0x08    /* Pattern is matched case-insensitive */
+#define        FNM_LEADING_DIR 0x10    /* Ignore /<tail> after Imatch. */
 #endif
 
 #include <sys/cdefs.h>
diff -r 045cc72889d0 -r 97a43c9dc93a lib/libc/gen/fnmatch.3
--- a/lib/libc/gen/fnmatch.3    Sun Oct 06 03:00:02 2002 +0000
+++ b/lib/libc/gen/fnmatch.3    Sun Oct 06 03:15:45 2002 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: fnmatch.3,v 1.17 2002/02/07 07:00:11 ross Exp $
+.\"    $NetBSD: fnmatch.3,v 1.18 2002/10/06 03:15:46 provos Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -98,6 +98,12 @@
 .Dv FNM_PATHNAME
 is set,
 a period is ``leading'' if it immediately follows a slash.
+.It Dv FNM_LEADING_DIR
+Ignore
+.Nm /*
+rest after successful
+.Fa pattern
+matching.
 .It Dv FNM_CASEFOLD
 The pattern is matched in a case-insensitive fashion.
 .El
diff -r 045cc72889d0 -r 97a43c9dc93a lib/libc/gen/fnmatch.c
--- a/lib/libc/gen/fnmatch.c    Sun Oct 06 03:00:02 2002 +0000
+++ b/lib/libc/gen/fnmatch.c    Sun Oct 06 03:15:45 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fnmatch.c,v 1.18 2000/06/28 01:13:36 thorpej Exp $     */
+/*     $NetBSD: fnmatch.c,v 1.19 2002/10/06 03:15:46 provos Exp $      */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)fnmatch.c  8.2 (Berkeley) 4/16/94";
 #else
-__RCSID("$NetBSD: fnmatch.c,v 1.18 2000/06/28 01:13:36 thorpej Exp $");
+__RCSID("$NetBSD: fnmatch.c,v 1.19 2002/10/06 03:15:46 provos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -90,6 +90,8 @@
        for (stringstart = string;;)
                switch (c = FOLDCASE(*pattern++, flags)) {
                case EOS:
+                       if ((flags & FNM_LEADING_DIR) && *string == '/')
+                               return (0);
                        return (*string == EOS ? 0 : FNM_NOMATCH);
                case '?':
                        if (*string == EOS)
@@ -116,7 +118,8 @@
                        /* Optimize for pattern with * at end or before /. */
                        if (c == EOS) {
                                if (flags & FNM_PATHNAME)
-                                       return (strchr(string, '/') == NULL ?
+                                       return ((flags & FNM_LEADING_DIR) ||
+                                           strchr(string, '/') == NULL ?
                                            0 : FNM_NOMATCH);
                                else
                                        return (0);



Home | Main Index | Thread Index | Old Index