Build a dot-joined string from segments. Returns heap-allocated string. */
| 34 | |
| 35 | /* Build a dot-joined string from segments. Returns heap-allocated string. */ |
| 36 | static char *join_segments(const char **segments, int count) { |
| 37 | if (count == 0) { |
| 38 | return strdup(""); |
| 39 | } |
| 40 | size_t total = 0; |
| 41 | for (int i = 0; i < count; i++) { |
| 42 | total += strlen(segments[i]); |
| 43 | if (i > 0) { |
| 44 | total++; /* dot separator */ |
| 45 | } |
| 46 | } |
| 47 | char *result = malloc(total + SKIP_ONE); |
| 48 | if (!result) { |
| 49 | return NULL; |
| 50 | } |
| 51 | char *p = result; |
| 52 | for (int i = 0; i < count; i++) { |
| 53 | if (i > 0) { |
| 54 | *p++ = '.'; |
| 55 | } |
| 56 | size_t len = strlen(segments[i]); |
| 57 | memcpy(p, segments[i], len); |
| 58 | p += len; |
| 59 | } |
| 60 | *p = '\0'; |
| 61 | return result; |
| 62 | } |
| 63 | |
| 64 | /* Strip file extension from the last path component. */ |
| 65 | static void strip_file_extension(char *path) { |
no outgoing calls
no test coverage detected