#include "All.h"
#include "GlobalFunctions.h"
#include "IO.h"
#include "CharacterHelper.h"
#if 0
BOOL GetMMXAvailable ( void )
{
return FALSE;
}
#endif
int ReadSafe(CIO * pIO, void * pBuffer, int nBytes)
{
unsigned int nBytesRead = 0;
int nRetVal = pIO->Read(pBuffer, nBytes, &nBytesRead);
if (nRetVal == ERROR_SUCCESS)
{
if (nBytes != int(nBytesRead))
nRetVal = ERROR_IO_READ;
}
return nRetVal;
}
int WriteSafe(CIO * pIO, void * pBuffer, int nBytes)
{
unsigned int nBytesWritten = 0;
int nRetVal = pIO->Write(pBuffer, nBytes, &nBytesWritten);
if (nRetVal == ERROR_SUCCESS)
{
if (nBytes != int(nBytesWritten))
nRetVal = ERROR_IO_WRITE;
}
return nRetVal;
}
BOOL FileExists(char* pFilename)
{
if (0 == wcscmp(pFilename, "-") || 0 == wcscmp(pFilename, "/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
}