From cd61fce90e6f81a472ab951809039148bec6cb49 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sun, 17 Jun 2012 14:05:44 +0000 Subject: [PATCH] build: ship a weak symbol for vsnprintf, too, because our weak symbol for sprintf_s uses that function and VS2010 does not strip it off even if it is unused. Also do not use 64-bit integer division in the timer code because that will create unwanted references to ___moddi3 and ___divdi3. --- caca/canvas.c | 2 +- caca/figfont.c | 6 ++++++ caca/string.c | 12 +++++++++--- caca/time.c | 42 +++++++++++++++++++++++------------------- 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/caca/canvas.c b/caca/canvas.c index f8974e5..f9cd2ed 100644 --- a/caca/canvas.c +++ b/caca/canvas.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2010 Sam Hocevar + * Copyright (c) 2002-2012 Sam Hocevar * All Rights Reserved * * This library is free software. It comes without any warranty, to diff --git a/caca/figfont.c b/caca/figfont.c index 8b12185..7860026 100644 --- a/caca/figfont.c +++ b/caca/figfont.c @@ -31,6 +31,7 @@ #if defined _WIN32 && defined __GNUC__ && __GNUC__ >= 3 int sprintf_s(char *s, size_t n, const char *fmt, ...) CACA_WEAK; +int vsnprintf(char *s, size_t n, const char *fmt, va_list ap) CACA_WEAK; #endif struct caca_charfont @@ -640,6 +641,11 @@ int sprintf_s(char *s, size_t n, const char *fmt, ...) va_end(args); return ret; } + +int vsnprintf(char *s, size_t n, const char *fmt, va_list ap) +{ + return 0; +} #endif /* diff --git a/caca/string.c b/caca/string.c index 023f0fa..d583635 100644 --- a/caca/string.c +++ b/caca/string.c @@ -38,7 +38,8 @@ #if defined _WIN32 && defined __GNUC__ && __GNUC__ >= 3 int vsnprintf_s(char *s, size_t n, size_t c, - const char *fmt, va_list args) CACA_WEAK; + const char *fmt, va_list ap) CACA_WEAK; +int vsnprintf(char *s, size_t n, const char *fmt, va_list ap) CACA_WEAK; #endif /** \brief Set cursor position. @@ -607,9 +608,14 @@ int caca_set_canvas_boundaries(caca_canvas_t *cv, int x, int y, int w, int h) */ #if defined _WIN32 && defined __GNUC__ && __GNUC__ >= 3 -int vsnprintf_s(char *s, size_t n, size_t c, const char *fmt, va_list args) +int vsnprintf_s(char *s, size_t n, size_t c, const char *fmt, va_list ap) { - return vsnprintf(s, n, fmt, args); + return vsnprintf(s, n, fmt, ap); +} + +int vsnprintf(char *s, size_t n, const char *fmt, va_list ap) +{ + return 0; } #endif diff --git a/caca/time.c b/caca/time.c index b6fb87b..b663383 100644 --- a/caca/time.c +++ b/caca/time.c @@ -1,6 +1,6 @@ /* * libcaca Colour ASCII-Art library - * Copyright (c) 2002-2010 Sam Hocevar + * Copyright (c) 2002-2012 Sam Hocevar * All Rights Reserved * * This library is free software. It comes without any warranty, to @@ -35,10 +35,10 @@ void _caca_sleep(int usec) { -#if defined(HAVE_USLEEP) - usleep(usec); -#elif defined(HAVE_SLEEP) +#if defined(HAVE_SLEEP) Sleep((usec + 500) / 1000); +#elif defined(HAVE_USLEEP) + usleep(usec); #else /* SLEEP */ #endif @@ -46,29 +46,33 @@ void _caca_sleep(int usec) int _caca_getticks(caca_timer_t *timer) { -#if defined(HAVE_GETTIMEOFDAY) +#if defined(USE_WIN32) + LARGE_INTEGER tmp; + static double freq = -1.0; /* FIXME: can this move to caca_context? */ + double seconds; +#elif defined(HAVE_GETTIMEOFDAY) struct timeval tv; -#elif defined(USE_WIN32) - static __int64 freq = -1; /* FIXME: can this move to caca_context? */ - __int64 usec; #endif int ticks = 0; int new_sec, new_usec; -#if defined(HAVE_GETTIMEOFDAY) - gettimeofday(&tv, NULL); - new_sec = tv.tv_sec; - new_usec = tv.tv_usec; -#elif defined(USE_WIN32) - if(freq == -1) +#if defined(USE_WIN32) + if (freq < 0.0) { - if(!QueryPerformanceFrequency((LARGE_INTEGER *)&freq)) - freq = 0; + if(!QueryPerformanceFrequency(&tmp)) + freq = 0.0; + else + freq = 1.0 / (double)tmp.QuadPart; } - QueryPerformanceCounter((LARGE_INTEGER *)&usec); - new_sec = (int)(usec * 1000000 / freq / 1000000); - new_usec = (int)((usec * 1000000 / freq) % 1000000); + QueryPerformanceCounter(&tmp); + seconds = freq * (double)tmp.QuadPart; + new_sec = (int)seconds; + new_usec = (int)((seconds - new_sec) * 1000000.0); +#elif defined(HAVE_GETTIMEOFDAY) + gettimeofday(&tv, NULL); + new_sec = tv.tv_sec; + new_usec = tv.tv_usec; #endif if(timer->last_sec != 0)