X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/aec75b037b9296961699d2fd5e8ab58859fed2ff..0f78b81511be65d8fe21af1e6ac674f9e80ac29d:/wildtest.c diff --git a/wildtest.c b/wildtest.c index 09a49c22..5286b64b 100644 --- a/wildtest.c +++ b/wildtest.c @@ -1,13 +1,29 @@ /* -** wildmatch test suite. -*/ + * Test suite for the wildmatch code. + * + * Copyright (C) 2003, 2004, 2006 Wayne Davison + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ /*#define COMPARE_WITH_FNMATCH*/ #define WILD_TEST_ITERATIONS #include "lib/wildmatch.c" -#include "popt.h" +#include #ifdef COMPARE_WITH_FNMATCH #include @@ -47,37 +63,25 @@ run_test(int line, bool matches, bool same_as_fnmatch, #endif if (explode_mod) { - static char *buf; - char *texts[MAXPATHLEN], *hold; + char buf[MAXPATHLEN*2], *texts[MAXPATHLEN]; int pos = 0, cnt = 0, ndx = 0, len = strlen(text); - if (!buf) { - int j; - if (!(buf = calloc(MAXPATHLEN * 2, 1))) - exit(1); - for (j = (MAXPATHLEN-1) / explode_mod; j >= 0; j--) - texts[j] = buf + j * (explode_mod + 1); - } - if (empty_at_start) - texts[ndx++][0] = '\0'; + texts[ndx++] = ""; /* An empty string must turn into at least one empty array item. */ while (1) { - strncpy(texts[ndx++], text + pos, explode_mod); - if (pos + explode_mod >= len) { - texts[ndx-1][len - pos] = '\0'; + texts[ndx] = buf + ndx * (explode_mod + 1); + strlcpy(texts[ndx++], text + pos, explode_mod + 1); + if (pos + explode_mod >= len) break; - } pos += explode_mod; if (!(++cnt % empties_mod)) - texts[ndx++][0] = '\0'; + texts[ndx++] = ""; } if (empty_at_end) - texts[ndx++][0] = '\0'; - hold = texts[ndx]; + texts[ndx++] = ""; texts[ndx] = NULL; matched = wildmatch_array(pattern, (const char**)texts, 0); - texts[ndx] = hold; } else matched = wildmatch(pattern, text); #ifdef COMPARE_WITH_FNMATCH