equal
deleted
inserted
replaced
29 if(tmpbuf && vsnprintf(tmpbuf, requiredSize, fmt, args)>=0) { // and then do the actual formatting. |
29 if(tmpbuf && vsnprintf(tmpbuf, requiredSize, fmt, args)>=0) { // and then do the actual formatting. |
30 result = tmpbuf; |
30 result = tmpbuf; |
31 tmpbuf = NULL; |
31 tmpbuf = NULL; |
32 } |
32 } |
33 free(tmpbuf); |
33 free(tmpbuf); |
|
34 } |
|
35 } |
|
36 return result; |
|
37 } |
|
38 |
|
39 char *flib_join(char **parts, int partCount, const char *delimiter) { |
|
40 size_t totalSize = 1; |
|
41 size_t delimLen = strlen(delimiter); |
|
42 for(int i=0; i<partCount; i++) { |
|
43 totalSize += strlen(parts[i]) + delimLen; |
|
44 } |
|
45 |
|
46 char *result = flib_malloc(totalSize); |
|
47 if(result) { |
|
48 size_t outpos = 0; |
|
49 for(int i=0; i<partCount; i++) { |
|
50 if(i>0) { |
|
51 strcpy(result+outpos, delimiter); |
|
52 outpos += delimLen; |
|
53 } |
|
54 strcpy(result+outpos, parts[i]); |
|
55 outpos += strlen(parts[i]); |
34 } |
56 } |
35 } |
57 } |
36 return result; |
58 return result; |
37 } |
59 } |
38 |
60 |