xref: /haiku/src/add-ons/media/plugins/ape_reader/MAClib/GlobalFunctions.cpp (revision 053cc0d4fe060114342762e1e8dbbf86a9cad259)
1 #include "All.h"
2 #include "GlobalFunctions.h"
3 #include "IO.h"
4 
5 #include "CharacterHelper.h"
6 
7 #if 0
8 BOOL GetMMXAvailable ( void )	// 適当
9 {
10 	return FALSE;
11 }
12 #endif
13 
14 /*
15 #ifndef __GNUC_IA32__
16 
17 extern "C" BOOL GetMMXAvailable(void)
18 {
19 #ifdef ENABLE_ASSEMBLY
20 
21     unsigned long nRegisterEDX;
22 
23     try
24     {
25         __asm mov eax, 1
26         __asm CPUID
27         __asm mov nRegisterEDX, edx
28        }
29     catch(...)
30     {
31         return FALSE;
32     }
33 
34     if (nRegisterEDX & 0x800000)
35         RETURN_ON_EXCEPTION(__asm emms, FALSE)
36     else
37         return FALSE;
38 
39     return TRUE;
40 
41 #else
42     return FALSE;
43 #endif
44 }
45 
46 #endif // #ifndef __GNUC_IA32__
47 */
48 
ReadSafe(CIO * pIO,void * pBuffer,int nBytes)49 int ReadSafe(CIO * pIO, void * pBuffer, int nBytes)
50 {
51     unsigned int nBytesRead = 0;
52     int nRetVal = pIO->Read(pBuffer, nBytes, &nBytesRead);
53     if (nRetVal == ERROR_SUCCESS)
54     {
55         if (nBytes != int(nBytesRead))
56             nRetVal = ERROR_IO_READ;
57     }
58 
59     return nRetVal;
60 }
61 
WriteSafe(CIO * pIO,void * pBuffer,int nBytes)62 int WriteSafe(CIO * pIO, void * pBuffer, int nBytes)
63 {
64     unsigned int nBytesWritten = 0;
65     int nRetVal = pIO->Write(pBuffer, nBytes, &nBytesWritten);
66     if (nRetVal == ERROR_SUCCESS)
67     {
68         if (nBytes != int(nBytesWritten))
69             nRetVal = ERROR_IO_WRITE;
70     }
71 
72     return nRetVal;
73 }
74 
FileExists(char * pFilename)75 BOOL FileExists(char* pFilename)
76 {
77     if (0 == wcscmp(pFilename, "-")  ||  0 == wcscmp(pFilename, "/dev/stdin"))
78         return TRUE;
79 
80 #ifdef _WIN32
81 
82     BOOL bFound = FALSE;
83 
84     WIN32_FIND_DATA WFD;
85     HANDLE hFind = FindFirstFile(pFilename, &WFD);
86     if (hFind != INVALID_HANDLE_VALUE)
87     {
88         bFound = TRUE;
89         CloseHandle(hFind);
90     }
91 
92     return bFound;
93 
94 #else
95 
96     CSmartPtr<char> spANSI(GetANSIFromUTF16(pFilename), TRUE);
97 
98     struct stat b;
99 
100     if (stat(spANSI, &b) != 0)
101         return FALSE;
102 
103     if (!S_ISREG(b.st_mode))
104         return FALSE;
105 
106     return TRUE;
107 
108 #endif
109 }
110