From 1bc2132e1d13cebf8b2dba84fcfebd34c0da94cf Mon Sep 17 00:00:00 2001 From: Renaud Allard Date: Thu, 27 Aug 2015 14:48:21 +0200 Subject: [PATCH] Do not append a / at the end of the output path Solves issue #13 --- fiche.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fiche.c b/fiche.c index 7267e8a..8a1a370 100644 --- a/fiche.c +++ b/fiche.c @@ -286,9 +286,10 @@ void generate_url(char *buffer, char *slug, size_t slug_length, struct client_da int create_directory(char *slug) { - char *directory = malloc(strlen(BASEDIR) + strlen(slug) + 1); + char *directory = malloc(strlen(BASEDIR) + strlen(slug) + 2); strcpy(directory, BASEDIR); + strcat(directory, "/"); strcat(directory, slug); mkdir(BASEDIR, S_IRWXU | S_IRGRP | S_IROTH | S_IXOTH | S_IXGRP); @@ -303,8 +304,9 @@ int create_directory(char *slug) void save_to_file(char *slug, char *buffer, struct client_data data) { - char *directory = malloc(strlen(BASEDIR) + strlen(slug) + strlen("/index.txt") + 1); + char *directory = malloc(strlen(BASEDIR) + strlen(slug) + strlen("/index.txt") + 2); strcpy(directory, BASEDIR); + strcat(directory, "/"); strcat(directory, slug); strcat(directory, "/index.txt"); @@ -348,7 +350,7 @@ int check_protocol(char *buffer) void set_basedir() { BASEDIR = getenv("HOME"); - strcat(BASEDIR, "/code/"); + strcat(BASEDIR, "/code"); } void startup_message() @@ -387,8 +389,6 @@ void parse_parameters(int argc, char **argv) break; case 'o': BASEDIR = optarg; - if((BASEDIR[strlen(BASEDIR) - 1]) != '/') - strcat(BASEDIR, "/"); break; case 'l': LOG = optarg;