#ifdef HAVE_STRING_H
#include <string.h>
#endif
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
#include "archive.h"
#include "archive_private.h"
struct match_list {
struct match *first;
struct match **last;
- int count;
- int unmatched_count;
+ size_t unmatched_count;
struct match *unmatched_next;
int unmatched_eof;
};
struct entry_list {
struct match_file *first;
struct match_file **last;
- int count;
};
struct id_array {
const char *);
static int add_pattern_wcs(struct archive_match *, struct match_list *,
const wchar_t *);
+#if !defined(_WIN32) || defined(__CYGWIN__)
static int cmp_key_mbs(const struct archive_rb_node *, const void *);
-static int cmp_key_wcs(const struct archive_rb_node *, const void *);
static int cmp_node_mbs(const struct archive_rb_node *,
const struct archive_rb_node *);
+#else
+static int cmp_key_wcs(const struct archive_rb_node *, const void *);
static int cmp_node_wcs(const struct archive_rb_node *,
const struct archive_rb_node *);
+#endif
static void entry_list_add(struct entry_list *, struct match_file *);
static void entry_list_free(struct entry_list *);
static void entry_list_init(struct entry_list *);
#define get_date archive_parse_date
-static const struct archive_rb_tree_ops rb_ops_mbs = {
+static const struct archive_rb_tree_ops rb_ops = {
+#if !defined(_WIN32) || defined(__CYGWIN__)
cmp_node_mbs, cmp_key_mbs
-};
-
-static const struct archive_rb_tree_ops rb_ops_wcs = {
+#else
cmp_node_wcs, cmp_key_wcs
+#endif
};
/*
a->recursive_include = 1;
match_list_init(&(a->inclusions));
match_list_init(&(a->exclusions));
- __archive_rb_tree_init(&(a->exclusion_tree), &rb_ops_mbs);
+ __archive_rb_tree_init(&(a->exclusion_tree), &rb_ops);
entry_list_init(&(a->exclusion_entry_list));
match_list_init(&(a->inclusion_unames));
match_list_init(&(a->inclusion_gnames));
ARCHIVE_STATE_NEW, "archive_match_unmatched_inclusions");
a = (struct archive_match *)_a;
- return (a->inclusions.unmatched_count);
+ if (a->inclusions.unmatched_count > (size_t)INT_MAX)
+ return INT_MAX;
+ return (int)(a->inclusions.unmatched_count);
}
int
break;
}
} else {
- if (*b == 0x0d || *b == 0x0a) {
+ if (*b == 0x0d || *b == 0x0a) {
found_separator = 1;
break;
}
}
}
- /* Exclusions take priority */
+ /* Exclusions take priority. */
for (match = a->exclusions.first; match != NULL;
match = match->next){
r = match_path_exclusion(a, match, mbs, pathname);
{
list->first = NULL;
list->last = &(list->first);
- list->count = 0;
}
static void
{
*list->last = m;
list->last = &(m->next);
- list->count++;
list->unmatched_count++;
}
/*
* Call back functions for archive_rb.
*/
+#if !defined(_WIN32) || defined(__CYGWIN__)
static int
cmp_node_mbs(const struct archive_rb_node *n1,
const struct archive_rb_node *n2)
return (-1);
return (strcmp(p1, p2));
}
-
+
static int
cmp_key_mbs(const struct archive_rb_node *n, const void *key)
{
return (-1);
return (strcmp(p, (const char *)key));
}
-
+#else
static int
cmp_node_wcs(const struct archive_rb_node *n1,
const struct archive_rb_node *n2)
return (-1);
return (wcscmp(p1, p2));
}
-
+
static int
cmp_key_wcs(const struct archive_rb_node *n, const void *key)
{
return (-1);
return (wcscmp(p, (const wchar_t *)key));
}
+#endif
static void
entry_list_init(struct entry_list *list)
{
list->first = NULL;
list->last = &(list->first);
- list->count = 0;
}
static void
{
*list->last = file;
list->last = &(file->next);
- list->count++;
}
static int
return (ARCHIVE_FAILED);
}
archive_mstring_copy_wcs(&(f->pathname), pathname);
- a->exclusion_tree.rbt_ops = &rb_ops_wcs;
#else
- (void)rb_ops_wcs;
pathname = archive_entry_pathname(entry);
if (pathname == NULL) {
free(f);
return (ARCHIVE_FAILED);
}
archive_mstring_copy_mbs(&(f->pathname), pathname);
- a->exclusion_tree.rbt_ops = &rb_ops_mbs;
#endif
f->flag = flag;
f->mtime_sec = archive_entry_mtime(entry);
}
/* If there is no exclusion list, include the file. */
- if (a->exclusion_entry_list.count == 0)
+ if (a->exclusion_entry_list.first == NULL)
return (0);
#if defined(_WIN32) && !defined(__CYGWIN__)
pathname = archive_entry_pathname_w(entry);
- a->exclusion_tree.rbt_ops = &rb_ops_wcs;
#else
- (void)rb_ops_wcs;
pathname = archive_entry_pathname(entry);
- a->exclusion_tree.rbt_ops = &rb_ops_mbs;
#endif
if (pathname == NULL)
return (0);
static int
add_owner_id(struct archive_match *a, struct id_array *ids, int64_t id)
{
- unsigned i;
+ size_t i;
if (ids->count + 1 >= ids->size) {
void *p;
static int
match_owner_id(struct id_array *ids, int64_t id)
{
- unsigned b, m, t;
+ size_t b, m, t;
t = 0;
- b = (unsigned)ids->count;
+ b = ids->count;
while (t < b) {
m = (t + b)>>1;
if (ids->ids[m] == id)
return (1);
}
- if (a->inclusion_unames.count) {
+ if (a->inclusion_unames.first != NULL) {
#if defined(_WIN32) && !defined(__CYGWIN__)
r = match_owner_name_wcs(a, &(a->inclusion_unames),
archive_entry_uname_w(entry));
return (r);
}
- if (a->inclusion_gnames.count) {
+ if (a->inclusion_gnames.first != NULL) {
#if defined(_WIN32) && !defined(__CYGWIN__)
r = match_owner_name_wcs(a, &(a->inclusion_gnames),
archive_entry_gname_w(entry));