commit 3d8df59c130064c8297bd34d0bacf021608eaf28 from: Stefan Sperling date: Tue Feb 05 13:49:54 2019 UTC add a caller-provided data pointer to path list elements commit - 7a3c76f5480c716bf8b721ef7c5dac901259b222 commit + 3d8df59c130064c8297bd34d0bacf021608eaf28 blob - 1ceecd51125f92305dd4eb045497421d3c89087d blob + 1d766a09291a9b72e2f9f336bad668cc74a37885 --- lib/got_lib_path.h +++ 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 *); blob - ab846633cefec4d06aea9e37720a03a6623ddfcf blob + 8deccf40930398276c6f6880a025fb54ea2c1ca4 --- lib/path.c +++ 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 **insert 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 blob - 7587afc044c1f8805f93944569423d2fef1b9a67 blob + 4514dde0727519afee770ae44ddcc350f37da197 --- regress/path/path_test.c +++ 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;