diff options
author | Ulf Hermann <[email protected]> | 2018-07-16 11:13:08 +0200 |
---|---|---|
committer | Ulf Hermann <[email protected]> | 2018-07-17 18:48:46 +0000 |
commit | e95a17dc79836e6639444fe6c065cd0e7e14e4db (patch) | |
tree | f2070f906d97c3cea662ad04c063c0a13a2d5d0e /src/ar.c | |
parent | f26fd0282f3b3a7d7e3fbf9849ca2bde8e6eda74 (diff) |
Eliminate trees from ar.c
Apparently they don't do what we want them to, and we're not interested in
the (supposedly) better performance anyway.
Change-Id: I0797520afbe5ba6feaccf9b99b46bbaebdd6bc37
Reviewed-by: Christian Kandeler <[email protected]>
Diffstat (limited to 'src/ar.c')
-rw-r--r-- | src/ar.c | 132 |
1 files changed, 41 insertions, 91 deletions
@@ -28,7 +28,6 @@ #include <libintl.h> #include <limits.h> #include <locale.h> -#include <search.h> #include <stdbool.h> #include <stdlib.h> #include <stdio.h> @@ -437,21 +436,6 @@ copy_content (Elf *elf, int newfd, off_t off, size_t n) return write_retry (newfd, rawfile + off, n) != (ssize_t) n; } - -static int -string_compare (const void *a, const void *b) -{ - return strcmp((const char *)a, (const char *)b); -} - - -void -free_node (void *node) -{ - (void) node; -} - - static int do_oper_extract (int oper, const char *arfname, char **argv, int argc, long int instance) @@ -473,15 +457,6 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc, Elf *elf; int fd = open_archive (arfname, O_RDONLY | O_BINARY, 0, &elf, NULL, false); - void *root = NULL; - - for (int cnt = 0; cnt < argc; ++cnt) - { - if (tsearch (argv[cnt], &root, &string_compare) == NULL) - error (EXIT_FAILURE, errno, - gettext ("cannot insert into hash table")); - } - struct stat st; if (force_symtab) { @@ -519,10 +494,15 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc, bool do_extract = argc <= 0; if (!do_extract) { - void *res = tfind (arhdr->ar_name, &root, &string_compare); - if (res != NULL && (instance < 0 || instance-- == 0) - && !found[(char **) res - argv]) - found[(char **) res - argv] = do_extract = true; + for (int cnt = 0; cnt < argc; ++cnt) + { + if (!strcmp (arhdr->ar_name, argv[cnt])) + { + if ((instance < 0 || instance-- == 0) && !found[cnt]) + found[cnt] = do_extract = true; + break; + } + } } if (do_extract) @@ -724,9 +704,6 @@ cannot rename temporary file to %.*s"), error (1, 0, "%s: %s", arfname, elf_errmsg (-1)); } - tdestroy(root, &free_node); - root = NULL; - if (force_symtab) { arlib_finalize (); @@ -905,15 +882,6 @@ do_oper_delete (const char *arfname, char **argv, int argc, struct stat st; int fd = open_archive (arfname, O_RDONLY | O_BINARY, 0, &elf, &st, false); - void *root = NULL; - - for (int cnt = 0; cnt < argc; ++cnt) - { - if (tsearch (argv[cnt], &root, &string_compare) == NULL) - error (EXIT_FAILURE, errno, - gettext ("cannot insert into hash table")); - } - arlib_init (); off_t cur_off = SARMAG; @@ -931,10 +899,15 @@ do_oper_delete (const char *arfname, char **argv, int argc, bool do_delete = argc <= 0; if (!do_delete) { - void *res = tfind (arhdr->ar_name, &root, &string_compare); - if (res != NULL && (instance < 0 || instance-- == 0) - && !found[(char **) res - argv]) - found[(char **) res - argv] = do_delete = true; + for (int cnt = 0; cnt < argc; ++cnt) + { + if (!strcmp (arhdr->ar_name, argv[cnt])) + { + if ((instance < 0 || instance-- == 0) && !found[cnt]) + found[cnt] = do_delete = true; + break; + } + } } if (do_delete) @@ -975,9 +948,6 @@ do_oper_delete (const char *arfname, char **argv, int argc, arlib_finalize (); - tdestroy (root, &free_node); - root = NULL; - /* Create a new, temporary file in the same directory as the original file. */ char tmpfname[strlen (arfname) + 7]; @@ -1076,14 +1046,6 @@ no0print (bool ofmt, char *buf, int bufsize, long int val) return true; } - -static int -basename_compare(const void *a, const void *b) -{ - return strcmp(basename((const char *)a), basename((const char *)b)); -} - - static int do_oper_insert (int oper, const char *arfname, char **argv, int argc, const char *member) @@ -1092,7 +1054,6 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, Elf *elf = NULL; struct stat st; int fd = open_archive (arfname, O_RDONLY | O_BINARY, 0, &elf, &st, oper != oper_move); - void *root = NULL; /* List of the files we keep. */ struct armem *all = NULL; @@ -1114,20 +1075,6 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, goto no_old; } - /* Store the names of all files from the command line in a hash - table so that we can match it. Note that when no file name is - given we are basically doing nothing except recreating the - index. */ - if (oper != oper_qappend) - { - for (int cnt = 0; cnt < argc; ++cnt) - { - if (tsearch (argv[cnt], &root, full_path ? &basename_compare : &string_compare) == NULL) - error (EXIT_FAILURE, errno, - gettext ("cannot insert into hash table")); - } - } - /* While iterating over the current content of the archive we must determine a number of things: which archive members to keep, which are replaced, and where to insert the new members. */ @@ -1165,23 +1112,32 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, member = NULL; } - void *res = tfind(arhdr->ar_name, &root, full_path ? &basename_compare : &string_compare); - if (res != NULL && found[(char **) res - argv] == NULL) + const char *arhdr_basename = basename (arhdr->ar_name); + for (int cnt = 0; cnt < argc; ++cnt) { - found[(char **) res - argv] = newp; - - /* If we insert before or after a certain element move - all files to a special list. */ - if (unlikely (ipos != ipos_none || oper == oper_move)) - { - if (after_memberelem == newp) - /* Since we remove this element even though we should - insert everything after it, we in fact insert - everything after the previous element. */ - after_memberelem = all; + if (full_path && strcmp (arhdr_basename, basename (argv[cnt]))) + continue; + else if (!full_path && strcmp (arhdr->ar_name, argv[cnt])) + continue; + + if (found[cnt] == NULL) + { + found[cnt] = newp; + + /* If we insert before or after a certain element move + all files to a special list. */ + if (unlikely (ipos != ipos_none || oper == oper_move)) + { + if (after_memberelem == newp) + /* Since we remove this element even though we should + insert everything after it, we in fact insert + everything after the previous element. */ + after_memberelem = all; - goto next; + goto next; + } } + break; } } @@ -1199,12 +1155,6 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, error (EXIT_FAILURE, 0, "%s: %s", arfname, elf_errmsg (-1)); } - if (oper != oper_qappend) - { - tdestroy(root, &free_node); - root = NULL; - } - no_old: if (member != NULL) error (EXIT_FAILURE, 0, gettext ("position member %s not found"), |