summaryrefslogtreecommitdiffstats
path: root/src/pacman/util.c
diff options
context:
space:
mode:
authorJudd Vinet <judd@archlinux.org>2005-10-08 01:29:49 +0200
committerJudd Vinet <judd@archlinux.org>2005-10-08 01:29:49 +0200
commit5ef51b3e266cf43411947248886372001fdb207a (patch)
tree8d255349530045686053faacd1804502a96b269c /src/pacman/util.c
parent79031ccd1a544475162facb8ca3d671f3464d1f8 (diff)
downloadpacman-5ef51b3e266cf43411947248886372001fdb207a.tar.gz
pacman-5ef51b3e266cf43411947248886372001fdb207a.tar.xz
Merging in recent fixes/additions from 2.9.7
Diffstat (limited to 'src/pacman/util.c')
-rw-r--r--src/pacman/util.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 1d3844a3..5a60070b 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -29,6 +29,7 @@
#include <ctype.h>
#include <dirent.h>
#include <unistd.h>
+#include <regex.h>
#ifdef CYGWIN
#include <limits.h> /* PATH_MAX */
#endif
@@ -224,4 +225,19 @@ int yesno(char *fmt, ...)
return(0);
}
+/* match a string against a regular expression */
+int reg_match(char *string, char *pattern)
+{
+ int result;
+ regex_t reg;
+
+ if(regcomp(&reg, pattern, REG_EXTENDED | REG_NOSUB | REG_ICASE) != 0) {
+ fprintf(stderr, "error: %s is not a valid regular expression.\n", pattern);
+ return(-1);
+ }
+ result = regexec(&reg, string, 0, 0, 0);
+ regfree(&reg);
+ return(!(result));
+}
+
/* vim: set ts=2 sw=2 noet: */