From fcb49d75ceb756b54ad6b7c78569947d49afce66 Mon Sep 17 00:00:00 2001 From: valenok Date: Tue, 7 Sep 2010 11:00:10 +0100 Subject: [PATCH] got rid of getcwd(). using __cdecl for signal handler. --- main.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index d937922b..6ab67d89 100644 --- a/main.c +++ b/main.c @@ -45,10 +45,12 @@ #define snprintf _snprintf #define vsnprintf _vsnprintf #define sleep(x) Sleep((x) * 1000) +#define WINCDECL __cdecl #else #include #include #define DIRSEP '/' +#define WINCDECL #endif // _WIN32 #define MAX_OPTIONS 40 @@ -62,7 +64,7 @@ static struct mg_context *ctx; #define CONFIG_FILE "mongoose.conf" #endif /* !CONFIG_FILE */ -static void signal_handler(int sig_num) { +static void WINCDECL signal_handler(int sig_num) { #if !defined(_WIN32) if (sig_num == SIGCHLD) { do { @@ -177,7 +179,7 @@ static void set_option(char **options, const char *name, const char *value) { static void process_command_line_arguments(char *argv[], char **options) { const char *config_file = NULL; - char line[512], opt[512], val[512], path[PATH_MAX]; + char line[512], opt[512], val[512], path[PATH_MAX], *p; FILE *fp = NULL; struct stat st; size_t i, line_no = 0; @@ -185,12 +187,12 @@ 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]; - } else if (argv[1] == NULL) { + } else if (argv[1] == NULL && (p = strchr(argv[0], DIRSEP)) == NULL) { // No command line flags specified. Look where binary lives - // TODO(lsm): do proper error handling here - getcwd(path, sizeof(path)); - snprintf(path + strlen(path), sizeof(path) - strlen(path), "%c%s", - DIRSEP, CONFIG_FILE); + config_file = CONFIG_FILE; + } else if (argv[1] == NULL) { + snprintf(path, sizeof(path), "%.*s%c%s", + (int) (p - argv[0]), argv[0], DIRSEP, CONFIG_FILE); if (stat(path, &st) == 0) { config_file = path; }