platform/pocketpc.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 22 Nov 2002 06:17:59 +0000
changeset 501 fa1298d1157b
child 566 1e640d4acab9
permissions -rw-r--r--
Initial add.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * Skeleton platform-dependent support routines for PhysicsFS.
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE in the source's root directory.
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#if HAVE_CONFIG_H
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#  include <config.h>
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#endif
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <stdio.h>
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <windows.h>
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#define __PHYSICSFS_INTERNAL__
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include "physfs_internal.h"
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#define INVALID_FILE_ATTRIBUTES		0xFFFFFFFF
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
#define INVALID_SET_FILE_POINTER	0xFFFFFFFF
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
typedef struct
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
    HANDLE handle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
    int readonly;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
} winCEfile;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
const char *__PHYSFS_platformDirSeparator = "\\";
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
/*
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
 * Figure out what the last failing Win32 API call was, and
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
 *  generate a human-readable string for the error message.
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
 *
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
 * The return value is a static buffer that is overwritten with
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
 *  each call to this function.
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
 */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
static const char *win32strerror(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
    static TCHAR msgbuf[255];
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    TCHAR *ptr = msgbuf;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    FormatMessage(
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
        FORMAT_MESSAGE_FROM_SYSTEM |
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
        FORMAT_MESSAGE_IGNORE_INSERTS,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
        NULL,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
        GetLastError(),
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
        msgbuf,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
        sizeof (msgbuf) / sizeof (TCHAR),
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
        NULL 
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
    );
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
        /* chop off newlines. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    for (ptr = msgbuf; *ptr; ptr++)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
        if ((*ptr == '\n') || (*ptr == '\r'))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
        {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
            *ptr = ' ';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
            break;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
        } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    } /* for */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    return((const char *) msgbuf);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
} /* win32strerror */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
static char *UnicodeToAsc(const wchar_t *w_str)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
	char *str=NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
	if(w_str!=NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
		int len=wcslen(w_str)+1;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
		str=(char *)malloc(len);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
		if(WideCharToMultiByte(CP_ACP,0,w_str,-1,str,len,NULL,NULL)==0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
		{	//Conversion failed
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
			free(str);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
			return NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
		}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
		else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
		{	//Conversion successful
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
			return(str);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
		}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
	else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
	{	//Given NULL string
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
		return NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
static wchar_t *AscToUnicode(const char *str)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
	wchar_t *w_str=NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
	if(str!=NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
		int len=strlen(str)+1;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
		w_str=(wchar_t *)malloc(sizeof(wchar_t)*len);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
		if(MultiByteToWideChar(CP_ACP,0,str,-1,w_str,len)==0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
		{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
			free(w_str);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
			return NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
		}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
		else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
		{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
			return(w_str);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
		}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
	else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
		return NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
int __PHYSFS_platformInit(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
    return(1);  /* always succeed. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
} /* __PHYSFS_platformInit */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
int __PHYSFS_platformDeinit(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    return(1);  /* always succeed. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
} /* __PHYSFS_platformDeinit */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
char **__PHYSFS_platformDetectAvailableCDs(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
} /* __PHYSFS_platformDetectAvailableCDs */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
	return("\\");
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
//    BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
} /* __PHYSFS_platformCalcBaseDir */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
char *__PHYSFS_platformGetUserName(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
} /* __PHYSFS_platformGetUserName */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
char *__PHYSFS_platformGetUserDir(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
	return("\\");
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
} /* __PHYSFS_platformGetUserDir */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    return(1);  /* single threaded. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
} /* __PHYSFS_platformGetThreadID */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
int __PHYSFS_platformStricmp(const char *x, const char *y)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
{    
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
	const char *p1 = x, *p2 = y;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
	int r = 0;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
    while((*p1) && (*p2) && (toupper(*p1++) == toupper(*p2++)))  ++r;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
    r = (!((*p1) || (*p2)) ? (0) : ((toupper(*p1) > toupper(*p2)) ?
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
                                    (r + 1) : -(r + 1)));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
    return(r);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
} /* __PHYSFS_platformStricmp */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
int __PHYSFS_platformExists(const char *fname)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
	int retval=0;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
	wchar_t *w_fname=AscToUnicode(fname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
	
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
	if(w_fname!=NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
		retval=(GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
		free(w_fname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
	return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
} /* __PHYSFS_platformExists */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
int __PHYSFS_platformIsSymLink(const char *fname)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
} /* __PHYSFS_platformIsSymlink */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
int __PHYSFS_platformIsDirectory(const char *fname)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
	int retval=0;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
	wchar_t *w_fname=AscToUnicode(fname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
	if(w_fname!=NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
	    retval=((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
		free(w_fname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
	return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
} /* __PHYSFS_platformIsDirectory */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
char *__PHYSFS_platformCvtToDependent(const char *prepend,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
                                      const char *dirName,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
                                      const char *append)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
    int len = ((prepend) ? strlen(prepend) : 0) +
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
              ((append) ? strlen(append) : 0) +
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
              strlen(dirName) + 1;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
    char *retval = malloc(len);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
    char *p;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
    if (prepend)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
        strcpy(retval, prepend);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
        retval[0] = '\0';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
    strcat(retval, dirName);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    if (append)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
        strcat(retval, append);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
        *p = '\\';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
} /* __PHYSFS_platformCvtToDependent */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
void __PHYSFS_platformTimeslice(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
    Sleep(10);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
} /* __PHYSFS_platformTimeslice */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
                                                  int omitSymLinks)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
    LinkedStringList *retval = NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
    LinkedStringList *l = NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
    LinkedStringList *prev = NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
    HANDLE dir;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
    WIN32_FIND_DATA ent;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
    char *SearchPath;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
	wchar_t *w_SearchPath;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
    size_t len = strlen(dirname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
    /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
    SearchPath = (char *) alloca(len + 3);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
    BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL);	
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
    /* Copy current dirname */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    strcpy(SearchPath, dirname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
    /* if there's no '\\' at the end of the path, stick one in there. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
    if (SearchPath[len - 1] != '\\')
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
        SearchPath[len++] = '\\';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
        SearchPath[len] = '\0';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
    /* Append the "*" to the end of the string */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
    strcat(SearchPath, "*");
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
	w_SearchPath=AscToUnicode(SearchPath);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
    dir = FindFirstFile(w_SearchPath, &ent);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
	free(w_SearchPath);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
	free(SearchPath);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
	if(dir == INVALID_HANDLE_VALUE)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
		return NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
    do
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
        if (wcscmp(ent.cFileName, L".") == 0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
            continue;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
        if (wcscmp(ent.cFileName, L"..") == 0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
            continue;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
        l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
        if (l == NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
            break;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
		l->str=UnicodeToAsc(ent.cFileName);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
        if (l->str == NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
        {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
            free(l);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
            break;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
        }
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
        if (retval == NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
            retval = l;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
        else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
            prev->next = l;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
        prev = l;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
        l->next = NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
    } while (FindNextFile(dir, &ent) != 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
    FindClose(dir);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
} /* __PHYSFS_platformEnumerateFiles */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
char *__PHYSFS_platformCurrentDir(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
	return("\\");
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
} /* __PHYSFS_platformCurrentDir */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
char *__PHYSFS_platformRealPath(const char *path)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
	char *retval=(char *)malloc(strlen(path)+1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
	strcpy(retval,path);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
	return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
} /* __PHYSFS_platformRealPath */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
int __PHYSFS_platformMkDir(const char *path)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
	wchar_t *w_path = AscToUnicode(path);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
	if(w_path!=NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
	    DWORD rc = CreateDirectory(w_path, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
		free(w_path);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
		if(rc==0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
		{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
			return(0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
		}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
		return(1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
	else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
		return(0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
} /* __PHYSFS_platformMkDir */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
    HANDLE fileHandle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
    winCEfile *retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
	wchar_t *w_fname=AscToUnicode(fname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
    fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
                            creation, FILE_ATTRIBUTE_NORMAL, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
	free(w_fname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
	if(fileHandle==INVALID_HANDLE_VALUE)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
		return NULL;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
    BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
	retval = malloc(sizeof (winCEfile));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
	if (retval == NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
		CloseHandle(fileHandle);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
		BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
	} /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
	retval->readonly = rdonly;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
	retval->handle = fileHandle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
	return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
} /* doOpen */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
void *__PHYSFS_platformOpenRead(const char *filename)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
    return(doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
} /* __PHYSFS_platformOpenRead */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
void *__PHYSFS_platformOpenWrite(const char *filename)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
    return(doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
} /* __PHYSFS_platformOpenWrite */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
void *__PHYSFS_platformOpenAppend(const char *filename)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
    void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
    if (retval != NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
        HANDLE h = ((winCEfile *) retval)->handle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
        if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
        {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
            const char *err = win32strerror();
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
            CloseHandle(h);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
            free(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
            BAIL_MACRO(err, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
        } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
} /* __PHYSFS_platformOpenAppend */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
    HANDLE FileHandle = ((winCEfile *) opaque)->handle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
    DWORD CountOfBytesRead;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
    PHYSFS_sint64 retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
    /* Read data from the file */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
    /*!!! - uint32 might be a greater # than DWORD */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
    if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
		retval=-1;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
        /* Return the number of "objects" read. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
        /* !!! - What if not the right amount of bytes was read to make an object? */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
        retval = CountOfBytesRead / size;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
} /* __PHYSFS_platformRead */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
    HANDLE FileHandle = ((winCEfile *) opaque)->handle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
    DWORD CountOfBytesWritten;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
    PHYSFS_sint64 retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
    /* Read data from the file */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
    /*!!! - uint32 might be a greater # than DWORD */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
    if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten, NULL))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
		retval=-1;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
        /* Return the number of "objects" read. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
        /*!!! - What if not the right number of bytes was written? */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
        retval = CountOfBytesWritten / size;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
	return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
} /* __PHYSFS_platformWrite */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
    HANDLE FileHandle = ((winCEfile *) opaque)->handle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
    DWORD HighOrderPos;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
    DWORD rc;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
    /* Get the high order 32-bits of the position */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
    //HighOrderPos = HIGHORDER_UINT64(pos);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
	HighOrderPos = (unsigned long)(pos>>32);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
    /*!!! SetFilePointer needs a signed 64-bit value. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
    /* Move pointer "pos" count from start of file */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486
    rc = SetFilePointer(FileHandle, (unsigned long)(pos&0x00000000ffffffff),
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
                        &HighOrderPos, FILE_BEGIN);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
    if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
	{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
        BAIL_MACRO(win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
	}
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
    return(1);  /* No error occured */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
} /* __PHYSFS_platformSeek */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
    HANDLE FileHandle = ((winCEfile *) opaque)->handle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
    DWORD HighPos = 0;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
    DWORD LowPos;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
    PHYSFS_sint64 retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
    /* Get current position */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
    LowPos = SetFilePointer(FileHandle, 0, &HighPos, FILE_CURRENT);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
    if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
        BAIL_MACRO(win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
        /* Combine the high/low order to create the 64-bit position value */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
        retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
        //assert(retval >= 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
} /* __PHYSFS_platformTell */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
    HANDLE FileHandle = ((winCEfile *) opaque)->handle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
    DWORD SizeHigh;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
    DWORD SizeLow;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
    PHYSFS_sint64 retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
    SizeLow = GetFileSize(FileHandle, &SizeHigh);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
    if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
        BAIL_MACRO(win32strerror(), -1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   535
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   536
        /* Combine the high/low order to create the 64-bit position value */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
        retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   538
        //assert(retval >= 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
} /* __PHYSFS_platformFileLength */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
int __PHYSFS_platformEOF(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
    PHYSFS_sint64 FilePosition;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
    int retval = 0;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
    /* Get the current position in the file */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
    if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
        /* Non-zero if EOF is equal to the file length */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
        retval = FilePosition == __PHYSFS_platformFileLength(opaque);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
} /* __PHYSFS_platformEOF */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
int __PHYSFS_platformFlush(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
    winCEfile *fh = ((winCEfile *) opaque);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
    if (!fh->readonly)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
        BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
    return(1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
} /* __PHYSFS_platformFlush */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
int __PHYSFS_platformClose(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
    HANDLE FileHandle = ((winCEfile *) opaque)->handle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
    BAIL_IF_MACRO(!CloseHandle(FileHandle), win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
    free(opaque);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
    return(1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
} /* __PHYSFS_platformClose */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   578
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
int __PHYSFS_platformDelete(const char *path)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
	wchar_t *w_path=AscToUnicode(path);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   583
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
    /* If filename is a folder */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
    if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   587
		int retval=!RemoveDirectory(w_path);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
		free(w_path);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   589
        BAIL_IF_MACRO(retval, win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   590
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
		int retval=!DeleteFile(w_path);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
		free(w_path);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
        BAIL_IF_MACRO(retval, win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   597
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   598
    return(1);  /* if you got here, it worked. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   599
} /* __PHYSFS_platformDelete */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   600
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   602
void *__PHYSFS_platformCreateMutex(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
    return((void *) CreateMutex(NULL, FALSE, NULL));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   605
} /* __PHYSFS_platformCreateMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   606
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
void __PHYSFS_platformDestroyMutex(void *mutex)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
    CloseHandle((HANDLE) mutex);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
} /* __PHYSFS_platformDestroyMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
int __PHYSFS_platformGrabMutex(void *mutex)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
    return(WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   617
} /* __PHYSFS_platformGrabMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   619
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
void __PHYSFS_platformReleaseMutex(void *mutex)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
    ReleaseMutex((HANDLE) mutex);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   623
} /* __PHYSFS_platformReleaseMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   624
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   629
} /* __PHYSFS_platformGetLastModTime */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   630
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
/* end of skeleton.c ... */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632