return NULL;
}
-void opkg_print_error_list (opkg_conf_t *conf)
-{
- struct errlist *err = error_list;
-
- if (err) {
- reverse_error_list(&err);
-
- printf ("Collected errors:\n");
- /* Here we print the errors collected and free the list */
- while (err != NULL) {
- printf (" * %s", err->errmsg);
- err = err->next;
-
- }
-
- free_error_list(&error_list);
- }
-
-}
-
int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, const char **argv, void *userdata)
{
int result;
result = (cmd->fun)(conf, argc, argv);
- if ( result != 0 && !error_list) {
- opkg_message(conf, OPKG_NOTICE, "An error occurred, return value: %d.\n", result);
- }
-
- opkg_print_error_list (conf);
+ print_error_list();
+ free_error_list();
p_userdata = NULL;
return result;
return 1;
}
+static struct errlist *error_list_head, *error_list_tail;
+
/*
* XXX: this function should not allocate memory as it may be called to
* print an error because we are out of memory.
*/
-void push_error_list(struct errlist ** errors, char * msg){
- struct errlist *err_lst_tmp;
-
- err_lst_tmp = calloc (1, sizeof (struct errlist) );
- if (err_lst_tmp == NULL) {
- fprintf(stderr, "%s: calloc: %s\n", __FUNCTION__, strerror(errno));
- return;
- }
-
- err_lst_tmp->errmsg = strdup(msg);
- if (err_lst_tmp->errmsg == NULL) {
- fprintf(stderr, "%s: strdup: %s\n", __FUNCTION__, strerror(errno));
- free(err_lst_tmp);
- return;
- }
-
- err_lst_tmp->next = *errors;
- *errors = err_lst_tmp;
+void push_error_list(char * msg)
+{
+ struct errlist *e;
+
+ e = calloc(1, sizeof(struct errlist));
+ if (e == NULL) {
+ fprintf(stderr, "%s: calloc: %s\n",
+ __FUNCTION__, strerror(errno));
+ return;
+ }
+
+ e->errmsg = strdup(msg);
+ if (e->errmsg == NULL) {
+ fprintf(stderr, "%s: strdup: %s\n",
+ __FUNCTION__, strerror(errno));
+ free(e);
+ return;
+ }
+
+ e->next = NULL;
+
+ if (error_list_head) {
+ error_list_tail->next = e;
+ error_list_tail = e;
+ } else {
+ error_list_head = error_list_tail = e;
+ }
}
-
-void reverse_error_list(struct errlist **errors){
- struct errlist *result=NULL;
- struct errlist *current= *errors;
- struct errlist *next;
-
- while ( current != NULL ) {
- next = current->next;
- current->next=result;
- result=current;
- current=next;
- }
- *errors=result;
-
+void free_error_list(void)
+{
+ struct errlist *err, *err_tmp;
+
+ err = error_list_head;
+ while (err != NULL) {
+ free(err->errmsg);
+ err_tmp = err;
+ err = err->next;
+ free(err_tmp);
+ }
}
-
-void free_error_list(struct errlist **errors){
-struct errlist *err_tmp_lst;
-
- err_tmp_lst = *errors;
-
- while (err_tmp_lst != NULL) {
- free(err_tmp_lst->errmsg);
- err_tmp_lst = error_list->next;
- free(*errors);
- *errors = err_tmp_lst;
- }
-
-
+void print_error_list (void)
+{
+ struct errlist *err = error_list_head;
+
+ if (err) {
+ printf ("Collected errors:\n");
+ /* Here we print the errors collected and free the list */
+ while (err != NULL) {
+ printf (" * %s", err->errmsg);
+ err = err->next;
+ }
+ }
}
-
-
#include "pkg.h"
#include "opkg_error.h"
-void push_error_list(struct errlist **errors,char * msg);
-void reverse_error_list(struct errlist **errors);
-void free_error_list(struct errlist **errors);
+void push_error_list(char * msg);
+void free_error_list(void);
+void print_error_list(void);
long unsigned int get_available_blocks(char * filesystem);
char **read_raw_pkgs_from_file(const char *file_name);