about summary refs log tree commit diff
path: root/Src/linklist.c
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2020-04-27 19:30:39 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2020-05-03 01:27:36 +0000
commit4d2bcf2fe7637b641ccde31a8ca7c4875f0699c1 (patch)
tree736b16476096638c74367c7170c8700af435ea9a /Src/linklist.c
parentd800c3850772d0bf7ae433938e9166315cf39f6d (diff)
downloadzsh-4d2bcf2fe7637b641ccde31a8ca7c4875f0699c1.tar.gz
zsh-4d2bcf2fe7637b641ccde31a8ca7c4875f0699c1.tar.xz
zsh-4d2bcf2fe7637b641ccde31a8ca7c4875f0699c1.zip
45729: internal: Add a second parameter to zlinklist2array(), analogously to hlinklist2array().
Will be used in the next commit.
Diffstat (limited to 'Src/linklist.c')
-rw-r--r--Src/linklist.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/Src/linklist.c b/Src/linklist.c
index 85d9bb367..f64685d9e 100644
--- a/Src/linklist.c
+++ b/Src/linklist.c
@@ -438,22 +438,27 @@ hlinklist2array(LinkList list, int copy)
 
 /*
  * Convert a linked list whose data elements are strings to
- * an array.  The result is a permanently allocated, freearrayable
- * array.
+ * a permanently-allocated array.  The elements of the array are the same
+ * elements as the linked list data if copy is 0, else they are duplicated
+ * into permanent memory so the result is a permanently allocated,
+ * freearrayable array that's a deep copy of the linked list.
  */
 
 /**/
 mod_export char **
-zlinklist2array(LinkList list)
+zlinklist2array(LinkList list, int copy)
 {
     int l = countlinknodes(list);
     char **ret = (char **) zalloc((l + 1) * sizeof(char *)), **p;
     LinkNode n;
 
     for (n = firstnode(list), p = ret; n; incnode(n), p++) {
-	*p = ztrdup((char *) getdata(n));
+	*p = (char *) getdata(n);
+	if (copy)
+	    *p = ztrdup(*p);
     }
     *p = NULL;
 
     return ret;
 }
+