Ejemplo n.º 1
0
char *
pyi_win32_wcs_to_mbs_sfn(const wchar_t *wstr)
{
    DWORD wsfnlen;
    wchar_t * wstr_sfn = NULL;
    char * str = NULL;
    DWORD ret;

    wsfnlen = GetShortPathNameW(wstr, NULL, 0);

    if (wsfnlen) {
        wstr_sfn = (wchar_t *)calloc(wsfnlen + 1, sizeof(wchar_t));
        ret = GetShortPathNameW(wstr, wstr_sfn, wsfnlen);

        if (ret) {
            str = pyi_win32_wcs_to_mbs(wstr_sfn);
        }
        free(wstr_sfn);
    }

    if (!str) {
        VS("Failed to get short path name for filename. GetShortPathNameW: \n%s\n",
           GetWinErrorString(0)
           );
        str = pyi_win32_wcs_to_mbs(wstr);
    }
    return str;
}
Ejemplo n.º 2
0
char * pyi_win32_utf8_to_mbs_ex(char * dst, const char * src, size_t max, int sfn) {
    wchar_t * wsrc;
    char * mbs;

    wsrc = pyi_win32_utils_from_utf8(NULL, src, 0);
    if(NULL == wsrc) {
        return NULL;
    }

    if(sfn) {
        mbs = pyi_win32_wcs_to_mbs_sfn(wsrc);
    } else {
        mbs = pyi_win32_wcs_to_mbs(wsrc);
    }

    free(wsrc);
    if(NULL == mbs) {
        return NULL;
    }
    if(dst){
        strncpy(dst, mbs, max);
        free(mbs);
        return dst;
    } else {
        return mbs;
    }
}