libxbps: move xbps_pkgpattern_match to util.c and simplify.
This commit is contained in:
25
lib/util.c
25
lib/util.c
@@ -33,7 +33,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
@@ -304,3 +304,26 @@ xbps_xasprintf(const char *fmt, ...)
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Match pkg against pattern, return 1 if matching, 0 otherwise or -1 on error.
|
||||
*/
|
||||
int
|
||||
xbps_pkgpattern_match(const char *pkg, const char *pattern)
|
||||
{
|
||||
/* simple match on "pkg" against "pattern */
|
||||
if (strcmp(pattern, pkg) == 0)
|
||||
return 1;
|
||||
|
||||
/* perform relational dewey match on version number */
|
||||
if (strpbrk(pattern, "<>") != NULL)
|
||||
return dewey_match(pattern, pkg);
|
||||
|
||||
/* glob match */
|
||||
if (strpbrk(pattern, "*?[]") != NULL)
|
||||
if (fnmatch(pattern, pkg, FNM_PERIOD) == 0)
|
||||
return 1;
|
||||
|
||||
/* no match */
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user