4 #include "MacCompatibility.h"
20 typedef long long __int64;
21 typedef __int64 LARGE_INTEGER;
22 static int QueryPerformanceFrequency(LARGE_INTEGER *liptr)
24 assert(sizeof (__int64) == 8);
25 assert(sizeof (LARGE_INTEGER) == 8);
30 static int QueryPerformanceCounter(LARGE_INTEGER *liptr)
33 gettimeofday(&tv, NULL);
34 *liptr = ( (((LARGE_INTEGER) tv.tv_sec) * 1000) +
35 (((LARGE_INTEGER) tv.tv_usec) / 1000) );
47 QueryPerformanceFrequency( (LARGE_INTEGER*)&counterRate);
48 QueryPerformanceCounter( (LARGE_INTEGER*)&baseCounter);
50 __int64 counterRate; // LARGE_INTEGER type has no math functions so use int64
53 static AppTime g_appTime;
56 void CopyCStringToPascal( const char* src, unsigned char dst[256])
58 int len = strlen( src);
60 memcpy( dst + 1, src, len);
64 void CopyPascalStringToC( const unsigned char* src, char* dst)
67 memcpy( dst, src + 1, len);
75 QueryPerformanceCounter( (LARGE_INTEGER*)&counter);
77 counter -= g_appTime.baseCounter;
80 time.lo = (unsigned long)counter;
81 time.hi = (unsigned long)(counter >> 32);
86 Duration AbsoluteDeltaToDuration( AbsoluteTime& a, AbsoluteTime& b)
91 __int64 value2 = b.hi;
97 return durationImmediate;
99 __int64 frac = value % g_appTime.counterRate;
100 value /= g_appTime.counterRate;
107 frac /= g_appTime.counterRate;
108 time = (Duration)frac;
113 frac /= g_appTime.counterRate;
116 time = (Duration)value;
124 #include <sys/types.h>
127 // public domain code from PhysicsFS: http://icculus.org/physfs/
128 static int locateOneElement(char *buf)
135 //if (PHYSFS_exists(buf))
136 if (access(buf, F_OK) == 0)
137 return(1); /* quick rejection: exists in current case. */
139 ptr = strrchr(buf, '/'); /* find entry at end of path. */
150 ptr++; /* point past dirsep to entry itself. */
154 while ((dent = readdir(dirp)) != NULL)
156 if (stricmp(dent->d_name, ptr) == 0)
158 strcpy(ptr, dent->d_name); /* found a match. Overwrite with this case. */
164 /* no match at all... */
167 } /* locateOneElement */
170 static inline int PHYSFSEXT_locateCorrectCase(char *buf)
178 return(0); /* Uh...I guess that's success. */
180 while (ptr = strchr(ptr + 1, '/'))
182 *ptr = '\0'; /* block this path section off */
183 rc = locateOneElement(buf);
184 *ptr = '/'; /* restore path separator */
186 return(-2); /* missing element in path. */
189 /* check final element... */
190 return(locateOneElement(buf) ? 0 : -1);
191 } /* PHYSFSEXT_locateCorrectCase */
195 static char g_filename[ 256];
196 char* ConvertFileName( const char* orgfilename)
198 // translate filename into proper path name
199 if (orgfilename[ 0] == ':')
201 strcpy( g_filename, orgfilename);
203 for (int n = 0; g_filename[ n]; n++)
205 if (g_filename[ n] == ':')
206 g_filename[ n] = '/';
210 PHYSFSEXT_locateCorrectCase(g_filename);