Browse Source

win32: define a custom sprintf_s() weak symbol. The VS2010 runtime does not

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
Sam Hocevar sam 12 years ago
parent
commit
02bb261647
4 changed files with 45 additions and 1 deletions
  1. +6
    -0
      caca/caca.h
  2. +3
    -1
      caca/canvas.c
  3. +20
    -0
      caca/figfont.c
  4. +16
    -0
      caca/string.c

+ 6
- 0
caca/caca.h View File

@@ -689,6 +689,12 @@ typedef struct cucul_buffer cucul_buffer_t;
# define CACA_ALIAS(x)
# endif

# if defined __GNUC__ && __GNUC__ > 3
# define CACA_WEAK __attribute__ ((weak))
# else
# define CACA_WEAK
# endif


/* Aliases from old libcaca and libcucul functions */
__extern int cucul_putchar(caca_canvas_t *, int, int,


+ 3
- 1
caca/canvas.c View File

@@ -341,13 +341,15 @@ int caca_free_canvas(caca_canvas_t *cv)
* \return A random integer comprised between \p min and \p max - 1
* (inclusive).
*/
static caca_timer_t timer = {0, 0};

int caca_rand(int min, int max)
{
static int need_init = 1;

if(need_init)
{
srand(getpid() + time(NULL));
srand(getpid() + _caca_getticks(&timer));
need_init = 0;
}



+ 20
- 0
caca/figfont.c View File

@@ -29,6 +29,10 @@
#include "caca.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
{
int term_width;
@@ -622,6 +626,22 @@ static uint32_t hsmush(uint32_t ch1, uint32_t ch2, int rule)
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.
*/


+ 16
- 0
caca/string.c View File

@@ -36,6 +36,11 @@
#include "caca.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.
*
* 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;
}

/*
* 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.
*/


Loading…
Cancel
Save