[ovs-dev] [PATCH] util: fix compile warnings
Joe Stringer
joestringer at nicira.com
Sun Jul 6 22:37:02 UTC 2014
I feel like this is easier to follow if there's only one #ifdef block.
We could combine the blocks and make the two platforms more aligned with
something like this (based against master):
diff --git a/lib/util.c b/lib/util.c
index 4f9b079..c65051d 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -43,7 +43,7 @@ VLOG_DEFINE_THIS_MODULE(util);
COVERAGE_DEFINE(util_xalloc);
/* argv[0] without directory names. */
-const char *program_name;
+char *program_name;
/* Name for the currently running thread or process, for log messages,
process
* listings, and debuggers. */
@@ -455,25 +455,26 @@ void
set_program_name__(const char *argv0, const char *version, const char
*date,
const char *time)
{
- free(program_name);
+ char *basename;
#ifdef _WIN32
- char *basename;
size_t max_len = strlen(argv0) + 1;
SetErrorMode(GetErrorMode() | SEM_NOGPFAULTERRORBOX);
_set_output_format(_TWO_DIGIT_EXPONENT);
+ free(program_name);
basename = xmalloc(max_len);
_splitpath_s(argv0, NULL, 0, NULL, 0, basename, max_len, NULL, 0);
- assert_single_threaded();
- program_name = basename;
#else
const char *slash = strrchr(argv0, '/');
- assert_single_threaded();
- program_name = xstrdup(slash ? slash + 1 : argv0);
+
+ free(program_name);
+ basename = xstrdup(slash ? slash + 1 : argv0);
#endif
+ assert_single_threaded();
+ program_name = basename;
free(program_version);
if (!strcmp(version, VERSION)) {
diff --git a/lib/util.h b/lib/util.h
index b626c0b..dc34ee5 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -86,7 +86,7 @@ void ovs_assert_failure(const char *, const char *, const
char *) NO_RETURN;
((void) sizeof ((int) ((POINTER) == (TYPE) (POINTER))), \
(TYPE) (POINTER))
-extern const char *program_name;
+extern char *program_name;
#define __ARRAY_SIZE_NOCHECK(ARRAY) (sizeof(ARRAY) / sizeof((ARRAY)[0]))
#ifdef __GNUC__
More information about the dev
mailing list