Last change
on this file since 3573 was 3320, checked in by Bruno Cornec, 10 years ago |
- Re-add (thanks git BTW) the 2.2.9 branch which had been destroyed in
the move to 3.0
|
-
Property svn:eol-style
set to
native
|
File size:
1.2 KB
|
Rev | Line | |
---|
[3320] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * Copyright (C) 2002 by Glenn McGrath
|
---|
| 4 | *
|
---|
| 5 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include <fnmatch.h>
|
---|
| 9 | #include "libbb.h"
|
---|
| 10 | #include "archive.h"
|
---|
| 11 |
|
---|
| 12 | /* Find a string in a shell pattern list */
|
---|
| 13 | const llist_t* FAST_FUNC find_list_entry(const llist_t *list, const char *filename)
|
---|
| 14 | {
|
---|
| 15 | while (list) {
|
---|
| 16 | if (fnmatch(list->data, filename, 0) == 0) {
|
---|
| 17 | return list;
|
---|
| 18 | }
|
---|
| 19 | list = list->link;
|
---|
| 20 | }
|
---|
| 21 | return NULL;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | /* Same, but compares only path components present in pattern
|
---|
| 25 | * (extra trailing path components in filename are assumed to match)
|
---|
| 26 | */
|
---|
| 27 | const llist_t* FAST_FUNC find_list_entry2(const llist_t *list, const char *filename)
|
---|
| 28 | {
|
---|
| 29 | char buf[PATH_MAX];
|
---|
| 30 | int pattern_slash_cnt;
|
---|
| 31 | const char *c;
|
---|
| 32 | char *d;
|
---|
| 33 |
|
---|
| 34 | while (list) {
|
---|
| 35 | c = list->data;
|
---|
| 36 | pattern_slash_cnt = 0;
|
---|
| 37 | while (*c)
|
---|
| 38 | if (*c++ == '/') pattern_slash_cnt++;
|
---|
| 39 | c = filename;
|
---|
| 40 | d = buf;
|
---|
| 41 | /* paranoia is better than buffer overflows */
|
---|
| 42 | while (*c && d != buf + sizeof(buf)-1) {
|
---|
| 43 | if (*c == '/' && --pattern_slash_cnt < 0)
|
---|
| 44 | break;
|
---|
| 45 | *d++ = *c++;
|
---|
| 46 | }
|
---|
| 47 | *d = '\0';
|
---|
| 48 | if (fnmatch(list->data, buf, 0) == 0) {
|
---|
| 49 | return list;
|
---|
| 50 | }
|
---|
| 51 | list = list->link;
|
---|
| 52 | }
|
---|
| 53 | return NULL;
|
---|
| 54 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.