summaryrefslogtreecommitdiffstats
path: root/libopkg/opkg_utils.c
diff options
context:
space:
mode:
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-11-01 22:39:12 (EST)
committer graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-11-01 22:39:12 (EST)
commit908c671d6b3807854d41b4b51c584d16d7c2694b (patch)
treec3f120f1bfb0fed4a7a80b0759233e2cf38d3a38 /libopkg/opkg_utils.c
parent5c617e296570ed33196988e96481a4ef3e6e626e (diff)
Cleanup error_list stuff a bit more.
- Remove reverse_error_list. - Push messages on to the tail of the list. - Move the print function in with the other error list functions. - Indentation and variable name cleanups. git-svn-id: http://opkg.googlecode.com/svn/trunk@238 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg/opkg_utils.c')
-rw-r--r--libopkg/opkg_utils.c100
1 files changed, 52 insertions, 48 deletions
diff --git a/libopkg/opkg_utils.c b/libopkg/opkg_utils.c
index f0ef051..92291c4 100644
--- a/libopkg/opkg_utils.c
+++ b/libopkg/opkg_utils.c
@@ -146,60 +146,64 @@ int line_is_blank(const char *line)
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;
+ }
+ }
}
-
-