diff options
author | Axel Beckert <abe@deuxchevaux.org> | 2022-04-11 00:17:48 +0200 |
---|---|---|
committer | Axel Beckert <abe@deuxchevaux.org> | 2022-04-11 00:17:48 +0200 |
commit | b09f4483416c54c1782824633dfabaf2ec0265b6 (patch) | |
tree | 304bc82642862525ae680c7fbaa249663b10ad57 /Src/linklist.c | |
parent | 12eb3e5356f2fc3351eed58ef1cef1b8fb83b504 (diff) | |
parent | 6e55c920503071e917619b8cb1a188cd35d772db (diff) | |
download | zsh-b09f4483416c54c1782824633dfabaf2ec0265b6.tar.gz zsh-b09f4483416c54c1782824633dfabaf2ec0265b6.zip |
New upstream version 5.8.1.2-test
Diffstat (limited to 'Src/linklist.c')
-rw-r--r-- | Src/linklist.c | 13 |
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; } + |