provide the deprecated snprintf(). The mingw32 runtime does not provide the MS-specific sprintf_s(). Mingw-w64 copes with both. So we switch to sprintf_s but also provide it as a weak symbol so that mingw32 does not complain.tags/v0.99.beta19
| @@ -689,6 +689,12 @@ typedef struct cucul_buffer cucul_buffer_t; | |||||
| # define CACA_ALIAS(x) | # define CACA_ALIAS(x) | ||||
| # endif | # endif | ||||
| # if defined __GNUC__ && __GNUC__ > 3 | |||||
| # define CACA_WEAK __attribute__ ((weak)) | |||||
| # else | |||||
| # define CACA_WEAK | |||||
| # endif | |||||
| /* Aliases from old libcaca and libcucul functions */ | /* Aliases from old libcaca and libcucul functions */ | ||||
| __extern int cucul_putchar(caca_canvas_t *, int, int, | __extern int cucul_putchar(caca_canvas_t *, int, int, | ||||
| @@ -341,13 +341,15 @@ int caca_free_canvas(caca_canvas_t *cv) | |||||
| * \return A random integer comprised between \p min and \p max - 1 | * \return A random integer comprised between \p min and \p max - 1 | ||||
| * (inclusive). | * (inclusive). | ||||
| */ | */ | ||||
| static caca_timer_t timer = {0, 0}; | |||||
| int caca_rand(int min, int max) | int caca_rand(int min, int max) | ||||
| { | { | ||||
| static int need_init = 1; | static int need_init = 1; | ||||
| if(need_init) | if(need_init) | ||||
| { | { | ||||
| srand(getpid() + time(NULL)); | |||||
| srand(getpid() + _caca_getticks(&timer)); | |||||
| need_init = 0; | need_init = 0; | ||||
| } | } | ||||
| @@ -29,6 +29,10 @@ | |||||
| #include "caca.h" | #include "caca.h" | ||||
| #include "caca_internals.h" | #include "caca_internals.h" | ||||
| #if defined _WIN32 && defined __GNUC__ && __GNUC__ >= 3 | |||||
| int sprintf_s(char *s, size_t n, const char *fmt, ...) CACA_WEAK; | |||||
| #endif | |||||
| struct caca_charfont | struct caca_charfont | ||||
| { | { | ||||
| int term_width; | int term_width; | ||||
| @@ -622,6 +626,22 @@ static uint32_t hsmush(uint32_t ch1, uint32_t ch2, int rule) | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* | |||||
| * Functions for the mingw32 runtime | |||||
| */ | |||||
| #if defined _WIN32 && defined __GNUC__ && __GNUC__ >= 3 | |||||
| int sprintf_s(char *s, size_t n, const char *fmt, ...) | |||||
| { | |||||
| va_list args; | |||||
| int ret; | |||||
| va_start(args, fmt); | |||||
| ret = vsnprintf(s, n, fmt, args); | |||||
| va_end(args); | |||||
| return ret; | |||||
| } | |||||
| #endif | |||||
| /* | /* | ||||
| * XXX: The following functions are aliases. | * XXX: The following functions are aliases. | ||||
| */ | */ | ||||
| @@ -36,6 +36,11 @@ | |||||
| #include "caca.h" | #include "caca.h" | ||||
| #include "caca_internals.h" | #include "caca_internals.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) CACA_WEAK; | |||||
| #endif | |||||
| /** \brief Set cursor position. | /** \brief Set cursor position. | ||||
| * | * | ||||
| * Put the cursor at the given coordinates. Functions making use of the | * Put the cursor at the given coordinates. Functions making use of the | ||||
| @@ -597,6 +602,17 @@ int caca_set_canvas_boundaries(caca_canvas_t *cv, int x, int y, int w, int h) | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| /* | |||||
| * Functions for the mingw32 runtime | |||||
| */ | |||||
| #if defined _WIN32 && defined __GNUC__ && __GNUC__ >= 3 | |||||
| int vsnprintf_s(char *s, size_t n, size_t c, const char *fmt, va_list args) | |||||
| { | |||||
| return vsnprintf(s, n, fmt, args); | |||||
| } | |||||
| #endif | |||||
| /* | /* | ||||
| * XXX: The following functions are aliases. | * XXX: The following functions are aliases. | ||||
| */ | */ | ||||