platform/pocketpc.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 01 Jan 2006 12:19:44 +0000
changeset 763 efadd9cdb6a4
parent 754 e7cd7411eadf
child 792 4c278733e281
permissions -rw-r--r--
Cleaned up overflow checks in platform memory allocators (thanks to Nicolas Lebedenco for pointing out the original issue with long long literals).
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
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    19
#define INVALID_FILE_ATTRIBUTES  0xFFFFFFFF
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    20
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
501
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 = "\\";
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    29
static char *userDir = NULL;
501
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
/*
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
 * Figure out what the last failing Win32 API call was, and
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
 *  generate a human-readable string for the error message.
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
 *
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
 * The return value is a static buffer that is overwritten with
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
 *  each call to this function.
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
 */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
static const char *win32strerror(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    static TCHAR msgbuf[255];
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    TCHAR *ptr = msgbuf;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
    FormatMessage(
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    44
        FORMAT_MESSAGE_FROM_SYSTEM |
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    45
        FORMAT_MESSAGE_IGNORE_INSERTS,
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    46
        NULL,
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    47
        GetLastError(),
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    48
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    49
        msgbuf,
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    50
        sizeof (msgbuf) / sizeof (TCHAR),
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    51
        NULL 
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    52
        );
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    54
    /* chop off newlines. */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    for (ptr = msgbuf; *ptr; ptr++)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
        if ((*ptr == '\n') || (*ptr == '\r'))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
        {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
            *ptr = ' ';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
            break;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
        } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    } /* for */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
    return((const char *) msgbuf);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
} /* win32strerror */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
static char *UnicodeToAsc(const wchar_t *w_str)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
{
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    70
    char *str = NULL;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    72
    if (w_str != NULL)
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    73
    {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    74
        int len = wcslen(w_str) + 1;
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
    75
        str = (char *) allocator.Malloc(len);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    77
        if (WideCharToMultiByte(CP_ACP,0,w_str,-1,str,len,NULL,NULL) == 0)
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    78
        {    /*Conversion failed */
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
    79
            allocator.Free(str);
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    80
            return(NULL);
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    81
        } /* if */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    82
        else
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    83
        {    /* Conversion successful */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    84
            return(str);
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    85
        } /* else */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    86
    } /* if */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    87
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    88
    else
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    89
    {    /* Given NULL string */
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    90
        return NULL;
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    91
    }
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    92
} /* UnicodeToAsc */
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    93
501
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
static wchar_t *AscToUnicode(const char *str)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
{
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    97
    wchar_t *w_str = NULL;
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
    98
    if (str != NULL)
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    99
    {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   100
        int len = strlen(str) + 1;
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   101
        w_str = (wchar_t *) allocator.Malloc(sizeof (wchar_t) * len);
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   102
        if (MultiByteToWideChar(CP_ACP,0,str,-1,w_str,len) == 0)
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   103
        {
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   104
            allocator.Free(w_str);
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   105
            return(NULL);
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   106
        } /* if */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   107
        else
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   108
        {
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   109
            return(w_str);
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   110
        } /* else */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   111
    } /* if */
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   112
    else
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   113
    {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   114
        return(NULL);
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   115
    } /* else */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   116
} /* AscToUnicode */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   119
static char *getExePath()
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   120
{
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   121
    DWORD buflen;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   122
    int success = 0;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   123
    TCHAR *ptr = NULL;
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   124
    TCHAR *retval = (TCHAR*) allocator.Malloc(sizeof (TCHAR) * (MAX_PATH + 1));
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   125
    char *charretval;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   126
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   127
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   128
    retval[0] = _T('\0');
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   129
    buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   130
    if (buflen <= 0) {
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   131
        __PHYSFS_setError(win32strerror());
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   132
    } else {
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   133
        retval[buflen] = '\0';  /* does API always null-terminate this? */
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   134
    ptr = retval+buflen;
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   135
    while( ptr != retval )
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   136
    {
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   137
        if( *ptr != _T('\\') ) {
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   138
        *ptr-- = _T('\0');
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   139
        } else {
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   140
        break;
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   141
        }
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   142
    }
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   143
    success = 1;
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   144
    } /* else */
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   145
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   146
    if (!success)
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   147
    {
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   148
        allocator.Free(retval);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   149
        return(NULL);  /* physfs error message will be set, above. */
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   150
    } /* if */
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   151
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   152
    /* free up the bytes we didn't actually use. */
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   153
    ptr = (TCHAR *) allocator.Realloc(retval, sizeof(TCHAR)*_tcslen(retval)+1);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   154
    if (ptr != NULL)
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   155
        retval = ptr;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   156
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   157
    charretval = UnicodeToAsc(retval);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   158
    allocator.Free(retval);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   159
    if(charretval == NULL) {
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   160
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   161
    }
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   162
    
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   163
    return(charretval);   /* w00t. */
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   164
} /* getExePath */
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   165
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
int __PHYSFS_platformInit(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   168
    userDir = getExePath();
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   169
    BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* failed? */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
    return(1);  /* always succeed. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
} /* __PHYSFS_platformInit */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
int __PHYSFS_platformDeinit(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
{
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   176
    allocator.Free(userDir);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    return(1);  /* always succeed. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
} /* __PHYSFS_platformDeinit */
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
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   181
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
{
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   183
    /* no-op on this platform. */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
} /* __PHYSFS_platformDetectAvailableCDs */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
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
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   189
    return(getExePath());
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
} /* __PHYSFS_platformCalcBaseDir */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
char *__PHYSFS_platformGetUserName(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
} /* __PHYSFS_platformGetUserName */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
char *__PHYSFS_platformGetUserDir(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   201
    return userDir;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
} /* __PHYSFS_platformGetUserDir */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
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
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
    return(1);  /* single threaded. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
} /* __PHYSFS_platformGetThreadID */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
int __PHYSFS_platformStricmp(const char *x, const char *y)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
{    
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   214
    return(_stricmp(x, y));
596
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   215
} /* __PHYSFS_platformStricmp */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
596
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   217
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   218
int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 len)
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   219
{    
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   220
    return(_strnicmp(x, y, (int) len));
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   221
} /* __PHYSFS_platformStrnicmp */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
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
int __PHYSFS_platformExists(const char *fname)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   226
    int retval=0;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   228
    wchar_t *w_fname=AscToUnicode(fname);
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   229
    
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   230
    if(w_fname!=NULL)
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   231
    {
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   232
    retval=(GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   233
    allocator.Free(w_fname);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   234
    }
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   236
    return(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
} /* __PHYSFS_platformExists */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
int __PHYSFS_platformIsSymLink(const char *fname)
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
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
} /* __PHYSFS_platformIsSymlink */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
int __PHYSFS_platformIsDirectory(const char *fname)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   248
    int retval=0;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   250
    wchar_t *w_fname=AscToUnicode(fname);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   252
    if(w_fname!=NULL)
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   253
    {
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   254
    retval=((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   255
    allocator.Free(w_fname);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   256
    }
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   258
    return(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
} /* __PHYSFS_platformIsDirectory */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
char *__PHYSFS_platformCvtToDependent(const char *prepend,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
                                      const char *dirName,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
                                      const char *append)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    int len = ((prepend) ? strlen(prepend) : 0) +
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   267
    ((append) ? strlen(append) : 0) +
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   268
    strlen(dirName) + 1;
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   269
    char *retval = (char *) allocator.Malloc(len);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
    char *p;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
    if (prepend)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
        strcpy(retval, prepend);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
        retval[0] = '\0';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
    strcat(retval, dirName);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
    if (append)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
        strcat(retval, append);
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
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
        *p = '\\';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
} /* __PHYSFS_platformCvtToDependent */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
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
void __PHYSFS_platformTimeslice(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
    Sleep(10);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
} /* __PHYSFS_platformTimeslice */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   297
void __PHYSFS_platformEnumerateFiles(const char *dirname,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   298
                                     int omitSymLinks,
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   299
                                     PHYSFS_EnumFilesCallback callback,
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   300
                                     const char *origdir,
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   301
                                     void *callbackdata)
501
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
    HANDLE dir;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
    WIN32_FIND_DATA ent;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    char *SearchPath;
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   306
    wchar_t *w_SearchPath;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
    size_t len = strlen(dirname);
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
    /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
    SearchPath = (char *) alloca(len + 3);
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   311
    BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL);    
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
    /* Copy current dirname */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
    strcpy(SearchPath, dirname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
    /* 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
   317
    if (SearchPath[len - 1] != '\\')
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
        SearchPath[len++] = '\\';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
        SearchPath[len] = '\0';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
    } /* if */
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
    /* Append the "*" to the end of the string */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
    strcat(SearchPath, "*");
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   326
    w_SearchPath=AscToUnicode(SearchPath);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
    dir = FindFirstFile(w_SearchPath, &ent);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   329
    allocator.Free(w_SearchPath);
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   330
    allocator.Free(SearchPath);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   332
    if (dir == INVALID_HANDLE_VALUE)
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   333
        return;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
    do
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
    {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   337
        const char *str;
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   338
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
        if (wcscmp(ent.cFileName, L".") == 0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
            continue;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
        if (wcscmp(ent.cFileName, L"..") == 0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
            continue;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   345
        /* !!! FIXME: avoid malloc in UnicodeToAsc? */
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   346
        str = UnicodeToAsc(ent.cFileName);
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   347
        if (str == NULL)
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
            break;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   350
        callback(callbackdata, origdir, str);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   351
        allocator.Free(str);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
    } while (FindNextFile(dir, &ent) != 0);
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
    FindClose(dir);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
} /* __PHYSFS_platformEnumerateFiles */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
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
char *__PHYSFS_platformCurrentDir(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   360
    return("\\");
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
} /* __PHYSFS_platformCurrentDir */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
char *__PHYSFS_platformRealPath(const char *path)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
{
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   366
    char *retval = (char *) allocator.Malloc(strlen(path) + 1);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   367
    strcpy(retval,path);
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   368
    return(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
} /* __PHYSFS_platformRealPath */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
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
int __PHYSFS_platformMkDir(const char *path)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   374
    wchar_t *w_path = AscToUnicode(path);
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   375
    if(w_path!=NULL)
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   376
    {
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   377
    DWORD rc = CreateDirectory(w_path, NULL);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   378
    allocator.Free(w_path);
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   379
    if(rc==0)
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   380
    {
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   381
        return(0);
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   382
    }
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   383
    return(1);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   384
    }
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   385
    else
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   386
    {
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   387
    return(0);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   388
    }
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
} /* __PHYSFS_platformMkDir */
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
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
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
    HANDLE fileHandle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
    winCEfile *retval;
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   396
    wchar_t *w_fname=AscToUnicode(fname);
501
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
    fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
                            creation, FILE_ATTRIBUTE_NORMAL, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   401
    allocator.Free(w_fname);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   403
    if(fileHandle==INVALID_HANDLE_VALUE)
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   404
    {
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   405
    return NULL;
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   406
    }
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
    BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   410
    retval = (winCEfile *) allocator.Malloc(sizeof (winCEfile));
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   411
    if (retval == NULL)
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   412
    {
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   413
    CloseHandle(fileHandle);
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   414
    BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   415
    } /* if */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   417
    retval->readonly = rdonly;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   418
    retval->handle = fileHandle;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   419
    return(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
} /* doOpen */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
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
void *__PHYSFS_platformOpenRead(const char *filename)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
    return(doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
} /* __PHYSFS_platformOpenRead */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
void *__PHYSFS_platformOpenWrite(const char *filename)
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
    return(doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
} /* __PHYSFS_platformOpenWrite */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
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
void *__PHYSFS_platformOpenAppend(const char *filename)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
    void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
    if (retval != NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
        HANDLE h = ((winCEfile *) retval)->handle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
        if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
        {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
            const char *err = win32strerror();
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
            CloseHandle(h);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   445
            allocator.Free(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
            BAIL_MACRO(err, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
        } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
    return(retval);
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
} /* __PHYSFS_platformOpenAppend */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   458
    HANDLE Handle = ((winCEfile *) opaque)->handle;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
    DWORD CountOfBytesRead;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
    PHYSFS_sint64 retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
    /* Read data from the file */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
    /*!!! - uint32 might be a greater # than DWORD */
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   464
    if (!ReadFile(Handle, buffer, count * size, &CountOfBytesRead, NULL))
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
    {
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   466
        retval = -1;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
        /* Return the number of "objects" read. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
        /* !!! - 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
   472
        retval = CountOfBytesRead / size;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
} /* __PHYSFS_platformRead */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
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
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   483
    HANDLE Handle = ((winCEfile *) opaque)->handle;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
    DWORD CountOfBytesWritten;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
    PHYSFS_sint64 retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
    /* Read data from the file */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
    /*!!! - uint32 might be a greater # than DWORD */
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   489
    if (!WriteFile(Handle, buffer, count * size, &CountOfBytesWritten, NULL))
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
    {
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   491
        retval = -1;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
        /* Return the number of "objects" read. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
        /*!!! - What if not the right number of bytes was written? */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
        retval = CountOfBytesWritten / size;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   500
    return(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
} /* __PHYSFS_platformWrite */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
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
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   507
    HANDLE Handle = ((winCEfile *) opaque)->handle;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
    DWORD HighOrderPos;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
    DWORD rc;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
    /* Get the high order 32-bits of the position */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
    //HighOrderPos = HIGHORDER_UINT64(pos);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   513
    HighOrderPos = (unsigned long)(pos>>32);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
    /*!!! SetFilePointer needs a signed 64-bit value. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
    /* Move pointer "pos" count from start of file */
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   517
    rc = SetFilePointer(Handle, (unsigned long)(pos&0x00000000ffffffff),
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
                        &HighOrderPos, FILE_BEGIN);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
    if ((rc == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   521
    {
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
        BAIL_MACRO(win32strerror(), 0);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   523
    }
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
    return(1);  /* No error occured */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
} /* __PHYSFS_platformSeek */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
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
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   531
    HANDLE Handle = ((winCEfile *) opaque)->handle;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
    DWORD HighPos = 0;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
    DWORD LowPos;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
    PHYSFS_sint64 retval;
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
    /* Get current position */
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   537
    LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   538
    if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
        BAIL_MACRO(win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
    else
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
        /* Combine the high/low order to create the 64-bit position value */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
        retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
        //assert(retval >= 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
} /* __PHYSFS_platformTell */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
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
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   555
    HANDLE Handle = ((winCEfile *) opaque)->handle;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
    DWORD SizeHigh;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
    DWORD SizeLow;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
    PHYSFS_sint64 retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   560
    SizeLow = GetFileSize(Handle, &SizeHigh);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
    if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
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
        BAIL_MACRO(win32strerror(), -1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
    else
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
        /* Combine the high/low order to create the 64-bit position value */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
        retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
        //assert(retval >= 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
} /* __PHYSFS_platformFileLength */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
int __PHYSFS_platformEOF(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   578
    PHYSFS_sint64 FilePosition;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
    int retval = 0;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
    /* Get the current position in the file */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
    if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
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
        /* Non-zero if EOF is equal to the file length */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
        retval = FilePosition == __PHYSFS_platformFileLength(opaque);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   587
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   589
} /* __PHYSFS_platformEOF */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   590
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
int __PHYSFS_platformFlush(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
    winCEfile *fh = ((winCEfile *) opaque);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
    if (!fh->readonly)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
        BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0);
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);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   599
} /* __PHYSFS_platformFlush */
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
int __PHYSFS_platformClose(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   604
    HANDLE Handle = ((winCEfile *) opaque)->handle;
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   605
    BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   606
    allocator.Free(opaque);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
    return(1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
} /* __PHYSFS_platformClose */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
int __PHYSFS_platformDelete(const char *path)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   613
    wchar_t *w_path=AscToUnicode(path);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
    /* If filename is a folder */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
    if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   617
    {
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   618
    int retval=!RemoveDirectory(w_path);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   619
    allocator.Free(w_path);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
        BAIL_IF_MACRO(retval, win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   623
    {
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   624
    int retval=!DeleteFile(w_path);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   625
    allocator.Free(w_path);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
        BAIL_IF_MACRO(retval, win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   629
    return(1);  /* if you got here, it worked. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   630
} /* __PHYSFS_platformDelete */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
void *__PHYSFS_platformCreateMutex(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   635
    return((void *) CreateMutex(NULL, FALSE, NULL));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
} /* __PHYSFS_platformCreateMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
void __PHYSFS_platformDestroyMutex(void *mutex)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
    CloseHandle((HANDLE) mutex);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
} /* __PHYSFS_platformDestroyMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   644
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
int __PHYSFS_platformGrabMutex(void *mutex)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
    return(WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
} /* __PHYSFS_platformGrabMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
void __PHYSFS_platformReleaseMutex(void *mutex)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
    ReleaseMutex((HANDLE) mutex);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
} /* __PHYSFS_platformReleaseMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
} /* __PHYSFS_platformGetLastModTime */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   662
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   663
/* !!! FIXME: Don't use C runtime for allocators? */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   664
int __PHYSFS_platformAllocatorInit(void)
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   665
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   666
    return(1);  /* always succeeds. */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   667
} /* __PHYSFS_platformAllocatorInit */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   668
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   669
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   670
void __PHYSFS_platformAllocatorDeinit(void)
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   671
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   672
    /* no-op */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   673
} /* __PHYSFS_platformAllocatorInit */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   674
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   675
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   676
void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s)
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   677
{
763
efadd9cdb6a4 Cleaned up overflow checks in platform memory allocators (thanks to Nicolas
Ryan C. Gordon <icculus@icculus.org>
parents: 754
diff changeset
   678
    BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   679
    #undef malloc
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   680
    return(malloc((size_t) s));
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   681
} /* __PHYSFS_platformMalloc */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   682
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   683
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   684
void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s)
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   685
{
763
efadd9cdb6a4 Cleaned up overflow checks in platform memory allocators (thanks to Nicolas
Ryan C. Gordon <icculus@icculus.org>
parents: 754
diff changeset
   686
    BAIL_IF_MACRO(__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   687
    #undef realloc
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   688
    return(realloc(ptr, (size_t) s));
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   689
} /* __PHYSFS_platformRealloc */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   690
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   692
void __PHYSFS_platformAllocatorFree(void *ptr)
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   693
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   694
    #undef free
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   695
    free(ptr);
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   696
} /* __PHYSFS_platformAllocatorFree */
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   697
673
983fb6750fdd Fixed incorrect comment.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   698
/* end of pocketpc.c ... */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   699