platform/win32.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Apr 2002 23:51:47 +0000
changeset 197 b59917ad3bae
parent 195 c9eef6e349a2
child 198 39274fb69c25
permissions -rw-r--r--
Removed unused copyEnvironmentVariable function.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
     2
 * Win32 support routines for PhysicsFS.
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE in the source's root directory.
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#if (defined __STRICT_ANSI__)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#define __PHYSFS_DOING_STRICT_ANSI__
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#endif
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <windows.h>
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    14
#include <userenv.h>
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include <stdio.h>
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
    16
#include <stdlib.h>
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
    17
#include <ctype.h>
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#define __PHYSICSFS_INTERNAL__
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
#include "physfs_internal.h"
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
    22
#define LOWORDER_UINT64(pos)       (PHYSFS_uint32)(pos & 0x00000000FFFFFFFF)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
    23
#define HIGHORDER_UINT64(pos)      (PHYSFS_uint32)(pos & 0xFFFFFFFF00000000)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
    24
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
const char *__PHYSFS_platformDirSeparator = "\\";
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    27
static HANDLE ProcessHandle = NULL;     /* Current process handle */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    28
static HANDLE AccessTokenHandle = NULL; /* Security handle to process */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    29
static DWORD ProcessID;                 /* ID assigned to current process */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    30
static int runningNT;                   /* TRUE if NT derived OS */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    31
static OSVERSIONINFO OSVersionInfo;     /* Information about the OS */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    32
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    33
/* NT specific information */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    34
static char *ProfileDirectory = NULL;   /* User profile folder */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
static const char *win32strerror(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    38
    static TCHAR msgbuf[255];
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
    FormatMessage(
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
        FORMAT_MESSAGE_FROM_SYSTEM |
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
        FORMAT_MESSAGE_IGNORE_INSERTS,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
        NULL,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
        GetLastError(),
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    45
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    46
        msgbuf,
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    47
        sizeof (msgbuf) / sizeof (TCHAR),
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
        NULL 
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
    );
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    51
    return((const char *) msgbuf);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
} /* win32strerror */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
char **__PHYSFS_platformDetectAvailableCDs(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    char **retval = (char **) malloc(sizeof (char *));
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    int cd_count = 1;  /* We count the NULL entry. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    char drive_str[4] = "x:\\";
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    for (drive_str[0] = 'A'; drive_str[0] <= 'Z'; drive_str[0]++)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
        if (GetDriveType(drive_str) == DRIVE_CDROM)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
        {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
            char **tmp = realloc(retval, sizeof (char *) * cd_count + 1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
            if (tmp)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
            {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
                retval = tmp;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
                retval[cd_count-1] = (char *) malloc(4);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
                if (retval[cd_count-1])
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
                {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
                    strcpy(retval[cd_count-1], drive_str);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
                    cd_count++;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
                } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
            } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
        } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    } /* for */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    retval[cd_count - 1] = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
} /* __PHYSFS_detectAvailableCDs */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
127
0d54a1a087d2 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 119
diff changeset
    84
