diff options
author | Marc-André Lureau <marcandre.lureau@gmail.com> | 2012-05-11 02:08:26 +0200 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@gmail.com> | 2012-05-24 13:55:31 +0200 |
commit | 60e850c6e48c5223d00591e1d85ad1a31dcd44c5 (patch) | |
tree | da88128973e155c9ff4ade3e4a03a0068187e300 /common | |
parent | 55cf72c2a81dd540db9c7626850f3f9ea26f91c6 (diff) |
mingw: don't use *_s msvcrt variants
Apparently, it comes with a recent version of C library (msvcrt90?),
but I don't know if we can/should ship also a MS dll. Probably it used
to work with an inlined version with VS headers.
The build can be tweaked to use the -non-_s variant with -DOLDMSVCRT
CFLAGS.
Diffstat (limited to 'common')
-rw-r--r-- | common/vdcommon.h | 4 | ||||
-rw-r--r-- | common/vdlog.cpp | 4 | ||||
-rw-r--r-- | common/vdlog.h | 57 |
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) |