PocketPC fixes (thanks, David Hedbor!)

This commit is contained in:
Ryan C. Gordon 2003-05-18 07:52:28 +00:00
parent 283c6291a7
commit b50342ad13
3 changed files with 177 additions and 124 deletions

View File

@ -16,8 +16,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifndef _WIN32_WCE
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#endif
#include "physfs.h" #include "physfs.h"
#include "zlib.h" #include "zlib.h"
@ -186,7 +188,9 @@ static const char *zlib_error_string(int rc)
{ {
case Z_OK: return(NULL); /* not an error. */ case Z_OK: return(NULL); /* not an error. */
case Z_STREAM_END: return(NULL); /* not an error. */ case Z_STREAM_END: return(NULL); /* not an error. */
#ifndef _WIN32_WCE
case Z_ERRNO: return(strerror(errno)); case Z_ERRNO: return(strerror(errno));
#endif
case Z_NEED_DICT: return(ERR_ZLIB_NEED_DICT); case Z_NEED_DICT: return(ERR_ZLIB_NEED_DICT);
case Z_DATA_ERROR: return(ERR_ZLIB_DATA_ERROR); case Z_DATA_ERROR: return(ERR_ZLIB_DATA_ERROR);
case Z_MEM_ERROR: return(ERR_ZLIB_MEMORY_ERROR); case Z_MEM_ERROR: return(ERR_ZLIB_MEMORY_ERROR);
@ -894,6 +898,12 @@ static int zip_has_symlink_attr(ZIPentry *entry, PHYSFS_uint32 extern_attr)
static PHYSFS_sint64 zip_dos_time_to_physfs_time(PHYSFS_uint32 dostime) static PHYSFS_sint64 zip_dos_time_to_physfs_time(PHYSFS_uint32 dostime)
{ {
#ifdef _WIN32_WCE
/* We have no struct tm and no mktime right now.
FIXME: This should probably be fixed at some point.
*/
return -1;
#else
PHYSFS_uint32 dosdate; PHYSFS_uint32 dosdate;
struct tm unixtime; struct tm unixtime;
memset(&unixtime, '\0', sizeof (unixtime)); memset(&unixtime, '\0', sizeof (unixtime));
@ -915,6 +925,7 @@ static PHYSFS_sint64 zip_dos_time_to_physfs_time(PHYSFS_uint32 dostime)
unixtime.tm_isdst = -1; unixtime.tm_isdst = -1;
return((PHYSFS_sint64) mktime(&unixtime)); return((PHYSFS_sint64) mktime(&unixtime));
#endif
} /* zip_dos_time_to_physfs_time */ } /* zip_dos_time_to_physfs_time */

View File

@ -24,7 +24,7 @@
#if defined(__i386__) || defined(__ia64__) || defined(WIN32) || \ #if defined(__i386__) || defined(__ia64__) || defined(WIN32) || \
(defined(__alpha__) || defined(__alpha)) || \ (defined(__alpha__) || defined(__alpha)) || \
defined(__arm__) || \ defined(__arm__) || defined(ARM) || \
(defined(__mips__) && defined(__MIPSEL__)) || \ (defined(__mips__) && defined(__MIPSEL__)) || \
defined(__SYMBIAN32__) || \ defined(__SYMBIAN32__) || \
defined(__x86_64__) || \ defined(__x86_64__) || \

View File

@ -26,6 +26,7 @@ typedef struct
const char *__PHYSFS_platformDirSeparator = "\\"; const char *__PHYSFS_platformDirSeparator = "\\";
static char *userDir = NULL;
/* /*
* Figure out what the last failing Win32 API call was, and * Figure out what the last failing Win32 API call was, and
@ -114,14 +115,64 @@ static wchar_t *AscToUnicode(const char *str)
} }
static char *getExePath()
{
DWORD buflen;
int success = 0;
TCHAR *ptr = NULL;
TCHAR *retval = (TCHAR *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
char *charretval;
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
retval[0] = _T('\0');
buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
if (buflen <= 0) {
__PHYSFS_setError(win32strerror());
} else {
retval[buflen] = '\0'; /* does API always null-terminate this? */
ptr = retval+buflen;
while( ptr != retval )
{
if( *ptr != _T('\\') ) {
*ptr-- = _T('\0');
} else {
break;
}
}
success = 1;
} /* else */
if (!success)
{
free(retval);
return(NULL); /* physfs error message will be set, above. */
} /* if */
/* free up the bytes we didn't actually use. */
ptr = (TCHAR *) realloc(retval, sizeof(TCHAR) * _tcslen(retval) + 1);
if (ptr != NULL)
retval = ptr;
charretval = UnicodeToAsc(retval);
free(retval);
if(charretval == NULL) {
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
}
return(charretval); /* w00t. */
} /* getExePath */
int __PHYSFS_platformInit(void) int __PHYSFS_platformInit(void)
{ {
userDir = getExePath();
BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* failed? */
return(1); /* always succeed. */ return(1); /* always succeed. */
} /* __PHYSFS_platformInit */ } /* __PHYSFS_platformInit */
int __PHYSFS_platformDeinit(void) int __PHYSFS_platformDeinit(void)
{ {
free(userDir);
return(1); /* always succeed. */ return(1); /* always succeed. */
} /* __PHYSFS_platformDeinit */ } /* __PHYSFS_platformDeinit */
@ -134,8 +185,7 @@ char **__PHYSFS_platformDetectAvailableCDs(void)
char *__PHYSFS_platformCalcBaseDir(const char *argv0) char *__PHYSFS_platformCalcBaseDir(const char *argv0)
{ {
return("\\"); return(getExePath());
// BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
} /* __PHYSFS_platformCalcBaseDir */ } /* __PHYSFS_platformCalcBaseDir */
@ -147,7 +197,7 @@ char *__PHYSFS_platformGetUserName(void)
char *__PHYSFS_platformGetUserDir(void) char *__PHYSFS_platformGetUserDir(void)
{ {
return("\\"); return userDir;
BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL); BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
} /* __PHYSFS_platformGetUserDir */ } /* __PHYSFS_platformGetUserDir */
@ -160,15 +210,7 @@ PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
int __PHYSFS_platformStricmp(const char *x, const char *y) int __PHYSFS_platformStricmp(const char *x, const char *y)
{ {
const char *p1 = x, *p2 = y; return(_stricmp(x, y));
int r = 0;
while((*p1) && (*p2) && (toupper(*p1++) == toupper(*p2++))) ++r;
r = (!((*p1) || (*p2)) ? (0) : ((toupper(*p1) > toupper(*p2)) ?
(r + 1) : -(r + 1)));
return(r);
} /* __PHYSFS_platformStricmp */ } /* __PHYSFS_platformStricmp */