commit da7e57f
default
·
2023-01-08 09:39:11 +0000 UTC
parent 631f16a
Backport from xs.
4 files changed,
+25,
-9
M
xs.h
+22,
-6
1@@ -128,6 +128,10 @@ void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char
2
3 fclose(f);
4 }
5+#else
6+ (void)file;
7+ (void)line;
8+ (void)func;
9 #endif
10
11 return ndata;
12@@ -669,26 +673,38 @@ int xs_list_in(char *list, const char *val)
13 d_char *xs_join(char *list, const char *sep)
14 /* joins a list into a string */
15 {
16- d_char *s;
17+ d_char *s = NULL;
18 char *v;
19 int c = 0;
20-
21- s = xs_str_new(NULL);
22+ int offset = 0;
23+ int ssz = strlen(sep);
24
25 while (xs_list_iter(&list, &v)) {
26 /* refuse to join non-string values */
27 if (xs_type(v) == XSTYPE_STRING) {
28+ int sz;
29+
30 /* add the separator */
31- if (c != 0)
32- s = xs_str_cat(s, sep);
33+ if (c != 0) {
34+ s = xs_realloc(s, offset + ssz);
35+ memcpy(s + offset, sep, ssz);
36+ offset += ssz;
37+ }
38
39 /* add the element */
40- s = xs_str_cat(s, v);
41+ sz = strlen(v);
42+ s = xs_realloc(s, offset + sz);
43+ memcpy(s + offset, v, sz);
44+ offset += sz;
45
46 c++;
47 }
48 }
49
50+ /* null-terminate */
51+ s = xs_realloc(s, _xs_blk_size(offset + 1));
52+ s[offset] = '\0';
53+
54 return s;
55 }
56
+1,
-1
1@@ -71,7 +71,7 @@ static int _post_callback(char *buffer, size_t size,
2 int sz = pd->size - pd->offset;
3
4 /* if it's still bigger than the provided space, trim */
5- if (sz > size * nitems)
6+ if (sz > (int) (size * nitems))
7 sz = size * nitems;
8
9 memcpy(buffer, pd->data + pd->offset, sz);
+1,
-1
1@@ -21,7 +21,7 @@ d_char *xs_glob_n(const char *spec, int basename, int reverse, int max)
2 if (glob(spec, 0, NULL, &globbuf) == 0) {
3 int n;
4
5- if (max > globbuf.gl_pathc)
6+ if (max > (int) globbuf.gl_pathc)
7 max = globbuf.gl_pathc;
8
9 for (n = 0; n < max; n++) {
+1,
-1
1@@ -1 +1 @@
2-/* ae969c59232f4907369f10b84796456388fcf109 */
3+/* a04f6c8482d42d4d972f5190ecbad5c0509531b4 */