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

This commit is contained in:
provos 2002-10-06 03:15:45 +00:00
parent d1c3210192
commit b899aa2abc
3 changed files with 15 additions and 5 deletions

View File

@ -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>

View File

@ -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 @@ Additionally, if
.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

View File

@ -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 @@ fnmatch(pattern, string, flags)
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 @@ fnmatch(pattern, string, flags)
/* 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);