tskrtt

Simple libev based gopher server
git clone https://git.inz.fi/tskrtt/
Log | Files | Refs | README

commit 8aeae05926ec600aeb4af09f789080ad63126426
parent 522622907f2ef50606232ed57d41f8ae9c96691f
Author: Santtu Lakkala <inz@inz.fi>
Date:   Wed, 26 May 2021 22:44:34 +0300

Avoid double slashes

Diffstat:
Mtask.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/task.c b/task.c @@ -94,14 +94,18 @@ static bool tryfileat(int *fd, const char *fn) static char *joinstr(const char *a, const char *b, char separator) { char *rv; + size_t al; if (!a || !*a) return strdup(b); if (!b) return strdup(a); - rv = malloc(strlen(a) + strlen(b) + 2); + al = strlen(a); + if (al && a[al - 1] == separator) + al--; + rv = malloc(al + strlen(b) + 2); if (!rv) return NULL; - sprintf(rv, "%s%c%s", a, separator, b); + sprintf(rv, "%.*s%c%s", (int)al, a, separator, b); return rv; }