Commit f54c4c24c918de10964c89c400b6552516bb0069

Stefan Sperling 2019-02-07T11:36:16

get rid of xmalloc and a global declaration in worklist code

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