Changeset 4817


Ignore:
Timestamp:
06/13/12 13:32:42 (12 months ago)
Author:
sam
Message:

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().

Location:
libcaca/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/figfont.c

    r4812 r4817  
    298298static caca_charfont_t * open_charfont(char const *path) 
    299299{ 
    300 #if !defined __KERNEL__ && defined HAVE_SNPRINTF 
    301     char altpath[2048]; 
    302 #endif 
    303300    char buf[2048]; 
    304301    char hardblank[10]; 
     
    306303    char *data = NULL; 
    307304    caca_file_t *f; 
     305#if !defined __KERNEL__ && (defined HAVE_SNPRINTF || defined HAVE_SPRINTF_S) 
     306    int const pathlen = 2048; 
     307    char *altpath = NULL; 
     308#endif 
    308309    int i, j, size, comment_lines; 
    309310 
     
    317318    /* Open font: if not found, try .tlf, then .flf */ 
    318319    f = caca_file_open(path, "r"); 
    319 #if !defined __KERNEL__ && defined HAVE_SNPRINTF 
    320  
    321 #if (! defined(snprintf)) && ( defined(_WIN32) || defined(WIN32) ) && (! defined(__CYGWIN__)) 
    322 #define snprintf _snprintf 
     320#if !defined __KERNEL__ && (defined HAVE_SNPRINTF || defined HAVE_SPRINTF_S) 
     321    if(!f) 
     322        altpath = malloc(pathlen); 
     323    if(!f) 
     324    { 
     325#if defined HAVE_SPRINTF_S 
     326        sprintf_s(altpath, pathlen - 1, "%s.tlf", path); 
     327#else 
     328        snprintf(altpath, pathlen - 1, "%s.tlf", path); 
    323329#endif 
    324  
     330        altpath[pathlen - 1] = '\0'; 
     331        f = caca_file_open(altpath, "r"); 
     332    } 
    325333    if(!f) 
    326334    { 
    327         snprintf(altpath, 2047, "%s.tlf", path); 
    328         altpath[2047] = '\0'; 
     335#if defined HAVE_SPRINTF_S 
     336        sprintf_s(altpath, pathlen - 1, "%s.flf", path); 
     337#else 
     338        snprintf(altpath, pathlen - 1, "%s.flf", path); 
     339#endif 
     340        altpath[pathlen - 1] = '\0'; 
    329341        f = caca_file_open(altpath, "r"); 
    330342    } 
    331     if(!f) 
    332     { 
    333         snprintf(altpath, 2047, "%s.flf", path); 
    334         altpath[2047] = '\0'; 
    335         f = caca_file_open(altpath, "r"); 
    336     } 
     343    if (altpath) 
     344        free(altpath); 
    337345#endif 
    338346    if(!f) 
  • libcaca/trunk/caca/string.c

    r4369 r4817  
    337337        buf = malloc(cv->width - x + 1); 
    338338 
    339 #if defined(HAVE_VSNPRINTF) 
     339#if defined(HAVE_VSNPRINTF_S) 
     340    vsnprintf_s(buf, cv->width - x + 1, _TRUNCATE, format, args); 
     341#elif defined(HAVE_VSNPRINTF) 
    340342    vsnprintf(buf, cv->width - x + 1, format, args); 
    341343#else 
  • libcaca/trunk/configure.ac

    r4816 r4817  
    121121 
    122122AC_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) 
    123 AC_CHECK_FUNCS(signal ioctl snprintf vsnprintf getenv putenv strcasecmp htons) 
     123AC_CHECK_FUNCS(signal ioctl snprintf sprintf_s vsnprintf vsnprintf_s getenv putenv strcasecmp htons) 
    124124AC_CHECK_FUNCS(usleep gettimeofday atexit) 
    125125 
  • libcaca/trunk/win32/config.h

    r4679 r4817  
    4444/* #undef HAVE_SLSMG_UTF8_ENABLE */ 
    4545#define HAVE_SNPRINTF 1 
     46#define HAVE_SPRINTF_S 1 
    4647#define HAVE_STDARG_H 1 
    4748#define HAVE_STDIO_H 1 
     
    6061/* #undef HAVE_USLEEP */ 
    6162/* #undef HAVE_VSNPRINTF */ 
     63#define HAVE_VSNPRINTF_S 1 
    6264#define HAVE_WINDOWS_H 1 
    6365#define HAVE_WINSOCK2_H 1 
Note: See TracChangeset for help on using the changeset viewer.