aboutsummaryrefslogtreecommitdiffstats
path: root/shared.c
diff options
context:
space:
mode:
Diffstat (limited to 'shared.c')
-rw-r--r--shared.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/shared.c b/shared.c
index cc06930..1fa9c99 100644
--- a/shared.c
+++ b/shared.c
@@ -115,6 +115,21 @@ char *trim_end(const char *str, char c)
115 return xstrndup(str, len); 115 return xstrndup(str, len);
116} 116}
117 117
118char *ensure_end(const char *str, char c)
119{
120 size_t len = strlen(str);
121 char *result;
122
123 if (len && str[len - 1] == c)
124 return xstrndup(str, len);
125
126 result = xmalloc(len + 2);
127 memcpy(result, str, len);
128 result[len] = '/';
129 result[len + 1] = '\0';
130 return result;
131}
132
118char *strlpart(char *txt, int maxlen) 133char *strlpart(char *txt, int maxlen)
119{ 134{
120 char *result; 135 char *result;