get rid of xmalloc and a global declaration in worklist code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
diff --git a/lib/worklist.c b/lib/worklist.c
index 4dd7004..76ce96a 100644
--- a/lib/worklist.c
+++ b/lib/worklist.c
@@ -29,32 +29,36 @@
#include <err.h>
#include <signal.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "worklist.h"
-#include "xmalloc.h"
+#include "got_error.h"
/*
* adds a path to a worklist.
*/
-void
+const struct got_error *
worklist_add(const char *path, struct wklhead *worklist)
{
size_t len;
struct worklist *wkl;
sigset_t old, new;
- wkl = xcalloc(1, sizeof(*wkl));
+ wkl = calloc(1, sizeof(*wkl));
+ if (wkl == NULL)
+ return got_error_from_errno();
len = strlcpy(wkl->wkl_path, path, sizeof(wkl->wkl_path));
if (len >= sizeof(wkl->wkl_path))
- errx(1, "path truncation in worklist_add");
+ return got_error(GOT_ERR_NO_SPACE);
sigfillset(&new);
sigprocmask(SIG_BLOCK, &new, &old);
SLIST_INSERT_HEAD(worklist, wkl, wkl_list);
sigprocmask(SIG_SETMASK, &old, NULL);
+ return NULL;
}
/*
diff --git a/lib/worklist.h b/lib/worklist.h
index cf833e8..bb59617 100644
--- a/lib/worklist.h
+++ b/lib/worklist.h
@@ -37,12 +37,10 @@ struct worklist {
SLIST_HEAD(wklhead, worklist);
-void worklist_add(const char *, struct wklhead *);
+const struct got_error *worklist_add(const char *, struct wklhead *);
void worklist_run(struct wklhead *, void (*cb)(struct worklist *));
void worklist_clean(struct wklhead *, void (*cb)(struct worklist *));
void worklist_unlink(struct worklist *);
-extern struct wklhead temp_files;
-
#endif