diff --git a/ccan/opt/helpers.c b/ccan/opt/helpers.c index 8d0ac547..6b7218a0 100644 --- a/ccan/opt/helpers.c +++ b/ccan/opt/helpers.c @@ -11,7 +11,7 @@ /* FIXME: asprintf module? */ static char *arg_bad(const char *fmt, const char *arg) { - char *str = malloc(strlen(fmt) + strlen(arg)); + char *str = (char *)malloc(strlen(fmt) + strlen(arg)); sprintf(str, fmt, arg); return str; } @@ -74,7 +74,11 @@ char *opt_set_floatval(const char *arg, float *f) char *endp; errno = 0; +#if (_MSC_VER >= 1800) *f = strtof(arg, &endp); +#else + *f = strtod(arg, &endp); +#endif if (*endp || !arg[0]) return arg_bad("'%s' is not a number", arg); if (errno) diff --git a/ccan/opt/opt.c b/ccan/opt/opt.c index 9bc34d92..08f8d2a7 100644 --- a/ccan/opt/opt.c +++ b/ccan/opt/opt.c @@ -152,7 +152,7 @@ static void check_opt(const struct opt_table *entry) static void add_opt(const struct opt_table *entry) { - opt_table = realloc(opt_table, sizeof(opt_table[0]) * (opt_count+1)); + opt_table = (struct opt_table *)realloc(opt_table, sizeof(opt_table[0]) * (opt_count + 1)); opt_table[opt_count++] = *entry; } @@ -202,19 +202,19 @@ bool opt_parse(int *argc, char *argv[], void (*errlog)(const char *fmt, ...)) int ret; unsigned offset = 0; - #ifdef WIN32 +#if defined(WIN32) && !defined(_MSC_VER) char *original_argv0 = argv[0]; argv[0] = (char*)basename(argv[0]); - #endif +#endif /* This helps opt_usage. */ opt_argv0 = argv[0]; while ((ret = parse_one(argc, argv, &offset, errlog)) == 1); - #ifdef WIN32 +#if defined(WIN32) && !defined(_MSC_VER) argv[0] = original_argv0; - #endif +#endif /* parse_one returns 0 on finish, -1 on error */ return (ret == 0); @@ -249,7 +249,7 @@ void opt_log_stderr_exit(const char *fmt, ...) char *opt_invalid_argument(const char *arg) { - char *str = malloc(sizeof("Invalid argument '%s'") + strlen(arg)); + char *str = (char *)malloc(sizeof("Invalid argument '%s'") + strlen(arg)); sprintf(str, "Invalid argument '%s'", arg); return str; } diff --git a/ccan/opt/usage.c b/ccan/opt/usage.c index 4d784bc2..108e9b89 100644 --- a/ccan/opt/usage.c +++ b/ccan/opt/usage.c @@ -6,7 +6,7 @@ #include "private.h" /* We only use this for pointer comparisons. */ -const char opt_hidden[1]; +const char opt_hidden[1] = { 0 }; static unsigned write_short_options(char *str) { @@ -33,7 +33,7 @@ char *opt_usage(const char *argv0, const char *extra) for (i = 0; i < opt_count; i++) { if (opt_table[i].cb == (void *)opt_usage_and_exit && opt_table[i].u.carg) { - extra = opt_table[i].u.carg; + extra = (const char *)opt_table[i].u.carg; break; } } @@ -61,7 +61,7 @@ char *opt_usage(const char *argv0, const char *extra) } } - p = ret = malloc(len); + p = ret = (char *)malloc(len); if (!ret) return NULL;