From 3f45febeb351be5b39a440cf82c644ccb0377607 Mon Sep 17 00:00:00 2001 From: valenok Date: Sun, 19 Sep 2010 13:40:16 +0100 Subject: [PATCH] Fixing config file editing on Windows --- main.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index 11336b12..cb2a1480 100644 --- a/main.c +++ b/main.c @@ -56,9 +56,9 @@ #define MAX_OPTIONS 40 static int exit_flag; -static char server_name[40]; // Set by init_server_name() -static char *config_file; // Set by process_command_line_arguments() -static struct mg_context *ctx; // Set by start_mongoose() +static char server_name[40]; // Set by init_server_name() +static char config_file[PATH_MAX]; // Set by process_command_line_arguments() +static struct mg_context *ctx; // Set by start_mongoose() #if !defined(CONFIG_FILE) #define CONFIG_FILE "mongoose.conf" @@ -178,7 +178,7 @@ static void set_option(char **options, const char *name, const char *value) { } static void process_command_line_arguments(char *argv[], char **options) { - char line[512], opt[512], val[512], path[PATH_MAX], *p; + char line[512], opt[512], val[512], *p; FILE *fp = NULL; size_t i, line_no = 0; @@ -186,14 +186,13 @@ static void process_command_line_arguments(char *argv[], char **options) { // Should we use a config file ? if (argv[1] != NULL && argv[2] == NULL) { - config_file = argv[1]; + snprintf(config_file, sizeof(config_file), "%s", argv[1]); } else if ((p = strrchr(argv[0], DIRSEP)) == NULL) { // No command line flags specified. Look where binary lives - config_file = CONFIG_FILE; + snprintf(config_file, sizeof(config_file), "%s", CONFIG_FILE); } else { - snprintf(path, sizeof(path), "%.*s%c%s", + snprintf(config_file, sizeof(config_file), "%.*s%c%s", (int) (p - argv[0]), argv[0], DIRSEP, CONFIG_FILE); - config_file = path; } fp = fopen(config_file, "r");