[Spice-devel] [PATCHv2 win-agent 4/9] mingw: don't use *_s msvcrt variants
Christophe Fergeau
cfergeau at redhat.com
Tue May 22 05:53:19 PDT 2012
On Wed, May 16, 2012 at 08:15:28PM +0200, Marc-André Lureau wrote:
> 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.
> ---
> common/vdcommon.h | 4 ++++
> common/vdlog.cpp | 4 ++++
> common/vdlog.h | 19 +++++++++++++------
> 3 files changed, 21 insertions(+), 6 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..eda15d8 100644
> --- a/common/vdlog.h
> +++ b/common/vdlog.h
> @@ -57,19 +57,24 @@ static unsigned int log_level = LOG_INFO;
> 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, ...) if (type >= log_level && type <= LOG_FATAL) { \
This is a good opportunity to add do ... while (0) around these macros.
Christophe
> + 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__); \
> + } \
> +}
> #else
> -#define vd_ftime_s _ftime_s
> -#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); \
> + _ftime_s(&now); \
> localtime_s(&today, &now.time); \
> strftime(datetime_str, 20, "%Y-%m-%d %H:%M:%S", &today); \
> if (log) { \
> @@ -78,6 +83,8 @@ static unsigned int log_level = LOG_INFO;
> PRINT_LINE(type_as_char[type], format, datetime_str, now.millitm, ## __VA_ARGS__); \
> } \
> }
> +#endif
> +
>
> #define vd_printf(format, ...) LOG(LOG_INFO, format, ## __VA_ARGS__)
> #define LOG_INFO(format, ...) LOG(LOG_INFO, format, ## __VA_ARGS__)
> --
> 1.7.10.1
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20120522/8d6962d7/attachment.pgp>
More information about the Spice-devel
mailing list