From 4d2bcf2fe7637b641ccde31a8ca7c4875f0699c1 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 27 Apr 2020 19:30:39 +0000 Subject: 45729: internal: Add a second parameter to zlinklist2array(), analogously to hlinklist2array(). Will be used in the next commit. --- Src/linklist.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'Src/linklist.c') 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; } + -- cgit v1.2.3