summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authordd <dd@FreeBSD.org>2002-10-08 04:15:55 +0000
committerdd <dd@FreeBSD.org>2002-10-08 04:15:55 +0000
commitad775810328c27239d98ff30a2094979615da054 (patch)
treeb4cc92ca4e8e38d896ee5d8b07b785e538d94644 /sys
parent2af88da4a811029879c8a1c6e91242798f884bd2 (diff)
downloadFreeBSD-src-ad775810328c27239d98ff30a2094979615da054.zip
FreeBSD-src-ad775810328c27239d98ff30a2094979615da054.tar.gz
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
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/files1
-rw-r--r--sys/libkern/fnmatch.c29
-rw-r--r--sys/sys/libkern.h13
3 files changed, 23 insertions, 20 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 3a28232..80fbfb7 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -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
diff --git a/sys/libkern/fnmatch.c b/sys/libkern/fnmatch.c
index a07a2d0..9376b22 100644
--- a/sys/libkern/fnmatch.c
+++ b/sys/libkern/fnmatch.c
@@ -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);
}
diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h
index f050f06..2ad9846 100644
--- a/sys/sys/libkern.h
+++ b/sys/sys/libkern.h
@@ -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_ */
OpenPOWER on IntegriCloud