summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-01-08 10:39:11 +0100
committerGravatar default2023-01-08 10:39:11 +0100
commitda7e57f4cc016c254899c9438de1cbc9871a93bc (patch)
treecec0c0bd2ac110bc0ad7d420c656e93d2937e0e4
parentUpdated dependencies. (diff)
downloadpenes-snac2-da7e57f4cc016c254899c9438de1cbc9871a93bc.tar.gz
penes-snac2-da7e57f4cc016c254899c9438de1cbc9871a93bc.tar.xz
penes-snac2-da7e57f4cc016c254899c9438de1cbc9871a93bc.zip
Backport from xs.
-rw-r--r--xs.h28
-rw-r--r--xs_curl.h2
-rw-r--r--xs_glob.h2
-rw-r--r--xs_version.h2
4 files changed, 25 insertions, 9 deletions
diff --git a/xs.h b/xs.h
index b1e2cec..38d3050 100644
--- a/xs.h
+++ b/xs.h
@@ -128,6 +128,10 @@ void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char
128 128
129 fclose(f); 129 fclose(f);
130 } 130 }
131#else
132 (void)file;
133 (void)line;
134 (void)func;
131#endif 135#endif
132 136
133 return ndata; 137 return ndata;
@@ -669,26 +673,38 @@ int xs_list_in(char *list, const char *val)
669d_char *xs_join(char *list, const char *sep) 673d_char *xs_join(char *list, const char *sep)
670/* joins a list into a string */ 674/* joins a list into a string */
671{ 675{
672 d_char *s; 676 d_char *s = NULL;
673 char *v; 677 char *v;
674 int c = 0; 678 int c = 0;
675 679 int offset = 0;
676 s = xs_str_new(NULL); 680 int ssz = strlen(sep);
677 681
678 while (xs_list_iter(&list, &v)) { 682 while (xs_list_iter(&list, &v)) {
679 /* refuse to join non-string values */ 683 /* refuse to join non-string values */
680 if (xs_type(v) == XSTYPE_STRING) { 684 if (xs_type(v) == XSTYPE_STRING) {
685 int sz;
686
681 /* add the separator */ 687 /* add the separator */
682 if (c != 0) 688 if (c != 0) {
683 s = xs_str_cat(s, sep); 689 s = xs_realloc(s, offset + ssz);
690 memcpy(s + offset, sep, ssz);
691 offset += ssz;
692 }
684 693
685 /* add the element */ 694 /* add the element */
686 s = xs_str_cat(s, v); 695 sz = strlen(v);
696 s = xs_realloc(s, offset + sz);
697 memcpy(s + offset, v, sz);
698 offset += sz;
687 699
688 c++; 700 c++;
689 } 701 }
690 } 702 }
691 703
704 /* null-terminate */
705 s = xs_realloc(s, _xs_blk_size(offset + 1));
706 s[offset] = '\0';
707
692 return s; 708 return s;
693} 709}
694 710
diff --git a/xs_curl.h b/xs_curl.h
index 7ecef2d..2b07cad 100644
--- a/xs_curl.h
+++ b/xs_curl.h
@@ -71,7 +71,7 @@ static int _post_callback(char *buffer, size_t size,
71 int sz = pd->size - pd->offset; 71 int sz = pd->size - pd->offset;
72 72
73 /* if it's still bigger than the provided space, trim */ 73 /* if it's still bigger than the provided space, trim */
74 if (sz > size * nitems) 74 if (sz > (int) (size * nitems))
75 sz = size * nitems; 75 sz = size * nitems;
76 76
77 memcpy(buffer, pd->data + pd->offset, sz); 77 memcpy(buffer, pd->data + pd->offset, sz);
diff --git a/xs_glob.h b/xs_glob.h
index 978c200..a69cba1 100644
--- a/xs_glob.h
+++ b/xs_glob.h
@@ -21,7 +21,7 @@ d_char *xs_glob_n(const char *spec, int basename, int reverse, int max)
21 if (glob(spec, 0, NULL, &globbuf) == 0) { 21 if (glob(spec, 0, NULL, &globbuf) == 0) {
22 int n; 22 int n;
23 23
24 if (max > globbuf.gl_pathc) 24 if (max > (int) globbuf.gl_pathc)
25 max = globbuf.gl_pathc; 25 max = globbuf.gl_pathc;
26 26
27 for (n = 0; n < max; n++) { 27 for (n = 0; n < max; n++) {
diff --git a/xs_version.h b/xs_version.h
index e400777..682964a 100644
--- a/xs_version.h
+++ b/xs_version.h
@@ -1 +1 @@
/* ae969c59232f4907369f10b84796456388fcf109 */ /* a04f6c8482d42d4d972f5190ecbad5c0509531b4 */