diff options
-rw-r--r-- | multipart-replace-http-server.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/multipart-replace-http-server.c b/multipart-replace-http-server.c index a5b1c8b..a6a7870 100644 --- a/multipart-replace-http-server.c +++ b/multipart-replace-http-server.c @@ -53,9 +53,12 @@ void file_add(const char *filename) { if (fd < 0) error(EXIT_FAILURE, errno, "opening file: %s", filename); filev = xrealloc(filev, (++filec)*sizeof(*filev)); - const char *shortname = strrchr(filename, '/'); - if (shortname == NULL) - shortname = filename; + char *shortname = strrchr(filename, '/'); + if (shortname == NULL) { + shortname = alloca(strlen(filename)+2); + shortname[0] = '/'; + strcpy(&shortname[1], filename); + } strncpy(filev[filec-1].name, shortname, sizeof(filev[filec-1].name)); error(0, 0, "added file #%zd: %s", filec-1, filev[filec-1].name); filev[filec-1].stream = stream; |