|
diff --git a/shared.c b/shared.c index 50fe8e1..e06df91 100644 --- a/ shared.c+++ b/ shared.c |
|
@@ -294,24 +294,55 @@ char *trim_end(const char *str, char c) |
294 | len--; |
294 | len--; |
295 | |
295 | |
296 | if (len == 0) |
296 | if (len == 0) |
297 | return NULL; |
297 | return NULL; |
298 | |
298 | |
299 | c = t[len]; |
299 | c = t[len]; |
300 | t[len] = '\0'; |
300 | t[len] = '\0'; |
301 | s = xstrdup(t); |
301 | s = xstrdup(t); |
302 | t[len] = c; |
302 | t[len] = c; |
303 | return s; |
303 | return s; |
304 | } |
304 | } |
305 | |
305 | |
| |
306 | char *strlpart(char *txt, int maxlen) |
| |
307 | { |
| |
308 | char *result; |
| |
309 | |
| |
310 | if (!txt) |
| |
311 | return txt; |
| |
312 | |
| |
313 | if (strlen(txt) <= maxlen) |
| |
314 | return txt; |
| |
315 | result = xmalloc(maxlen + 1); |
| |
316 | memcpy(result, txt, maxlen - 3); |
| |
317 | result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; |
| |
318 | result[maxlen] = '\0'; |
| |
319 | return result; |
| |
320 | } |
| |
321 | |
| |
322 | char *strrpart(char *txt, int maxlen) |
| |
323 | { |
| |
324 | char *result; |
| |
325 | |
| |
326 | if (!txt) |
| |
327 | return txt; |
| |
328 | |
| |
329 | if (strlen(txt) <= maxlen) |
| |
330 | return txt; |
| |
331 | result = xmalloc(maxlen + 1); |
| |
332 | memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); |
| |
333 | result[0] = result[1] = result[2] = '.'; |
| |
334 | return result; |
| |
335 | } |
| |
336 | |
306 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) |
337 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) |
307 | { |
338 | { |
308 | size_t size; |
339 | size_t size; |
309 | |
340 | |
310 | if (list->count >= list->alloc) { |
341 | if (list->count >= list->alloc) { |
311 | list->alloc += (list->alloc ? list->alloc : 4); |
342 | list->alloc += (list->alloc ? list->alloc : 4); |
312 | size = list->alloc * sizeof(struct refinfo *); |
343 | size = list->alloc * sizeof(struct refinfo *); |
313 | list->refs = xrealloc(list->refs, size); |
344 | list->refs = xrealloc(list->refs, size); |
314 | } |
345 | } |
315 | list->refs[list->count++] = ref; |
346 | list->refs[list->count++] = ref; |
316 | } |
347 | } |
317 | |
348 | |
|