(linenum→info "unix/slp.c:2238")

gauche/0.8.12/src/win-compat.c

    1: /*
    2:  * Small utilities for Windows support.
    3:  *
    4:  * Note: Most compatibility stuff are in system.c.  This is splitted
    5:  * away so that it can be used from both libgauche and gauche-config,
    6:  * the latter of which doesn't link to the rest of gauche stuff. 
    7:  *
    8:  * This file is to included from both system.c and gauche-config.c.
    9:  */
   10: 
   11: /* If used from gauche-config.c, the caller must free the allocated
   12:    buffer (gauche-config doesn't link to GC). */
   13: 
   14: static WCHAR *mbs2wcs(const char *s, void (*errfn)(const char *, ...))
   15: {
   16:     WCHAR *wb;
   17:     int nc = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, s, -1, NULL, 0);
   18:     if (nc == 0) {
   19:         errfn("Windows error %d on MultiByteToWideChar", GetLastError());
   20:     }
   21: #if defined(GAUCHE_H)
   22:     wb = SCM_NEW_ATOMIC_ARRAY(WCHAR, nc);
   23: #else
   24:     wb = (WCHAR*)malloc(nc * sizeof(WCHAR));
   25: #endif
   26:     if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, s, -1, wb, nc) == 0) {
   27:         errfn("Windows error %d on MultiByteToWideChar", GetLastError());
   28:     }
   29:     return wb;
   30: }
   31: 
   32: static const char *wcs2mbs(const WCHAR *s, void (*errfn)(const char*, ...))
   33: {
   34:     char *mb;
   35:     int nb = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, 0, 0);
   36:     if (nb == 0) {
   37:         errfn("Windows error %d on WideCharToMultiByte", GetLastError());
   38:     }
   39: #if defined(GAUCHE_H)
   40:     mb = SCM_NEW_ATOMIC_ARRAY(char, nb);
   41: #else
   42:     mb = (char*)malloc(nb);
   43: #endif
   44:     if (WideCharToMultiByte(CP_UTF8, 0, s, -1, mb, nb, 0, 0) == 0) {
   45:         errfn("Windows error %d on WideCharToMultiByte", GetLastError());
   46:     }
   47:     return mb;
   48: }
   49: 
Syntax (Markdown)