Browse Source

win32: use sprintf_s and vsnprintf_s on Windows, so that our static library

works with the VS2010 runtime, too. Also reduce the stack size requirements
to avoid depending on __chkstk_ms().
tags/v0.99.beta19
Sam Hocevar sam 12 years ago
parent
commit
f56be9bffa
4 changed files with 27 additions and 15 deletions
  1. +21
    -13
      caca/figfont.c
  2. +3
    -1
      caca/string.c
  3. +1
    -1
      configure.ac
  4. +2
    -0
      win32/config.h

+ 21
- 13
caca/figfont.c View File

@@ -297,14 +297,15 @@ int caca_flush_figlet(caca_canvas_t *cv)

static caca_charfont_t * open_charfont(char const *path)
{
#if !defined __KERNEL__ && defined HAVE_SNPRINTF
char altpath[2048];
#endif
char buf[2048];
char hardblank[10];
caca_charfont_t *ff;
char *data = NULL;
caca_file_t *f;
#if !defined __KERNEL__ && (defined HAVE_SNPRINTF || defined HAVE_SPRINTF_S)
int const pathlen = 2048;
char *altpath = NULL;
#endif
int i, j, size, comment_lines;

ff = malloc(sizeof(caca_charfont_t));
@@ -316,24 +317,31 @@ static caca_charfont_t * open_charfont(char const *path)

/* Open font: if not found, try .tlf, then .flf */
f = caca_file_open(path, "r");
#if !defined __KERNEL__ && defined HAVE_SNPRINTF

#if (! defined(snprintf)) && ( defined(_WIN32) || defined(WIN32) ) && (! defined(__CYGWIN__))
#define snprintf _snprintf
#endif

#if !defined __KERNEL__ && (defined HAVE_SNPRINTF || defined HAVE_SPRINTF_S)
if(!f)
altpath = malloc(pathlen);
if(!f)
{
snprintf(altpath, 2047, "%s.tlf", path);
altpath[2047] = '\0';
#if defined HAVE_SPRINTF_S
sprintf_s(altpath, pathlen - 1, "%s.tlf", path);
#else
snprintf(altpath, pathlen - 1, "%s.tlf", path);
#endif
altpath[pathlen - 1] = '\0';
f = caca_file_open(altpath, "r");
}
if(!f)
{
snprintf(altpath, 2047, "%s.flf", path);
altpath[2047] = '\0';
#if defined HAVE_SPRINTF_S
sprintf_s(altpath, pathlen - 1, "%s.flf", path);
#else
snprintf(altpath, pathlen - 1, "%s.flf", path);
#endif
altpath[pathlen - 1] = '\0';
f = caca_file_open(altpath, "r");
}
if (altpath)
free(altpath);
#endif
if(!f)
{


+ 3
- 1
caca/string.c View File

@@ -336,7 +336,9 @@ int caca_vprintf(caca_canvas_t *cv, int x, int y, char const *format,
if(cv->width - x + 1 > BUFSIZ)
buf = malloc(cv->width - x + 1);

#if defined(HAVE_VSNPRINTF)
#if defined(HAVE_VSNPRINTF_S)
vsnprintf_s(buf, cv->width - x + 1, _TRUNCATE, format, args);
#elif defined(HAVE_VSNPRINTF)
vsnprintf(buf, cv->width - x + 1, format, args);
#else
vsprintf(buf, format, args);


+ 1
- 1
configure.ac View File

@@ -120,7 +120,7 @@ fi
AM_CONDITIONAL(USE_KERNEL, test "${ac_cv_my_have_kernel}" = "yes")

AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h errno.h locale.h getopt.h dlfcn.h termios.h)
AC_CHECK_FUNCS(signal ioctl snprintf vsnprintf getenv putenv strcasecmp htons)
AC_CHECK_FUNCS(signal ioctl snprintf sprintf_s vsnprintf vsnprintf_s getenv putenv strcasecmp htons)
AC_CHECK_FUNCS(usleep gettimeofday atexit)

ac_cv_have_getopt_long="no"


+ 2
- 0
win32/config.h View File

@@ -43,6 +43,7 @@
#define HAVE_SLEEP 1
/* #undef HAVE_SLSMG_UTF8_ENABLE */
#define HAVE_SNPRINTF 1
#define HAVE_SPRINTF_S 1
#define HAVE_STDARG_H 1
#define HAVE_STDIO_H 1
/* #undef HAVE_STDINT_H */
@@ -59,6 +60,7 @@
/* #undef HAVE_UNISTD_H */
/* #undef HAVE_USLEEP */
/* #undef HAVE_VSNPRINTF */
#define HAVE_VSNPRINTF_S 1
#define HAVE_WINDOWS_H 1
#define HAVE_WINSOCK2_H 1
/* #undef HAVE_X11_XKBLIB_H */


Loading…
Cancel
Save