Import the libc fnmatch() into the kernel. This will be used by,

among other things, the DEVFS rule subsystem to match nodes against a
path pattern supplied by the user.

fnmatch.c was repo-copied from src/lib/libc/gen/fnmatch.c, and the
only changes to it are those necessary to make it compile in the
kernel.  The relevant parts of fnmatch.h were imported into libkern.h.

Approved by:	-arch
This commit is contained in:
Dima Dorfman 2002-10-08 04:15:55 +00:00
parent c4598a8916
commit 20a6cb8cb8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=104652
3 changed files with 23 additions and 20 deletions

View File

@ -1031,6 +1031,7 @@ libkern/index.c standard
libkern/inet_ntoa.c standard
libkern/mcount.c optional profiling-routine
libkern/qsort.c standard
libkern/fnmatch.c standard
libkern/random.c standard
libkern/rindex.c standard
libkern/scanc.c standard

View File

@ -32,25 +32,18 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
* Compares a filename or pathname to a pattern.
*/
#include <ctype.h>
#include <fnmatch.h>
#include <string.h>
#include <stdio.h>
#include "collate.h"
#include <sys/param.h>
#include <sys/ctype.h>
#include <sys/libkern.h>
#define EOS '\0'
@ -101,12 +94,12 @@ fnmatch(pattern, string, flags)
if (c == EOS)
if (flags & FNM_PATHNAME)
return ((flags & FNM_LEADING_DIR) ||
strchr(string, '/') == NULL ?
index(string, '/') == NULL ?
0 : FNM_NOMATCH);
else
return (0);
else if (c == '/' && flags & FNM_PATHNAME) {
if ((string = strchr(string, '/')) == NULL)
if ((string = index(string, '/')) == NULL)
return (FNM_NOMATCH);
break;
}
@ -218,16 +211,12 @@ rangematch(pattern, test, flags, newp)
if (flags & FNM_CASEFOLD)
c2 = tolower((unsigned char)c2);
if (__collate_load_error ?
c <= test && test <= c2 :
__collate_range_cmp(c, test) <= 0
&& __collate_range_cmp(test, c2) <= 0
)
if (c <= test && test <= c2)
ok = 1;
} else if (c == test)
ok = 1;
} while ((c = *pattern++) != ']');
*newp = (char *)pattern;
*newp = (char *)(uintptr_t)pattern;
return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH);
}

View File

@ -74,6 +74,7 @@ int ffs(int);
#ifndef HAVE_INLINE_FLS
int fls(int);
#endif
int fnmatch(const char *, const char *, int);
int locc(int, char *, u_int);
void qsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
@ -113,4 +114,16 @@ memset(void *b, int c, size_t len)
return (b);
}
/* fnmatch() return values. */
#define FNM_NOMATCH 1 /* Match failed. */
/* fnmatch() flags. */
#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
#define FNM_PERIOD 0x04 /* Period must be matched by period. */
#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
#define FNM_CASEFOLD 0x10 /* Case insensitive search. */
#define FNM_IGNORECASE FNM_CASEFOLD
#define FNM_FILE_NAME FNM_PATHNAME
#endif /* !_SYS_LIBKERN_H_ */