[Spice-devel] [vdagent-win 2/2] Add OLDMSVCRT fallback for _ftime_s

Christophe Fergeau cfergeau at redhat.com
Fri Dec 21 02:28:06 PST 2012


Aliasing _ftime_s to _ftime when OLDMSVCRT is defined makes it
possible to remove the timestamp-less implementation of LOG()
while still getting a binary working on Windows XP. I've tested
this with a MinGW build, hopefully this won't break VC++ builds...
---
 common/vdcommon.h |  4 ++++
 common/vdlog.h    | 16 ++--------------
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/common/vdcommon.h b/common/vdcommon.h
index e50f2b0..cc3bd3d 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -46,5 +46,9 @@ typedef CRITICAL_SECTION mutex_t;
 #define swprintf_s(buf, sz, format...) swprintf(buf, format)
 #endif
 
+#ifdef OLDMSVCRT
+#define _ftime_s(timeb) _ftime(timeb)
+#endif
+
 #endif
 
diff --git a/common/vdlog.h b/common/vdlog.h
index 2ca03f3..6d0413b 100644
--- a/common/vdlog.h
+++ b/common/vdlog.h
@@ -25,6 +25,8 @@
 #include <time.h>
 #include <sys/timeb.h>
 
+#include "vdcommon.h"
+
 class VDLog {
 public:
     ~VDLog();
@@ -57,19 +59,6 @@ static unsigned int log_level = LOG_INFO;
     printf("%lu::%s::%s,%.3d::%s::" format "\n", GetCurrentThreadId(), type, datetime, ms, \
            __FUNCTION__, ## __VA_ARGS__);
 
-#ifdef OLDMSVCRT
-#define LOG(type, format, ...) do {                                     \
-    if (type >= log_level && type <= LOG_FATAL) {                       \
-        VDLog* log = VDLog::get();                                      \
-        const char *type_as_char[] = { "DEBUG", "INFO", "WARN", "ERROR", "FATAL" }; \
-        if (log) {                                                      \
-            log->PRINT_LINE(type_as_char[type], format, "", 0, ## __VA_ARGS__); \
-        } else {                                                        \
-            PRINT_LINE(type_as_char[type], format, "", 0, ## __VA_ARGS__); \
-        }                                                               \
-    }                                                                   \
-} while(0)
-#else
 #define LOG(type, format, ...) do {                                     \
     if (type >= log_level && type <= LOG_FATAL) {                       \
         VDLog* log = VDLog::get();                                      \
@@ -87,7 +76,6 @@ static unsigned int log_level = LOG_INFO;
         }                                                               \
     }                                                                   \
 } while(0)
-#endif
 
 
 #define vd_printf(format, ...) LOG(LOG_INFO, format, ## __VA_ARGS__)
-- 
1.8.0.2



More information about the Spice-devel mailing list