Commit 3d8df59c130064c8297bd34d0bacf021608eaf28

Stefan Sperling 2019-02-05T14:49:54

add a caller-provided data pointer to path list elements

diff --git a/lib/got_lib_path.h b/lib/got_lib_path.h
index 1ceecd5..1d766a0 100644
--- a/lib/got_lib_path.h
+++ b/lib/got_lib_path.h
@@ -69,6 +69,7 @@ int got_path_cmp(const char *, const char *);
 struct got_pathlist_entry {
 	TAILQ_ENTRY(got_pathlist_entry) entry;
 	const char *path;
+	void *data; /* data pointer provided to got_pathlist_insert() */
 };
 TAILQ_HEAD(got_pathlist_head, got_pathlist_entry);
 
@@ -81,7 +82,7 @@ TAILQ_HEAD(got_pathlist_head, got_pathlist_entry);
  * element, or to a NULL pointer in case the path was already on the list.
  */
 const struct got_error *got_pathlist_insert(struct got_pathlist_entry **,
-    struct got_pathlist_head *, const char *);
+    struct got_pathlist_head *, const char *, void *);
 
 /* Free resources allocated for a path list. */
 void got_pathlist_free(struct got_pathlist_head *);
diff --git a/lib/path.c b/lib/path.c
index ab84663..8deccf4 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -214,7 +214,7 @@ got_path_cmp(const char *path1, const char *path2)
 
 const struct got_error *
 got_pathlist_insert(struct got_pathlist_entry **inserted,
-    struct got_pathlist_head *pathlist, const char *path)
+    struct got_pathlist_head *pathlist, const char *path, void *data)
 {
 	struct got_pathlist_entry *new, *pe;
 
@@ -225,6 +225,7 @@ got_pathlist_insert(struct got_pathlist_entry **inserted,
 	if (new == NULL)
 		return got_error_from_errno();
 	new->path = path;
+	new->data = data;
 
 	/*
 	 * Many callers will provide paths in a somewhat sorted order while
diff --git a/regress/path/path_test.c b/regress/path/path_test.c
index 7587afc..4514dde 100644
--- a/regress/path/path_test.c
+++ b/regress/path/path_test.c
@@ -142,7 +142,8 @@ path_list(void)
 
 	TAILQ_INIT(&paths);
 	for (i = 0; i < nitems(path_list_input); i++) {
-		err = got_pathlist_insert(NULL, &paths, path_list_input[i]);
+		err = got_pathlist_insert(NULL, &paths, path_list_input[i],
+		    NULL);
 		if (err) {
 			test_printf("%s\n", __func__, err->msg);
 			return 0;
@@ -177,7 +178,8 @@ path_list_reverse_input(void)
 
 	TAILQ_INIT(&paths);
 	for (i = nitems(path_list_input) - 1; i >= 0; i--) {
-		err = got_pathlist_insert(NULL, &paths, path_list_input[i]);
+		err = got_pathlist_insert(NULL, &paths, path_list_input[i],
+		    NULL);
 		if (err) {
 			test_printf("%s\n", __func__, err->msg);
 			return 0;