Browse Source

libpkgconf: path: add path list copying function

William Pitcock 1 year ago
parent
commit
43e8c7b44d
2 changed files with 33 additions and 0 deletions
  1. 1
    0
      libpkgconf/libpkgconf.h
  2. 32
    0
      libpkgconf/path.c

+ 1
- 0
libpkgconf/libpkgconf.h View File

@@ -338,6 +338,7 @@ PKGCONF_API size_t pkgconf_path_build_from_environ(const char *envvarname, const
338 338
 PKGCONF_API bool pkgconf_path_match_list(const char *path, const pkgconf_list_t *dirlist);
339 339
 PKGCONF_API void pkgconf_path_free(pkgconf_list_t *dirlist);
340 340
 PKGCONF_API bool pkgconf_path_relocate(char *buf, size_t buflen);
341
+PKGCONF_API void pkgconf_path_copy_list(pkgconf_list_t *dst, const pkgconf_list_t *src);
341 342
 
342 343
 #ifdef __cplusplus
343 344
 }

+ 32
- 0
libpkgconf/path.c View File

@@ -222,6 +222,38 @@ pkgconf_path_match_list(const char *path, const pkgconf_list_t *dirlist)
222 222
 	return false;
223 223
 }
224 224
 
225
+/*
226
+ * !doc
227
+ *
228
+ * .. c:function:: void pkgconf_path_copy_list(pkgconf_list_t *dst, const pkgconf_list_t *src)
229
+ *
230
+ *    Copies a path list to another path list.
231
+ *
232
+ *    :param pkgconf_list_t* dst: The path list to copy to.
233
+ *    :param pkgconf_list_t* src: The path list to copy from.
234
+ *    :return: nothing
235
+ */
236
+void
237
+pkgconf_path_copy_list(pkgconf_list_t *dst, const pkgconf_list_t *src)
238
+{
239
+	pkgconf_node_t *n;
240
+
241
+	PKGCONF_FOREACH_LIST_ENTRY(src->head, n)
242
+	{
243
+		pkgconf_path_t *srcpath = n->data, *path;
244
+
245
+		path = calloc(sizeof(pkgconf_path_t), 1);
246
+		path->path = strdup(srcpath->path);
247
+
248
+#ifdef PKGCONF_CACHE_INODES
249
+		path->handle_path = srcpath->handle_path;
250
+		path->handle_device = srcpath->handle_device;
251
+#endif
252
+
253
+		pkgconf_node_insert_tail(&path->lnode, path, dst);
254
+	}
255
+}
256
+
225 257
 /*
226 258
  * !doc
227 259
  *