commit - e08cc72dc07ea915bb95484818f3be5847d6e556
commit + 7e5c804bbace8241acc368ccd2087ae2aa1674d7
blob - a3451ceb2cfc850c40fbd36a6bd24c8725de887f
blob + 1ceecd51125f92305dd4eb045497421d3c89087d
--- lib/got_lib_path.h
+++ lib/got_lib_path.h
* The caller should already have initialized the list head. This list stores
* the pointer to the path as-is, i.e. the path is not copied internally and
* must remain available until the list is freed with got_pathlist_free().
+ * If the first argument is not NULL, set it to a pointer to the newly inserted
+ * 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_head *,
- const char *);
+const struct got_error *got_pathlist_insert(struct got_pathlist_entry **,
+ struct got_pathlist_head *, const char *);
/* Free resources allocated for a path list. */
void got_pathlist_free(struct got_pathlist_head *);
blob - cc15eae49b0e361ae325d2e6c1fda427850d2591
blob + ab846633cefec4d06aea9e37720a03a6623ddfcf
--- lib/path.c
+++ lib/path.c
}
const struct got_error *
-got_pathlist_insert(struct got_pathlist_head *pathlist, const char *path)
+got_pathlist_insert(struct got_pathlist_entry **inserted,
+ struct got_pathlist_head *pathlist, const char *path)
{
struct got_pathlist_entry *new, *pe;
+
+ if (inserted)
+ *inserted = NULL;
new = malloc(sizeof(*new));
if (new == NULL)
return NULL;
} else if (cmp < 0) {
TAILQ_INSERT_AFTER(pathlist, pe, new, entry);
+ if (inserted)
+ *inserted = new;
return NULL;
}
pe = TAILQ_PREV(pe, got_pathlist_head, entry);
}
TAILQ_INSERT_HEAD(pathlist, new, entry);
+ if (inserted)
+ *inserted = new;
return NULL;
}
blob - 24bfb418705d1482e271f5d2f70ebcdd3a95243b
blob + 7587afc044c1f8805f93944569423d2fef1b9a67
--- regress/path/path_test.c
+++ regress/path/path_test.c
TAILQ_INIT(&paths);
for (i = 0; i < nitems(path_list_input); i++) {
- err = got_pathlist_insert(&paths, path_list_input[i]);
+ err = got_pathlist_insert(NULL, &paths, path_list_input[i]);
if (err) {
test_printf("%s\n", __func__, err->msg);
return 0;
TAILQ_INIT(&paths);
for (i = nitems(path_list_input) - 1; i >= 0; i--) {
- err = got_pathlist_insert(&paths, path_list_input[i]);
+ err = got_pathlist_insert(NULL, &paths, path_list_input[i]);
if (err) {
test_printf("%s\n", __func__, err->msg);
return 0;