summaryrefslogtreecommitdiff
path: root/ar.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>1993-06-10 22:13:54 +0000
committerRoland McGrath <roland@redhat.com>1993-06-10 22:13:54 +0000
commitd66f4e340716ee7057e956e28df6179710314521 (patch)
tree1d9bcedc4070c962cafbdafc1da97411350a1283 /ar.c
parent4abb5e433f41e6a35b91a23f5b9ba63077775b9b (diff)
downloadgunmake-d66f4e340716ee7057e956e28df6179710314521.tar.gz
Formerly ar.c.~5~
Diffstat (limited to 'ar.c')
-rw-r--r--ar.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/ar.c b/ar.c
index 726ceb9..29ee43b 100644
--- a/ar.c
+++ b/ar.c
@@ -225,6 +225,40 @@ ar_glob_alphacompare (a, b)
return strcmp (*a, *b);
}
+/* Return nonzero if PATTERN contains any metacharacters.
+ Metacharacters can be quoted with backslashes if QUOTE is nonzero. */
+static int
+glob_pattern_p (pattern, quote)
+ const char *pattern;
+ const int quote;
+{
+ register const char *p;
+ int open = 0;
+
+ for (p = pattern; *p != '\0'; ++p)
+ switch (*p)
+ {
+ case '?':
+ case '*':
+ return 1;
+
+ case '\\':
+ if (quote)
+ ++p;
+ break;
+
+ case '[':
+ open = 1;
+ break;
+
+ case ']':
+ if (open)
+ return 1;
+ break;
+ }
+
+ return 0;
+}
/* Glob for MEMBER_PATTERN in archive ARNAME.
Return a malloc'd chain of matching elements (or nil if none). */
@@ -239,6 +273,9 @@ ar_glob (arname, member_pattern, size)
struct nameseq *n;
unsigned int i;
+ if (! glob_pattern_p (member_pattern, 1))
+ return 0;
+
/* Scan the archive for matches.
ar_glob_match will accumulate them in STATE.chain. */
i = strlen (arname);