ifupdown: save some 100+ bytes of code in addstr()
[oweals/busybox.git] / archival / dpkg.c
index b55822460cfd3e8b95a830fe750945e3ad7f60b7..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) {
@@ -878,7 +878,8 @@ static void write_status_file(deb_file_t **deb_file)
                                                        /* remove trailing \n's */
                                                        write_buffer_no_status(new_status_file, deb_file[i]->control_file);
                                                        set_status(status_num, "ok", 2);
-                                                       fprintf(new_status_file, "Status: %s\n\n", name_hashtable[status_hashtable[status_num]->status]);
+                                                       fprintf(new_status_file, "Status: %s\n\n",
+                                                                       name_hashtable[status_hashtable[status_num]->status]);
                                                        write_flag = TRUE;
                                                        break;
                                                }
@@ -886,7 +887,9 @@ static void write_status_file(deb_file_t **deb_file)
                                        }
                                        /* This is temperary, debugging only */
                                        if (deb_file[i] == NULL) {
-                                               bb_error_msg_and_die("ALERT: Couldnt find a control file, your status file may be broken, status may be incorrect for %s", package_name);
+                                               bb_error_msg_and_die("ALERT: cannot find a control file, "
+                                                       "your status file may be broken, status may be "
+                                                       "incorrect for %s", package_name);
                                        }
                                }
                                else if (strcmp("not-installed", name_hashtable[state_status]) == 0) {
@@ -963,7 +966,8 @@ static void write_status_file(deb_file_t **deb_file)
        }
 
        if (rename("/var/lib/dpkg/status.udeb", "/var/lib/dpkg/status") == -1) {
-               bb_error_msg_and_die("DANGER: Cannot create status file, you need to manually repair your status file");
+               bb_error_msg_and_die("DANGER: cannot create status file, "
+                       "you need to manually repair your status file");
        }
 }
 
@@ -1202,7 +1206,7 @@ static char **create_list(const char *filename)
                return NULL;
        }
 
-       while ((line = bb_get_chomped_line_from_file(list_stream)) != NULL) {
+       while ((line = xmalloc_getline(list_stream)) != NULL) {
                file_list = xrealloc(file_list, sizeof(char *) * (count + 2));
                file_list[count] = line;
                count++;
@@ -1370,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);
 
@@ -1417,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 */