Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-01-03 12:13:02 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-01-03 12:13:44 +0300
commit16ed20ff3cc68589a5fe48075d2b80692d3c90ea (patch)
tree83aa3159bc18939a89e223b5eb8f73c4e0cf9179 /source/blender/blenlib/intern/storage.c
parent6b8b3badf58942356d4cc8aa64214f94272a7958 (diff)
Add some BLI helpers needed by asset branch.
`BLI_strncpy_ensure_pad()` is also useful with current master code. The two others (`BLI_strcmp_ignore_pad()` and `BLI_filelist_duplicate()`) are only used in asset branch currently, but think they could be useful in other places too, and simplifies handling of asset branch & future patch review. Reviewers: campbellbarton Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D965
Diffstat (limited to 'source/blender/blenlib/intern/storage.c')
-rw-r--r--source/blender/blenlib/intern/storage.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index c062d62bca5..78057b1655f 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -409,7 +409,40 @@ unsigned int BLI_dir_contents(const char *dirname, struct direntry **filelist)
return dir_ctx.nrfiles;
}
-/* frees storage for an array of direntries, including the array itself. */
+/**
+ * Deep-duplicate of an array of direntries, including the array itself.
+ *
+ * \param dup_poin If given, called for each non-NULL direntry->poin. Otherwise, pointer is always simply copied over.
+ */
+void BLI_filelist_duplicate(
+ struct direntry **dest_filelist, struct direntry *src_filelist, unsigned int nrentries,
+ void *(*dup_poin)(void *))
+{
+ unsigned int i;
+
+ *dest_filelist = malloc(sizeof(**dest_filelist) * (size_t)(nrentries));
+ for (i = 0; i < nrentries; ++i) {
+ struct direntry * const src = &src_filelist[i];
+ struct direntry *dest = &(*dest_filelist)[i];
+ *dest = *src;
+ if (dest->image) {
+ dest->image = IMB_dupImBuf(src->image);
+ }
+ if (dest->relname) {
+ dest->relname = MEM_dupallocN(src->relname);
+ }
+ if (dest->path) {
+ dest->path = MEM_dupallocN(src->path);
+ }
+ if (dest->poin && dup_poin) {
+ dest->poin = dup_poin(src->poin);
+ }
+ }
+}
+
+/**
+ * frees storage for an array of direntries, including the array itself.
+ */
void BLI_free_filelist(struct direntry *filelist, unsigned int nrentries)
{
unsigned int i;