diff options
Diffstat (limited to 'shared.c')
-rw-r--r-- | shared.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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 | ||
118 | char *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 | |||
118 | char *strlpart(char *txt, int maxlen) | 133 | char *strlpart(char *txt, int maxlen) |
119 | { | 134 | { |
120 | char *result; | 135 | char *result; |