Commit fcb49d75 authored by valenok's avatar valenok

got rid of getcwd(). using __cdecl for signal handler.

parent 1ceafea1
...@@ -45,10 +45,12 @@ ...@@ -45,10 +45,12 @@
#define snprintf _snprintf #define snprintf _snprintf
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#define sleep(x) Sleep((x) * 1000) #define sleep(x) Sleep((x) * 1000)
#define WINCDECL __cdecl
#else #else
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#define DIRSEP '/' #define DIRSEP '/'
#define WINCDECL
#endif // _WIN32 #endif // _WIN32
#define MAX_OPTIONS 40 #define MAX_OPTIONS 40
...@@ -62,7 +64,7 @@ static struct mg_context *ctx; ...@@ -62,7 +64,7 @@ static struct mg_context *ctx;
#define CONFIG_FILE "mongoose.conf" #define CONFIG_FILE "mongoose.conf"
#endif /* !CONFIG_FILE */ #endif /* !CONFIG_FILE */
static void signal_handler(int sig_num) { static void WINCDECL signal_handler(int sig_num) {
#if !defined(_WIN32) #if !defined(_WIN32)
if (sig_num == SIGCHLD) { if (sig_num == SIGCHLD) {
do { do {
...@@ -177,7 +179,7 @@ static void set_option(char **options, const char *name, const char *value) { ...@@ -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) { static void process_command_line_arguments(char *argv[], char **options) {
const char *config_file = NULL; 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; FILE *fp = NULL;
struct stat st; struct stat st;
size_t i, line_no = 0; size_t i, line_no = 0;
...@@ -185,12 +187,12 @@ static void process_command_line_arguments(char *argv[], char **options) { ...@@ -185,12 +187,12 @@ static void process_command_line_arguments(char *argv[], char **options) {
/* Should we use a config file ? */ /* Should we use a config file ? */
if (argv[1] != NULL && argv[2] == NULL) { if (argv[1] != NULL && argv[2] == NULL) {
config_file = argv[1]; 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 // No command line flags specified. Look where binary lives
// TODO(lsm): do proper error handling here config_file = CONFIG_FILE;
getcwd(path, sizeof(path)); } else if (argv[1] == NULL) {
snprintf(path + strlen(path), sizeof(path) - strlen(path), "%c%s", snprintf(path, sizeof(path), "%.*s%c%s",
DIRSEP, CONFIG_FILE); (int) (p - argv[0]), argv[0], DIRSEP, CONFIG_FILE);
if (stat(path, &st) == 0) { if (stat(path, &st) == 0) {
config_file = path; config_file = path;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment