ifupdown: save some 100+ bytes of code in addstr()
[oweals/busybox.git] / archival / dpkg.c
index 4d0f3fbf3ba27a8bcedaa488f6d82176c96e81b9..9024d41d237ecfdff522ebe464cac557f36957c9 100644 (file)
@@ -644,7 +644,7 @@ static unsigned int fill_package_struct(char *control_buffer)
                        goto fill_package_struct_cleanup; /* Oh no, the dreaded goto statement ! */
                }
 
-               field_num = compare_string_array(field_names, field_name);
+               field_num = index_in_str_array(field_names, field_name);
                switch (field_num) {
                        case 0: /* Package */
                                new_node->name = search_name_hashtable(field_value);
@@ -711,7 +711,7 @@ static unsigned int get_status(const unsigned int status_node, const int num)
                /* skip past the separating spaces */
                status_string += strspn(status_string, " ");
        }
-       len = strcspn(status_string, " \n\0");
+       len = strcspn(status_string, " \n");
        state_sub_string = xstrndup(status_string, len);
        state_sub_num = search_name_hashtable(state_sub_string);
        free(state_sub_string);
@@ -787,7 +787,7 @@ static void index_status_file(const char *filename)
        unsigned int status_num;
 
        status_file = xfopen(filename, "r");
-       while ((control_buffer = fgets_str(status_file, "\n\n")) != NULL) {
+       while ((control_buffer = xmalloc_fgets_str(status_file, "\n\n")) != NULL) {
                const unsigned int package_num = fill_package_struct(control_buffer);
                if (package_num != -1) {
                        status_node = xmalloc(sizeof(status_node_t));
@@ -796,7 +796,7 @@ static void index_status_file(const char *filename)
                        if (status_line != NULL) {
                                status_line += 7;
                                status_line += strspn(status_line, " \n\t");
-                               status_line = xstrndup(status_line, strcspn(status_line, "\n\0"));
+                               status_line = xstrndup(status_line, strcspn(status_line, "\n"));
                                status_node->status = search_name_hashtable(status_line);
                                free(status_line);
                        }
@@ -842,14 +842,14 @@ static void write_status_file(deb_file_t **deb_file)
        int i = 0;
 
        /* Update previously known packages */
-       while ((control_buffer = fgets_str(old_status_file, "\n\n")) != NULL) {
+       while ((control_buffer = xmalloc_fgets_str(old_status_file, "\n\n")) != NULL) {
                if ((tmp_string = strstr(control_buffer, "Package:")) == NULL) {
                        continue;
                }
 
                tmp_string += 8;
                tmp_string += strspn(tmp_string, " \n\t");
-               package_name = xstrndup(tmp_string, strcspn(tmp_string, "\n\0"));
+               package_name = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
                write_flag = FALSE;
                tmp_string = strstr(control_buffer, "Status:");
                if (tmp_string != NULL) {
@@ -1374,8 +1374,8 @@ static void remove_package(const unsigned int package_num, int noisy)
        sprintf(conffile_name, "/var/lib/dpkg/info/%s.conffiles", package_name);
        exclude_files = create_list(conffile_name);
 
-       /* Some directories cant be removed straight away, so do multiple passes */
-       while (remove_file_array(remove_files, exclude_files));
+       /* Some directories can't be removed straight away, so do multiple passes */
+       while (remove_file_array(remove_files, exclude_files)) /*repeat */;
        free_array(exclude_files);
        free_array(remove_files);
 
@@ -1421,7 +1421,7 @@ static void purge_package(const unsigned int package_num)
        exclude_files = xzalloc(sizeof(char*));
 
        /* Some directories cant be removed straight away, so do multiple passes */
-       while (remove_file_array(remove_files, exclude_files));
+       while (remove_file_array(remove_files, exclude_files)) /* repeat */;
        free_array(remove_files);
 
        /* Create a list of all /var/lib/dpkg/info/<package> files */