예제 #1
0
int CAPETag::GetFieldString(const str_utf16 * pFieldName, str_ansi * pBuffer, int * pBufferCharacters, BOOL bUTF8Encode)
{
    int nOriginalCharacters = *pBufferCharacters;
    str_utf16 * pUTF16 = new str_utf16 [*pBufferCharacters + 1];
    pUTF16[0] = 0;

    int nRetVal = GetFieldString(pFieldName, pUTF16, pBufferCharacters);
    if (nRetVal == ERROR_SUCCESS)
    {
        CSmartPtr<str_ansi> spANSI(bUTF8Encode ? (str_ansi *) GetUTF8FromUTF16(pUTF16) : GetANSIFromUTF16(pUTF16), TRUE);
        if (int(strlen(spANSI)) > nOriginalCharacters)
        {
            memset(pBuffer, 0, nOriginalCharacters * sizeof(str_ansi));
            *pBufferCharacters = 0;
            nRetVal = ERROR_UNDEFINED;
        }
        else
        {
            strcpy(pBuffer, spANSI);
            *pBufferCharacters = strlen(spANSI);
        }
    }
    
    delete [] pUTF16;

    return nRetVal;
}
예제 #2
0
BOOL FileExists(wchar_t * pFilename)
{    
    if (0 == wcscmp(pFilename, L"-")  ||  0 == wcscmp(pFilename, L"/dev/stdin"))
        return TRUE;

#ifdef _WIN32

    BOOL bFound = FALSE;

    WIN32_FIND_DATA WFD;
    HANDLE hFind = FindFirstFile(pFilename, &WFD);
    if (hFind != INVALID_HANDLE_VALUE)
    {
        bFound = TRUE;
        CloseHandle(hFind);
    }

    return bFound;

#else

    CSmartPtr<char> spANSI(GetANSIFromUTF16(pFilename), TRUE);

    struct stat b;

    if (stat(spANSI, &b) != 0)
        return FALSE;

    if (!S_ISREG(b.st_mode))
        return FALSE;

    return TRUE;

#endif
}