static char *getExePath(const char *argv0)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
{
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
    86
    char *filepart = NULL;
111
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
    87
    char *retval = (char *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
127
0d54a1a087d2 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 119
diff changeset
    88
    DWORD buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
83
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    89
    retval[buflen] = '\0';  /* does API always null-terminate the string? */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    90
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    91
        /* make sure the string was not truncated. */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    92
    if (__PHYSFS_platformStricmp(&retval[buflen - 4], ".exe") == 0)
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    93
    {
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    94
        char *ptr = strrchr(retval, '\\');
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    95
        if (ptr != NULL)
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    96
        {
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    97
            *(ptr + 1) = '\0';  /* chop off filename. */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    98
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    99
            /* free up the bytes we didn't actually use. */            
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   100
            retval = (char *) realloc(retval, strlen(retval) + 1);
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   101
            if (retval != NULL)
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   102
                return(retval);
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   103
        } /* if */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   104
    } /* if */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   105
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   106
    /* if any part of the previous approach failed, try SearchPath()... */
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   107
    buflen = SearchPath(NULL, argv0, NULL, buflen, NULL, NULL);
83
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   108
    retval = (char *) realloc(retval, buflen);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
    BAIL_IF_MACRO(!retval, ERR_OUT_OF_MEMORY, NULL);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   110
    SearchPath(NULL, argv0, NULL, buflen, retval, &filepart);
83
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   111
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
    return(retval);
111
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   113
} /* getExePath */
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   114
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   115
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   116
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   117
{
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   118
    if (strchr(argv0, '\\') != NULL)   /* default behaviour can handle this. */
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   119
        return(NULL);
cbedf24a1dc6 Changes to user dir.
Ryan C. Gordon <icculus@icculus.org>
parents: 87
diff changeset
   120
127
0d54a1a087d2 Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 119
diff changeset
   121
    return(getExePath(argv0));
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
} /* __PHYSFS_platformCalcBaseDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
char *__PHYSFS_platformGetUserName(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   127
    DWORD bufsize = 0;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    LPTSTR retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
    if (GetUserName(NULL, &bufsize) == 0)  /* This SHOULD fail. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
        retval = (LPTSTR) malloc(bufsize);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
        BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
        if (GetUserName(retval, &bufsize) == 0)  /* ?! */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
        {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
            free(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
            retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
        } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    return((char *) retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
} /* __PHYSFS_platformGetUserName */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
char *__PHYSFS_platformGetUserDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
{
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   147
    char *userdir = NULL;
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   148
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   149
    if(runningNT)
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   150
    {
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   151
        userdir = ProfileDirectory;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   152
    }
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   153
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   154
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   155
        /*!!!TODO - Need to return something for Win9x/ME */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   156
    }
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   157
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   158
    return userdir;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
} /* __PHYSFS_platformGetUserDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   162
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
{
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   164
    return((PHYSFS_uint64)GetCurrentThreadId());
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
} /* __PHYSFS_platformGetThreadID */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   168
/* ...make this Cygwin AND Visual C friendly... */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
int __PHYSFS_platformStricmp(const char *x, const char *y)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
{
195
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   171
#if (defined _MSC_VER)
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   172
    return(stricmp(x, y));
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   173
#else
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   174
    int ux, uy;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   175
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   176
    do
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   177
    {
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   178
        ux = toupper((int) *x);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   179
        uy = toupper((int) *y);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   180
        if (ux > uy)
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   181
            return(1);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   182
        else if (ux < uy)
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   183
            return(-1);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   184
        x++;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   185
        y++;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   186
    } while ((ux) && (uy));
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   187
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   188
    return(0);
195
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   189
#endif
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
} /* __PHYSFS_platformStricmp */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
int __PHYSFS_platformExists(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    return(GetFileAttributes(fname) != 0xffffffff);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
} /* __PHYSFS_platformExists */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
int __PHYSFS_platformIsSymLink(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
    return(0);  /* no symlinks on win32. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
} /* __PHYSFS_platformIsSymlink */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
int __PHYSFS_platformIsDirectory(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
    return((GetFileAttributes(fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
} /* __PHYSFS_platformIsDirectory */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
char *__PHYSFS_platformCvtToDependent(const char *prepend,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
                                      const char *dirName,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
                                      const char *append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
    int len = ((prepend) ? strlen(prepend) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
              ((append) ? strlen(append) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
              strlen(dirName) + 1;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
    char *retval = malloc(len);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   219
    char *p;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
    if (prepend)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
        strcpy(retval, prepend);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    else
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
        retval[0] = '\0';
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
    strcat(retval, dirName);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
    if (append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
        strcat(retval, append);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
        *p = '\\';
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
} /* __PHYSFS_platformCvtToDependent */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
/* Much like my college days, try to sleep for 10 milliseconds at a time... */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
void __PHYSFS_platformTimeslice(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
    Sleep(10);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
} /* __PHYSFS_platformTimeslice */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
                                                  int omitSymLinks)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
    LinkedStringList *retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
    LinkedStringList *l = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
    LinkedStringList *prev = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
    HANDLE dir;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
    WIN32_FIND_DATA ent;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
    dir = FindFirstFile(dirname, &ent);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
    BAIL_IF_MACRO(dir == INVALID_HANDLE_VALUE, win32strerror(), NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
119
3ba614e99e70 Minor logic fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   259
    while (FindNextFile(dir, &ent) != 0)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
    {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
        if (strcmp(ent.cFileName, ".") == 0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
            continue;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
        if (strcmp(ent.cFileName, "..") == 0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
            continue;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
        l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
        if (l == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
            break;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
        l->str = (char *) malloc(strlen(ent.cFileName) + 1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
        if (l->str == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
        {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
            free(l);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
            break;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
        } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
        strcpy(l->str, ent.cFileName);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
        if (retval == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
            retval = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
        else
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
            prev->next = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
        prev = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
        l->next = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
    } /* while */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
    FindClose(dir);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
} /* __PHYSFS_platformEnumerateFiles */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
char *__PHYSFS_platformCurrentDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   296
    LPTSTR retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
    DWORD buflen = 0;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   299
    buflen = GetCurrentDirectory(buflen, NULL);
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   300
    retval = (LPTSTR) malloc(sizeof (TCHAR) * (buflen + 2));
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   301
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   302
    GetCurrentDirectory(buflen, retval);
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   303
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   304
    if (retval[buflen - 2] != '\\')
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   305
        strcat(retval, "\\");
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   306
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
    return((char *) retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
} /* __PHYSFS_platformCurrentDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   311
/* this could probably use a cleanup. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
char *__PHYSFS_platformRealPath(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
{
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   314
    char *retval = NULL;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   315
    char *p = NULL;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   316
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   317
    BAIL_IF_MACRO(path == NULL, ERR_INVALID_ARGUMENT, NULL);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   318
    BAIL_IF_MACRO(*path == '\0', ERR_INVALID_ARGUMENT, NULL);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   319
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   320
    retval = (char *) malloc(MAX_PATH);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   321
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   322
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   323
        /*
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   324
         * If in \\server\path format, it's already an absolute path.
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   325
         *  We'll need to check for "." and ".." dirs, though, just in case.
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   326
         */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   327
    if ((path[0] == '\\') && (path[1] == '\\'))
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   328
        strcpy(retval, path);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   329
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   330
    else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   331
    {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   332
        char *currentDir = __PHYSFS_platformCurrentDir();
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   333
        if (currentDir == NULL)
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   334
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   335
            free(retval);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   336
            BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   337
        } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   338
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   339
        if (path[1] == ':')   /* drive letter specified? */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   340
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   341
            /*
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   342
             * Apparently, "D:mypath" is the same as "D:\\mypath" if
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   343
             *  D: is not the current drive. However, if D: is the
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   344
             *  current drive, then "D:mypath" is a relative path. Ugh.
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   345
             */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   346
            if (path[2] == '\\')  /* maybe an absolute path? */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   347
                strcpy(retval, path);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   348
            else  /* definitely an absolute path. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   349
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   350
                if (path[0] == currentDir[0]) /* current drive; relative. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   351
                {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   352
                    strcpy(retval, currentDir);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   353
                    strcat(retval, path + 2);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   354
                } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   355
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   356
                else  /* not current drive; absolute. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   357
                {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   358
                    retval[0] = path[0];
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   359
                    retval[1] = ':';
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   360
                    retval[2] = '\\';
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   361
                    strcpy(retval + 3, path + 2);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   362
                } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   363
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   364
        } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   365
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   366
        else  /* no drive letter specified. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   367
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   368
            if (path[0] == '\\')  /* absolute path. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   369
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   370
                retval[0] = currentDir[0];
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   371
                retval[1] = ':';
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   372
                strcpy(retval + 2, path);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   373
            } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   374
            else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   375
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   376
                strcpy(retval, currentDir);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   377
                strcat(retval, path);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   378
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   379
        } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   380
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   381
        free(currentDir);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   382
    } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   383
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   384
    /* (whew.) Ok, now take out "." and ".." path entries... */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   385
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   386
    p = retval;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   387
    while ( (p = strstr(p, "\\.")) != NULL)
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   388
    {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   389
            /* it's a "." entry that doesn't end the string. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   390
        if (p[2] == '\\')
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   391
            memmove(p + 1, p + 3, strlen(p + 3) + 1);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   392
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   393
            /* it's a "." entry that ends the string. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   394
        else if (p[2] == '\0')
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   395
            p[0] = '\0';
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   396
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   397
            /* it's a ".." entry. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   398
        else if (p[2] == '.')
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   399
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   400
            char *prevEntry = p - 1;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   401
            while ((prevEntry != retval) && (*prevEntry != '\\'))
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   402
                prevEntry--;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   403
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   404
            if (prevEntry == retval)  /* make it look like a "." entry. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   405
                memmove(p + 1, p + 2, strlen(p + 2) + 1);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   406
            else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   407
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   408
                if (p[3] != '\0') /* doesn't end string. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   409
                    *prevEntry = '\0';
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   410
                else /* ends string. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   411
                    memmove(prevEntry + 1, p + 4, strlen(p + 4) + 1);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   412
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   413
                p = prevEntry;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   414
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   415
        } /* else if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   416
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   417
        else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   418
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   419
            p++;  /* look past current char. */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   420
        } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   421
    } /* while */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   422
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   423
        /* shrink the retval's memory block if possible... */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   424
    p = (char *) realloc(retval, strlen(retval) + 1);
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   425
    if (p != NULL)
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   426
        retval = p;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   427
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   428
    return(retval);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
} /* __PHYSFS_platformRealPath */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
int __PHYSFS_platformMkDir(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   434
    DWORD rc = CreateDirectory(path, NULL);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
    BAIL_IF_MACRO(rc == 0, win32strerror(), 0);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
    return(1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
} /* __PHYSFS_platformMkDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   439
/*
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   440
 * Initialize any NT specific stuff.  This includes any OS based on NT.
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   441
 *
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   442
 * Return zero if there was a catastrophic failure and non-zero otherwise.
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   443
 */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   444
static int doNTInit()
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   445
{
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   446
    DWORD pathsize = 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   447
    char TempProfileDirectory[1];
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   448
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   449
    /* Create a process access token handle */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   450
    if(!OpenProcessToken(ProcessHandle, TOKEN_QUERY, &AccessTokenHandle))
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   451
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   452
        /* Access token is required by other win32 functions */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   453
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   454
    }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   455
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   456
    /* Should fail.  Will write the size of the profile path in pathsize*/
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   457
    /*!!! Second parameter can't be NULL or the function fails??? */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   458
    if(!GetUserProfileDirectory(AccessTokenHandle, TempProfileDirectory, &pathsize))
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   459
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   460
        /* Allocate memory for the profile directory */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   461
        ProfileDirectory = (char *)malloc(pathsize);
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   462
        BAIL_IF_MACRO(ProfileDirectory == NULL, ERR_OUT_OF_MEMORY, 0);
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   463
        /* Try to get the profile directory */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   464
        if(!GetUserProfileDirectory(AccessTokenHandle, ProfileDirectory, &pathsize))
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   465
        {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   466
            free(ProfileDirectory);
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   467
            return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   468
        }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   469
    }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   470
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   471
    /* Everything initialized okay */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   472
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   473
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   474
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   475
/* 
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   476
 * Get OS info and save it.
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   477
 *
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   478
 * Returns non-zero if successful, otherwise it returns zero on failure.
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   479
 */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   480
int getOSInfo(void)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   481
{
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   482
    /* Get OS info */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   483
    OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVersionInfo);
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   484
    if(!GetVersionEx(&OSVersionInfo))
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   485
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   486
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   487
    }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   488
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   489
    /* Set to TRUE if we are runnign a WinNT based OS 4.0 or greater */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   490
    runningNT = (OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   491
        (OSVersionInfo.dwMajorVersion > 3);
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   492
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   493
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   494
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   495
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   496
int __PHYSFS_platformInit(void)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   497
{
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   498
    if(!getOSInfo())
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   499
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   500
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   501
    }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   502
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   503
    /* Get Windows ProcessID associated with the current process */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   504
    ProcessID = GetCurrentProcessId();
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   505
    /* Create a process handle associated with the current process ID */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   506
    ProcessHandle = GetCurrentProcess();
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   507
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   508
    if(ProcessHandle == NULL)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   509
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   510
        /* Process handle is required by other win32 functions */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   511
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   512
    }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   513
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   514
    /* If running an NT system (NT/Win2k/XP, etc...) */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   515
    if(runningNT)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   516
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   517
        if(!doNTInit())
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   518
        {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   519
            /* Error initializing NT stuff */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   520
            return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   521
        }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   522
    }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   523
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   524
    /* It's all good */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   525
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   526
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   527
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   528
/*
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   529
 * Uninitialize any NT specific stuff done in doNTInit().
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   530
 *
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   531
 * Return zero if there was a catastrophic failure and non-zero otherwise.
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   532
 */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   533
static int doNTDeinit()
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   534
{
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   535
    if(CloseHandle(AccessTokenHandle) != S_OK)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   536
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   537
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   538
    }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   539
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   540
    free(ProfileDirectory);
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   541
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   542
    /* It's all good */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   543
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   544
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   545
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   546
int __PHYSFS_platformDeinit(void)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   547
{
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   548
    if(!doNTDeinit())
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   549
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   550
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   551
    if(CloseHandle(ProcessHandle) != S_OK)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   552
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   553
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   554
    /* It's all good */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   555
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   556
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   557
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   558
void *__PHYSFS_platformOpenRead(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   559
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   560
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   561
    
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   562
    /* Open an existing file for read only. File can be opened by others
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   563
       who request read access on the file only. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   564
    FileHandle = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, 
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   565
        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   566
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   567
    /* If CreateFile() failed */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   568
    if(FileHandle == INVALID_HANDLE_VALUE)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   569
        return NULL;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   570
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   571
    return (void *)FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   572
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   573
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   574
void *__PHYSFS_platformOpenWrite(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   575
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   576
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   577
    
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   578
    /* Open an existing file for write only.  File can be opened by others
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   579
       who request read access to the file only */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   580
    FileHandle = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, 
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   581
        CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   582
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   583
    /* If CreateFile() failed */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   584
    if(FileHandle == INVALID_HANDLE_VALUE)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   585
        return NULL;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   586
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   587
    return (void *)FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   588
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   589
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   590
void *__PHYSFS_platformOpenAppend(const char *filename)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   591
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   592
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   593
    
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   594
    /* Open an existing file for appending only.  File can be opened by others
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   595
       who request read access to the file only. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   596
    FileHandle = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, 
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   597
        TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   598
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   599
    /* If CreateFile() failed */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   600
    if(FileHandle == INVALID_HANDLE_VALUE)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   601
        /* CreateFile might have failed because the file doesn't exist, so
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   602
           we'll just create a new file for writing then */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   603
        return __PHYSFS_platformOpenWrite(filename);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   604
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   605
    return (void *)FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   606
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   607
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   608
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   609
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   610
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   611
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   612
    DWORD CountOfBytesRead;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   613
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   614
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   615
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   616
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   617
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   618
    /* Read data from the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   619
    /*!!! - uint32 might be a greater # than DWORD */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   620
    if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   621
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   622
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   623
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   624
        /* We errored out */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   625
        retval = -1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   626
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   627
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   628
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   629
        /* Return the number of "objects" read. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   630
        /* !!! - What if not the right amount of bytes was read to make an object? */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   631
        retval = CountOfBytesRead / size;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   632
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   633
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   634
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   635
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   636
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   637
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, void *buffer,
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   638
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   639
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   640
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   641
    DWORD CountOfBytesWritten;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   642
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   643
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   644
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   645
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   646
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   647
    /* Read data from the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   648
    /*!!! - uint32 might be a greater # than DWORD */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   649
    if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten, NULL))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   650
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   651
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   652
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   653
        /* We errored out */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   654
        retval = -1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   655
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   656
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   657
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   658
        /* Return the number of "objects" read. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   659
        /*!!! - What if not the right number of bytes was written? */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   660
        retval = CountOfBytesWritten / size;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   661
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   662
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   663
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   664
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   665
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   666
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   667
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   668
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   669
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   670
    DWORD HighOrderPos;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   671
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   672
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   673
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   674
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   675
    /* Get the high order 32-bits of the position */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   676
    HighOrderPos = HIGHORDER_UINT64(pos);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   677
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   678
    /*!!! SetFilePointer needs a signed 64-bit value. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   679
    /* Move pointer "pos" count from start of file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   680
    if((SetFilePointer(FileHandle, LOWORDER_UINT64(pos), &HighOrderPos, FILE_BEGIN)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   681
        == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   682
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   683
        /* An error occured.  Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   684
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   685
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   686
        retval = 0;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   687
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   688
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   689
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   690
        /* No error occured */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   691
        retval = 1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   692
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   693
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   694
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   695
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   696
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   697
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   698
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   699
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   700
    DWORD HighOrderPos = 0; 
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   701
    DWORD LowOrderPos;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   702
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   703
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   704
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   705
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   706
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   707
    /* Get current position */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   708
    if(((LowOrderPos = SetFilePointer(FileHandle, 0, &HighOrderPos, FILE_CURRENT))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   709
        == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   710
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   711
        /* Combine the high/low order to create the 64-bit position value */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   712
        retval = HighOrderPos;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   713
        retval = retval << 32;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   714
        retval |= LowOrderPos;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   715
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   716
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   717
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   718
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   719
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   720
        /* We errored out */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   721
        retval = 0;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   722
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   723
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   724
    /*!!! Can't find a file pointer routine?!?!?!!?!?*/
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   725
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   726
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   727
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   728
PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   729
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   730
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   731
    DWORD FileSizeHigh;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   732
    DWORD FileSizeLow;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   733
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   734
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   735
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   736
    FileHandle = (HANDLE)handle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   737
    
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   738
    if(((FileSizeLow = GetFileSize(FileHandle, &FileSizeHigh))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   739
        == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   740
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   741
        /* Combine the high/low order to create the 64-bit position value */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   742
        retval = FileSizeHigh;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   743
        retval = retval << 32;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   744
        retval |= FileSizeLow;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   745
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   746
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   747
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   748
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   749
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   750
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   751
        retval = -1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   752
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   753
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   754
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   755
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   756
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   757
int __PHYSFS_platformEOF(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   758
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   759
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   760
    PHYSFS_sint64 FilePosition;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   761
    int retval = 0;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   762
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   763
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   764
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   765
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   766
    /* Get the current position in the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   767
    if((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   768
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   769
        /* Non-zero if EOF is equal to the file length - 1 */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   770
        retval = FilePosition == __PHYSFS_platformFileLength(opaque) - 1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   771
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   772
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   773
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   774
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   775
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   776
int __PHYSFS_platformFlush(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   777
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   778
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   779
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   780
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   781
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   782
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   783
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   784
    /* Close the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   785
    if(!(retval = FlushFileBuffers(FileHandle)))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   786
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   787
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   788
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   789
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   790
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   791
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   792
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   793
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   794
int __PHYSFS_platformClose(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   795
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   796
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   797
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   798
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   799
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   800
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   801
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   802
    /* Close the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   803
    if(!(retval = CloseHandle(FileHandle)))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   804
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   805
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   806
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   807
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   808
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   809
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   810
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   811
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   812
/*
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   813
 * Remove a file or directory entry in the actual filesystem. (path) is
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   814
 *  specified in platform-dependent notation. Note that this deletes files
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   815
 *  _and_ directories, so you might need to do some determination.
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   816
 *  Non-empty directories should report an error and not delete themselves
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   817
 *  or their contents.
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   818
 *
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   819
 * Deleting a symlink should remove the link, not what it points to.
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   820
 *
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   821
 * On error, return zero and set the error message. Return non-zero on success.
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   822
 */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   823
int __PHYSFS_platformDelete(const char *path)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   824
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   825
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   826
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   827
    /* If filename is a folder */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   828
    if(GetFileAttributes(path) == FILE_ATTRIBUTE_DIRECTORY)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   829
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   830
        retval = RemoveDirectory(path);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   831
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   832
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   833
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   834
        retval = DeleteFile(path);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   835
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   836
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   837
    if(!retval)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   838
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   839
            /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   840
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   841
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   842
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   843
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   844
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   845
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   846
void *__PHYSFS_platformCreateMutex(void)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   847
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   848
    return (void *)CreateMutex(NULL, FALSE, NULL);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   849
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   850
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   851
void __PHYSFS_platformDestroyMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   852
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   853
    CloseHandle((HANDLE)mutex);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   854
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   855
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   856
int __PHYSFS_platformGrabMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   857
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   858
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   859
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   860
    if(WaitForSingleObject((HANDLE)mutex, INFINITE) == WAIT_FAILED)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   861
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   862
        /* Our wait failed for some unknown reason */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   863
        retval = 1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   864
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   865
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   866
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   867
        /* Good to go */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   868
        retval = 0;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   869
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   870
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   871
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   872
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   873
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   874
void __PHYSFS_platformReleaseMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   875
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   876
    ReleaseMutex((HANDLE)mutex);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   877
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   878
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   879
/* end of win32.c ... */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   880