just include fcntl.h not sys/fcntl.h
[oweals/busybox.git] / archival / dpkg.c
index 05ba4341482e69d82afdfcc127f5c80713d43de3..74d3a83d943ecab368cf6a5840a3c8634dae2d20 100644 (file)
@@ -544,17 +544,19 @@ static void free_package(common_node_t *node)
                for (i = 0; i < node->num_of_edges; i++) {
                        free(node->edge[i]);
                }
-               if ( node->edge )
-                       free(node->edge);
+               free(node->edge);
                free(node);
        }
 }
 
 static unsigned int fill_package_struct(char *control_buffer)
 {
+       static const char *const field_names[] = { "Package", "Version",
+               "Pre-Depends", "Depends","Replaces", "Provides",
+               "Conflicts", "Suggests", "Recommends", "Enhances", 0
+       };
+
        common_node_t *new_node = (common_node_t *) xcalloc(1, sizeof(common_node_t));
-       const char *field_names[] = { "Package", "Version", "Pre-Depends", "Depends",
-               "Replaces", "Provides", "Conflicts", "Suggests", "Recommends", "Enhances", 0};
        char *field_name;
        char *field_value;
        int field_start = 0;
@@ -850,7 +852,7 @@ static void write_status_file(deb_file_t **deb_file)
                }
 
                tmp_string += 8;
-               tmp_string += strspn(tmp_string, " \n\t");
+               tmp_string += strspn(tmp_string, " \n\t");
                package_name = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n\0"));
                write_flag = FALSE;
                tmp_string = strstr(control_buffer, "Status:");
@@ -989,8 +991,8 @@ static int package_satisfies_dependency(int package, int depend_type)
                return 0;
 
        switch (depend_type) {
-       case EDGE_PRE_DEPENDS:  return get_status(status_num, 3) == search_name_hashtable("installed");
-       case EDGE_DEPENDS:      return get_status(status_num, 1) == search_name_hashtable("install");
+       case EDGE_PRE_DEPENDS:  return get_status(status_num, 3) == search_name_hashtable("installed");
+       case EDGE_DEPENDS:      return get_status(status_num, 1) == search_name_hashtable("install");
        }
        return 0;
 }
@@ -1078,7 +1080,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
                        }
                }
                i++;
-       }       
+       }
 
 
        /* Check dependendcies */
@@ -1114,8 +1116,8 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
                 * things which are broken but unrelated to the
                 * packages that are currently being installed
                 */
-                if (state_status == search_name_hashtable("installed"))
-                        continue;
+               if (state_status == search_name_hashtable("installed"))
+                       continue;
 #endif
 
                /* This code is tested only for EDGE_DEPENDS, since I
@@ -1125,13 +1127,13 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
                for (j = 0; j < package_node->num_of_edges; j++) {
                        const edge_t *package_edge = package_node->edge[j];
                        unsigned int package_num;
-                       
+
                        if ( package_edge->type == EDGE_OR_PRE_DEPENDS ||
-                            package_edge->type == EDGE_OR_DEPENDS ) {  /* start an EDGE_OR_ list */
+                            package_edge->type == EDGE_OR_DEPENDS ) {  /* start an EDGE_OR_ list */
                                number_of_alternatives = package_edge->version;
                                root_of_alternatives = package_edge;
                                continue;
-                       } else if ( number_of_alternatives == 0 ) {     /* not in the middle of an EDGE_OR_ list */
+                       } else if ( number_of_alternatives == 0 ) {     /* not in the middle of an EDGE_OR_ list */
                                number_of_alternatives = 1;
                                root_of_alternatives = NULL;
                        }
@@ -1299,7 +1301,7 @@ static char **all_control_list(const char *package_name)
        char **remove_files;
 
        /* Create a list of all /var/lib/dpkg/info/<package> files */
-       remove_files = malloc(sizeof(all_control_files));
+       remove_files = xmalloc(sizeof(all_control_files));
        while (all_control_files[i]) {
                remove_files[i] = xmalloc(strlen(package_name) + strlen(all_control_files[i]) + 21);
                sprintf(remove_files[i], "/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
@@ -1329,7 +1331,7 @@ static void free_array(char **array)
  */
 static void list_packages(void)
 {
-        int i;
+       int i;
 
        printf("    Name           Version\n");
        printf("+++-==============-==============\n");
@@ -1520,6 +1522,7 @@ static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, lli
 {
        ar_handle->sub_archive->action_data = data_extract_to_buffer;
        ar_handle->sub_archive->accept = myaccept;
+       ar_handle->sub_archive->filter = filter_accept_list;
 
        unpack_ar_archive(ar_handle);
        close(ar_handle->src_fd);
@@ -1714,6 +1717,7 @@ int dpkg_main(int argc, char **argv)
 
                        if (package_num == -1) {
                                bb_error_msg("Invalid control file in %s", argv[optind]);
+                               optind++;
                                continue;
                        }
                        deb_file[deb_count]->package = (unsigned int) package_num;