* lib/basename.c (base_name):
* lib/dfa.c (mbs_to_wchar, state_index, dfaoptimize, dfaanalyze)
(icatalloc, enlist, allocmust, dfamust):
+ * lib/exclude.c (struct exclude_pattern, free_exclude_segment)
+ (file_pattern_matches, add_exclude, add_exclude_fp):
Prefer idx_t to size_t for indexes, and use idx_t-related allocators.
* lib/basename.c: Do not include xstrndup.h.
(basename): Simplify by always using memcpy.
struct exclude_pattern
{
struct patopts *exclude;
- size_t exclude_alloc;
- size_t exclude_count;
+ idx_t exclude_alloc;
+ idx_t exclude_count;
};
enum exclude_type
static void
free_exclude_segment (struct exclude_segment *seg)
{
- size_t i;
-
switch (seg->type)
{
case exclude_pattern:
- for (i = 0; i < seg->v.pat.exclude_count; i++)
+ for (idx_t i = 0; i < seg->v.pat.exclude_count; i++)
{
if (seg->v.pat.exclude[i].options & EXCLUDE_REGEX)
regfree (&seg->v.pat.exclude[i].v.re);
static bool
file_pattern_matches (struct exclude_segment const *seg, char const *f)
{
- size_t exclude_count = seg->v.pat.exclude_count;
+ idx_t exclude_count = seg->v.pat.exclude_count;
struct patopts const *exclude = seg->v.pat.exclude;
- size_t i;
- for (i = 0; i < exclude_count; i++)
+ for (idx_t i = 0; i < exclude_count; i++)
{
if (exclude_patopts (exclude + i, f))
return true;
pat = &seg->v.pat;
if (pat->exclude_count == pat->exclude_alloc)
- pat->exclude = x2nrealloc (pat->exclude, &pat->exclude_alloc,
- sizeof *pat->exclude);
+ pat->exclude = xpalloc (pat->exclude, &pat->exclude_alloc, 1, -1,
+ sizeof *pat->exclude);
patopts = &pat->exclude[pat->exclude_count++];
patopts->options = options;
if (options & FNM_LEADING_DIR)
{
char *tmp;
- size_t len = strlen (pattern);
+ idx_t len = strlen (pattern);
while (len > 0 && ISSLASH (pattern[len-1]))
--len;
rc = 1;
else
{
- tmp = xmalloc (len + 7);
+ tmp = ximalloc (len + 7);
memcpy (tmp, pattern, len);
strcpy (tmp + len, "(/.*)?");
rc = regcomp (&patopts->v.re, tmp, cflags);
char *p;
char *pattern;
char const *lim;
- size_t buf_alloc = 0;
- size_t buf_count = 0;
+ idx_t buf_alloc = 0;
+ idx_t buf_count = 0;
int c;
int e = 0;
while ((c = getc (fp)) != EOF)
{
if (buf_count == buf_alloc)
- buf = x2realloc (buf, &buf_alloc);
+ buf = xpalloc (buf, &buf_alloc, 1, -1, 1);
buf[buf_count++] = c;
}
if (ferror (fp))
e = errno;
- buf = xrealloc (buf, buf_count + 1);
+ buf = xirealloc (buf, buf_count + 1);
buf[buf_count] = line_end;
lim = buf + buf_count + ! (buf_count == 0 || buf[buf_count - 1] == line_end);