X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/10ac7ad1f30f914dc5ff36ba3651ef6dca11aaf7..0c8e184e9cbf4d3a1e907de9125f6d8210c169d6:/shared.c diff --git a/shared.c b/shared.c index 50fe8e1..e06df91 100644 --- a/shared.c +++ b/shared.c @@ -303,6 +303,37 @@ char *trim_end(const char *str, char c) return s; } +char *strlpart(char *txt, int maxlen) +{ + char *result; + + if (!txt) + return txt; + + if (strlen(txt) <= maxlen) + return txt; + result = xmalloc(maxlen + 1); + memcpy(result, txt, maxlen - 3); + result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; + result[maxlen] = '\0'; + return result; +} + +char *strrpart(char *txt, int maxlen) +{ + char *result; + + if (!txt) + return txt; + + if (strlen(txt) <= maxlen) + return txt; + result = xmalloc(maxlen + 1); + memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); + result[0] = result[1] = result[2] = '.'; + return result; +} + void cgit_add_ref(struct reflist *list, struct refinfo *ref) { size_t size;