platform/pocketpc.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 09 Mar 2007 08:15:47 +0000
changeset 793 c75c9498c001
parent 792 4c278733e281
child 808 7656f86a9a2c
permissions -rw-r--r--
Updated PocketPC code to handle UTF-8 strings.
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
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    67
#define UTF8_TO_UNICODE_STACK_MACRO(w_assignto, str) { \
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    68
    if (str == NULL) \
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    69
        w_assignto = NULL; \
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    70
    else { \
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    71
        const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) * 4) + 1); \
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    72
        w_assignto = (char *) alloca(len); \
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    73
        PHYSFS_uc2fromutf8(str, (PHYSFS_uint16 *) w_assignto, len); \
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    74
    } \
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    75
} \
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    78
static char *getExePath()
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    79
{
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    80
    DWORD buflen;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    81
    int success = 0;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    82
    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
    83
    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
    84
    char *charretval;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    85
    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
    86
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    87
    retval[0] = _T('\0');
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
    88
    /* !!! FIXME: don't preallocate here? */
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    89
    buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
792
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
    90
    if (buflen <= 0)
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
    91
        __PHYSFS_setError(win32strerror());
792
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
    92
    else
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
    93
    {
792
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
    94
        retval[buflen] = '\0';  /* does API always null-terminate this? */
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
    95
        ptr = retval+buflen;
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
    96
        while( ptr != retval )
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
    97
        {
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
    98
            if( *ptr != _T('\\') )
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
    99
                *ptr-- = _T('\0');
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
   100
            else
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
   101
                break;
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
   102
        } /* while */
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
   103
        success = 1;
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   104
    } /* else */
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   105
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   106
    if (!success)
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   107
    {
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   108
        allocator.Free(retval);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   109
        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
   110
    } /* if */
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   111
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   112
    buflen = (buflen * 4) + 1;
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   113
    charretval = (char *) allocator.Malloc(buflen);
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   114
    if (charretval != NULL)
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   115
        PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) retval, charretval, buflen);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   116
    allocator.Free(retval);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   117
    return(charretval);   /* w00t. */
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   118
} /* getExePath */
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   119
792
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
   120
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
int __PHYSFS_platformInit(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   123
    userDir = getExePath();
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   124
    BAIL_IF_MACRO(userDir == NULL, NULL, 0); /* failed? */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    return(1);  /* always succeed. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
} /* __PHYSFS_platformInit */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
int __PHYSFS_platformDeinit(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
{
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   131
    allocator.Free(userDir);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    return(1);  /* always succeed. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
} /* __PHYSFS_platformDeinit */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   136
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
{
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   138
    /* no-op on this platform. */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
} /* __PHYSFS_platformDetectAvailableCDs */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   144
    return(getExePath());
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
} /* __PHYSFS_platformCalcBaseDir */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
char *__PHYSFS_platformGetUserName(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
} /* __PHYSFS_platformGetUserName */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
char *__PHYSFS_platformGetUserDir(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   156
    return userDir;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
} /* __PHYSFS_platformGetUserDir */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
    return(1);  /* single threaded. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
} /* __PHYSFS_platformGetThreadID */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
int __PHYSFS_platformStricmp(const char *x, const char *y)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
{    
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   169
    return(_stricmp(x, y));
596
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   170
} /* __PHYSFS_platformStricmp */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
596
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   172
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   173
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
   174
{    
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   175
    return(_strnicmp(x, y, (int) len));
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 578
diff changeset
   176
} /* __PHYSFS_platformStrnicmp */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
int __PHYSFS_platformExists(const char *fname)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
{
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   181
    int retval = 0;
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   182
    wchar_t *w_fname = NULL;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   184
    UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname);
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   185
    if (w_fname != NULL)
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   186
        retval = (GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   188
    return(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
} /* __PHYSFS_platformExists */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
int __PHYSFS_platformIsSymLink(const char *fname)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
} /* __PHYSFS_platformIsSymlink */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
int __PHYSFS_platformIsDirectory(const char *fname)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
{
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   200
    int retval = 0;
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   201
    wchar_t *w_fname = NULL;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   203
    UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname);
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   204
    if (w_fname != NULL)
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   205
        retval = ((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   207
    return(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
} /* __PHYSFS_platformIsDirectory */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
char *__PHYSFS_platformCvtToDependent(const char *prepend,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
                                      const char *dirName,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
                                      const char *append)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
    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
   216
    ((append) ? strlen(append) : 0) +
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   217
    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
   218
    char *retval = (char *) allocator.Malloc(len);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
    char *p;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
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
    if (prepend)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
        strcpy(retval, prepend);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
        retval[0] = '\0';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
    strcat(retval, dirName);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
    if (append)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
        strcat(retval, append);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
        *p = '\\';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
} /* __PHYSFS_platformCvtToDependent */
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
void __PHYSFS_platformTimeslice(void)
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
    Sleep(10);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
} /* __PHYSFS_platformTimeslice */
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
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   246
static int doEnumCallback(const wchar_t *w_fname)
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   247
{
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   248
    const PHYSFS_uint64 len = (PHYSFS_uint64) ((wcslen(w_fname) * 4) + 1);
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   249
    char *str = (char *) alloca(len);
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   250
    PHYSFS_utf8fromucs2((const PHYSFS_uint16 *) w_fname, str, len);
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   251
    callback(callbackdata, origdir, str);
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   252
    return 1;
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   253
} /* doEnumCallback */
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   254
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   255
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   256
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
   257
                                     int omitSymLinks,
754
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   258
                                     PHYSFS_EnumFilesCallback callback,
e7cd7411eadf API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents: 747
diff changeset
   259
                                     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
   260
                                     void *callbackdata)
501
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
    HANDLE dir;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
    WIN32_FIND_DATA ent;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
    char *SearchPath;
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   265
    wchar_t *w_SearchPath;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    size_t len = strlen(dirname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
    /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
    SearchPath = (char *) alloca(len + 3);
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 566
diff changeset
   270
    BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL);    
501
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
    /* Copy current dirname */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
    strcpy(SearchPath, dirname);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
    /* 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
   276
    if (SearchPath[len - 1] != '\\')
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
        SearchPath[len++] = '\\';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
        SearchPath[len] = '\0';
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
    /* Append the "*" to the end of the string */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
    strcat(SearchPath, "*");
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   285
    UTF8_TO_UNICODE_STACK_MACRO(w_SearchPath, SearchPath);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
    dir = FindFirstFile(w_SearchPath, &ent);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   288
    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
   289
        return;
501
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
    do
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
    {
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   293
        const char *str = NULL;
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   294
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
        if (wcscmp(ent.cFileName, L".") == 0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
            continue;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
        if (wcscmp(ent.cFileName, L"..") == 0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
            continue;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   301
        if (!doEnumCallback(ent.cFileName))
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
            break;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
    } while (FindNextFile(dir, &ent) != 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    FindClose(dir);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
} /* __PHYSFS_platformEnumerateFiles */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
char *__PHYSFS_platformCurrentDir(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
{
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   311
    return("\\");
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
} /* __PHYSFS_platformCurrentDir */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
char *__PHYSFS_platformRealPath(const char *path)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
{
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   317
    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
   318
    strcpy(retval,path);
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   319
    return(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
} /* __PHYSFS_platformRealPath */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
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
int __PHYSFS_platformMkDir(const char *path)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
{
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   325
    wchar_t *w_path = NULL;
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   326
    UTF8_TO_UNICODE_STACK_MACRO(w_path, path);
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   327
    return ( (w_path != NULL) && (CreateDirectory(w_path, NULL)) );
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
} /* __PHYSFS_platformMkDir */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
    HANDLE fileHandle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
    winCEfile *retval;
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   335
    wchar_t *w_fname = NULL;
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   336
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   337
    UTF8_TO_UNICODE_STACK_MACRO(w_fname, fname);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
    fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
                            creation, FILE_ATTRIBUTE_NORMAL, NULL);
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
    BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   344
    retval = (winCEfile *) allocator.Malloc(sizeof (winCEfile));
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   345
    if (retval == NULL)
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   346
    {
792
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
   347
        CloseHandle(fileHandle);
4c278733e281 Ryanized the formatting in pocketpc.c
Ryan C. Gordon <icculus@icculus.org>
parents: 763
diff changeset
   348
        BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   349
    } /* if */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   351
    retval->readonly = rdonly;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   352
    retval->handle = fileHandle;
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   353
    return(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
} /* doOpen */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
void *__PHYSFS_platformOpenRead(const char *filename)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
    return(doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
} /* __PHYSFS_platformOpenRead */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
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
void *__PHYSFS_platformOpenWrite(const char *filename)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
    return(doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
} /* __PHYSFS_platformOpenWrite */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
void *__PHYSFS_platformOpenAppend(const char *filename)
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
    void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
    if (retval != NULL)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
        HANDLE h = ((winCEfile *) retval)->handle;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
        if (SetFilePointer(h, 0, NULL, FILE_END) == INVALID_SET_FILE_POINTER)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
        {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
            const char *err = win32strerror();
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
            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
   379
            allocator.Free(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
            BAIL_MACRO(err, NULL);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
        } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
} /* __PHYSFS_platformOpenAppend */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   392
    HANDLE Handle = ((winCEfile *) opaque)->handle;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
    DWORD CountOfBytesRead;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
    PHYSFS_sint64 retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
    /* Read data from the file */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
    /*!!! - 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
   398
    if (!ReadFile(Handle, buffer, count * size, &CountOfBytesRead, NULL))
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
    {
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   400
        retval = -1;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
        /* Return the number of "objects" read. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
        /* !!! - 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
   406
        retval = CountOfBytesRead / size;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
} /* __PHYSFS_platformRead */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   417
    HANDLE Handle = ((winCEfile *) opaque)->handle;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
    DWORD CountOfBytesWritten;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
    PHYSFS_sint64 retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
    /* Read data from the file */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
    /*!!! - 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
   423
    if (!WriteFile(Handle, buffer, count * size, &CountOfBytesWritten, NULL))
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
    {
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   425
        retval = -1;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
    else
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
        /* Return the number of "objects" read. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
        /*!!! - What if not the right number of bytes was written? */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
        retval = CountOfBytesWritten / size;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   434
    return(retval);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
} /* __PHYSFS_platformWrite */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   441
    HANDLE Handle = ((winCEfile *) opaque)->handle;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
    DWORD HighOrderPos;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
    DWORD rc;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
    /* Get the high order 32-bits of the position */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
    //HighOrderPos = HIGHORDER_UINT64(pos);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   447
    HighOrderPos = (unsigned long)(pos>>32);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
    /*!!! SetFilePointer needs a signed 64-bit value. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
    /* 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
   451
    rc = SetFilePointer(Handle, (unsigned long)(pos&0x00000000ffffffff),
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
                        &HighOrderPos, FILE_BEGIN);
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
    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
   455
    {
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
        BAIL_MACRO(win32strerror(), 0);
566
1e640d4acab9 PocketPC fixes (thanks, David Hedbor!)
Ryan C. Gordon <icculus@icculus.org>
parents: 501
diff changeset
   457
    }
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
    return(1);  /* No error occured */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
} /* __PHYSFS_platformSeek */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   465
    HANDLE Handle = ((winCEfile *) opaque)->handle;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
    DWORD HighPos = 0;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
    DWORD LowPos;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
    PHYSFS_sint64 retval;
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
    /* 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
   471
    LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
    if ((LowPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
        BAIL_MACRO(win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
        /* Combine the high/low order to create the 64-bit position value */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
        retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
        //assert(retval >= 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
} /* __PHYSFS_platformTell */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
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
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   489
    HANDLE Handle = ((winCEfile *) opaque)->handle;
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
    DWORD SizeHigh;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
    DWORD SizeLow;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
    PHYSFS_sint64 retval;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   494
    SizeLow = GetFileSize(Handle, &SizeHigh);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
    if ((SizeLow == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
        BAIL_MACRO(win32strerror(), -1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
        /* Combine the high/low order to create the 64-bit position value */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
        retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
        //assert(retval >= 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
} /* __PHYSFS_platformFileLength */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
int __PHYSFS_platformEOF(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
    PHYSFS_sint64 FilePosition;
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
    int retval = 0;
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
    /* Get the current position in the file */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
    if ((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
    {
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
        /* Non-zero if EOF is equal to the file length */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
        retval = FilePosition == __PHYSFS_platformFileLength(opaque);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
    return(retval);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
} /* __PHYSFS_platformEOF */
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
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
int __PHYSFS_platformFlush(void *opaque)
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
    winCEfile *fh = ((winCEfile *) opaque);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
    if (!fh->readonly)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
        BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
    return(1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
} /* __PHYSFS_platformFlush */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
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
int __PHYSFS_platformClose(void *opaque)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
{
651
cbe4ea4c7e8e Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   538
    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
   539
    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
   540
    allocator.Free(opaque);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
    return(1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
} /* __PHYSFS_platformClose */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
int __PHYSFS_platformDelete(const char *path)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
{
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   547
    wchar_t *w_path = NULL;
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   548
    UTF8_TO_UNICODE_STACK_MACRO(w_path, path);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
    /* If filename is a folder */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
    if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
    {
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   553
        int retval = !RemoveDirectory(w_path);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
        BAIL_IF_MACRO(retval, win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
    } /* if */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
    else
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
    {
793
c75c9498c001 Updated PocketPC code to handle UTF-8 strings.
Ryan C. Gordon <icculus@icculus.org>
parents: 792
diff changeset
   558
        int retval = !DeleteFile(w_path);
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
        BAIL_IF_MACRO(retval, win32strerror(), 0);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
    } /* else */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
    return(1);  /* if you got here, it worked. */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
} /* __PHYSFS_platformDelete */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
void *__PHYSFS_platformCreateMutex(void)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
    return((void *) CreateMutex(NULL, FALSE, NULL));
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
} /* __PHYSFS_platformCreateMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
void __PHYSFS_platformDestroyMutex(void *mutex)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
    CloseHandle((HANDLE) mutex);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
} /* __PHYSFS_platformDestroyMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
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
int __PHYSFS_platformGrabMutex(void *mutex)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
    return(WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
} /* __PHYSFS_platformGrabMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
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
void __PHYSFS_platformReleaseMutex(void *mutex)
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
{
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
    ReleaseMutex((HANDLE) mutex);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   587
} /* __PHYSFS_platformReleaseMutex */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   589
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   590
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
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
    BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
} /* __PHYSFS_platformGetLastModTime */
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   595
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   596
/* !!! 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
   597
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
   598
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   599
    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
   600
} /* __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
   601
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   602
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   603
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
   604
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   605
    /* 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
   606
} /* __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
   607
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   608
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
   609
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
   610
{
763
efadd9cdb6a4 Cleaned up overflow checks in platform memory allocators (thanks to Nicolas
Ryan C. Gordon <icculus@icculus.org>
parents: 754
diff changeset
   611
    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
   612
    #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
   613
    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
   614
} /* __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
   615
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   616
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
   617
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
   618
{
763
efadd9cdb6a4 Cleaned up overflow checks in platform memory allocators (thanks to Nicolas
Ryan C. Gordon <icculus@icculus.org>
parents: 754
diff changeset
   619
    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
   620
    #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
   621
    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
   622
} /* __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
   623
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   624
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   625
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
   626
{
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 673
diff changeset
   627
    #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
   628
    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
   629
} /* __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
   630
673
983fb6750fdd Fixed incorrect comment.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   631
/* end of pocketpc.c ... */
501
fa1298d1157b Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632