summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/vdcommon.h4
-rw-r--r--common/vdlog.cpp4
-rw-r--r--common/vdlog.h57
3 files changed, 42 insertions, 23 deletions
diff --git a/common/vdcommon.h b/common/vdcommon.h
index c5268f4..394333b 100644
--- a/common/vdcommon.h
+++ b/common/vdcommon.h
@@ -53,6 +53,10 @@ enum {
#define ALIGN_VC __declspec (align(1))
#endif
+#ifdef OLDMSVCRT
+#define swprintf_s(buf, sz, format...) swprintf(buf, format)
+#endif
+
typedef struct ALIGN_VC VDPipeMessage {
uint32_t type;
uint32_t opaque;
diff --git a/common/vdlog.cpp b/common/vdlog.cpp
index a0444d9..f84b5b3 100644
--- a/common/vdlog.cpp
+++ b/common/vdlog.cpp
@@ -52,7 +52,11 @@ VDLog* VDLog::get(TCHAR* path)
}
if (size != INVALID_FILE_SIZE && size > LOG_ROLL_SIZE) {
TCHAR roll_path[MAX_PATH];
+#ifdef OLDMSVCRT
+ swprintf(roll_path, L"%s.1", path);
+#else
swprintf_s(roll_path, MAX_PATH, L"%s.1", path);
+#endif
if (!MoveFileEx(path, roll_path, MOVEFILE_REPLACE_EXISTING)) {
return NULL;
}
diff --git a/common/vdlog.h b/common/vdlog.h
index b2a7295..2ca03f3 100644
--- a/common/vdlog.h
+++ b/common/vdlog.h
@@ -53,32 +53,43 @@ static unsigned int log_level = LOG_DEBUG;
static unsigned int log_level = LOG_INFO;
#endif
-#define PRINT_LINE(type, format, datetime, ms, ...) \
- printf("%lu::%s::%s,%.3d::%s::" format "\n", GetCurrentThreadId(), type, datetime, ms, \
+#define PRINT_LINE(type, format, datetime, ms, ...) \
+ printf("%lu::%s::%s,%.3d::%s::" format "\n", GetCurrentThreadId(), type, datetime, ms, \
__FUNCTION__, ## __VA_ARGS__);
-#ifdef __MINGW32__
-#define vd_ftime_s _ftime
+#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 vd_ftime_s _ftime_s
+#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" }; \
+ struct _timeb now; \
+ struct tm today; \
+ char datetime_str[20]; \
+ _ftime_s(&now); \
+ localtime_s(&today, &now.time); \
+ strftime(datetime_str, 20, "%Y-%m-%d %H:%M:%S", &today); \
+ if (log) { \
+ log->PRINT_LINE(type_as_char[type], format, datetime_str, now.millitm, ## __VA_ARGS__); \
+ } else { \
+ PRINT_LINE(type_as_char[type], format, datetime_str, now.millitm, ## __VA_ARGS__); \
+ } \
+ } \
+} while(0)
#endif
-#define LOG(type, format, ...) if (type >= log_level && type <= LOG_FATAL) { \
- VDLog* log = VDLog::get(); \
- const char *type_as_char[] = { "DEBUG", "INFO", "WARN", "ERROR", "FATAL" }; \
- struct _timeb now; \
- struct tm today; \
- char datetime_str[20]; \
- vd_ftime_s(&now); \
- localtime_s(&today, &now.time); \
- strftime(datetime_str, 20, "%Y-%m-%d %H:%M:%S", &today); \
- if (log) { \
- log->PRINT_LINE(type_as_char[type], format, datetime_str, now.millitm, ## __VA_ARGS__); \
- } else { \
- PRINT_LINE(type_as_char[type], format, datetime_str, now.millitm, ## __VA_ARGS__); \
- } \
-}
-
+
#define vd_printf(format, ...) LOG(LOG_INFO, format, ## __VA_ARGS__)
#define LOG_INFO(format, ...) LOG(LOG_INFO, format, ## __VA_ARGS__)
#define LOG_WARN(format, ...) LOG(LOG_WARN, format, ## __VA_ARGS__)
@@ -86,11 +97,11 @@ static unsigned int log_level = LOG_INFO;
#define DBGLEVEL 1000
-#define DBG(level, format, ...) { \
+#define DBG(level, format, ...) do { \
if (level <= DBGLEVEL) { \
LOG(LOG_DEBUG, format, ## __VA_ARGS__); \
} \
-}
+} while(0)
#define ASSERT(x) _ASSERTE(x)