diff --git a/sys/conf/files b/sys/conf/files index 3a282325ffc..80fbfb7496b 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 a07a2d06e7c..9376b22a49a 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 -__FBSDID("$FreeBSD$"); - /* * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6. * Compares a filename or pathname to a pattern. */ -#include -#include -#include -#include - -#include "collate.h" +#include +#include +#include #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 f050f06e2d3..2ad98466ecb 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 / after Imatch. */ +#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ +#define FNM_IGNORECASE FNM_CASEFOLD +#define FNM_FILE_NAME FNM_PATHNAME + #endif /* !_SYS_LIBKERN_H_ */