platform/win32.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 12 Apr 2002 23:48:31 +0000
changeset 195 c9eef6e349a2
parent 194 09c353d30cd4
child 197 b59917ad3bae
permissions -rw-r--r--
Fixed an endline issue.
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
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   145
static char *copyEnvironmentVariable(const char *varname)
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   146
{
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   147
    const char *envr = getenv(varname);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   148
    char *retval = NULL;
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   149
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   150
    if (envr != NULL)
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   151
    {
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   152
        retval = malloc(strlen(envr) + 1);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   153
        if (retval != NULL)
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   154
            strcpy(retval, envr);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   155
    } /* if */
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   156
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   157
    return(retval);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   158
} /* copyEnvironmentVariable */
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   159
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   160
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
char *__PHYSFS_platformGetUserDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
{
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   163
    char *userdir = NULL;
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   164
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   165
    if(runningNT)
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   166
    {
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   167
        userdir = ProfileDirectory;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   168
    }
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   169
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   170
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   171
        /*!!!TODO - Need to return something for Win9x/ME */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   172
    }
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   173
131
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   174
    return userdir;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
} /* __PHYSFS_platformGetUserDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   178
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
{
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   180
    return((PHYSFS_uint64)GetCurrentThreadId());
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
} /* __PHYSFS_platformGetThreadID */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   184
/* ...make this Cygwin AND Visual C friendly... */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
int __PHYSFS_platformStricmp(const char *x, const char *y)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
{
195
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   187
#if (defined _MSC_VER)
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   188
    return(stricmp(x, y));
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   189
#else
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   190
    int ux, uy;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   191
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   192
    do
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   193
    {
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   194
        ux = toupper((int) *x);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   195
        uy = toupper((int) *y);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   196
        if (ux > uy)
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   197
            return(1);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   198
        else if (ux < uy)
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   199
            return(-1);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   200
        x++;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   201
        y++;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   202
    } while ((ux) && (uy));
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   203
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   204
    return(0);
195
c9eef6e349a2 Fixed an endline issue.
Ryan C. Gordon <icculus@icculus.org>
parents: 194
diff changeset
   205
#endif
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
} /* __PHYSFS_platformStricmp */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
int __PHYSFS_platformExists(const char *fname)
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
    return(GetFileAttributes(fname) != 0xffffffff);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
} /* __PHYSFS_platformExists */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
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 __PHYSFS_platformIsSymLink(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
    return(0);  /* no symlinks on win32. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
} /* __PHYSFS_platformIsSymlink */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
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
int __PHYSFS_platformIsDirectory(const char *fname)
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
    return((GetFileAttributes(fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
} /* __PHYSFS_platformIsDirectory */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
char *__PHYSFS_platformCvtToDependent(const char *prepend,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
                                      const char *dirName,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
                                      const char *append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
    int len = ((prepend) ? strlen(prepend) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
              ((append) ? strlen(append) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
              strlen(dirName) + 1;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
    char *retval = malloc(len);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   235
    char *p;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
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
    if (prepend)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
        strcpy(retval, prepend);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
    else
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
        retval[0] = '\0';
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
    strcat(retval, dirName);
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
    if (append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
        strcat(retval, append);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
        *p = '\\';
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
} /* __PHYSFS_platformCvtToDependent */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
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
/* 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
   257
void __PHYSFS_platformTimeslice(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
    Sleep(10);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
} /* __PHYSFS_platformTimeslice */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
                                                  int omitSymLinks)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    LinkedStringList *retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
    LinkedStringList *l = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
    LinkedStringList *prev = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
    HANDLE dir;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
    WIN32_FIND_DATA ent;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
    dir = FindFirstFile(dirname, &ent);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
    BAIL_IF_MACRO(dir == INVALID_HANDLE_VALUE, win32strerror(), NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
119
3ba614e99e70 Minor logic fix.
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   275
    while (FindNextFile(dir, &ent) != 0)
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
    {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
        if (strcmp(ent.cFileName, ".") == 0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
            continue;
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 (strcmp(ent.cFileName, "..") == 0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
            continue;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
        l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
        if (l == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
            break;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
        l->str = (char *) malloc(strlen(ent.cFileName) + 1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
        if (l->str == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
        {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
            free(l);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
            break;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
        } /* if */
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
        strcpy(l->str, ent.cFileName);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
        if (retval == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
            retval = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
        else
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
            prev->next = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
        prev = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
        l->next = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
    } /* while */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    FindClose(dir);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
} /* __PHYSFS_platformEnumerateFiles */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
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
char *__PHYSFS_platformCurrentDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   312
    LPTSTR retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
    DWORD buflen = 0;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   315
    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
   316
    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
   317
    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
   318
    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
   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
    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
   321
        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
   322
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
    return((char *) retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
} /* __PHYSFS_platformCurrentDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   327
/* this could probably use a cleanup. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
char *__PHYSFS_platformRealPath(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
{
87
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   330
    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
   331
    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
   332
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   333
    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
   334
    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
   335
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   336
    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
   337
    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
   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
        /*
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   340
         * 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
   341
         *  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
   342
         */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   343
    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
   344
        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
   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
    else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   347
    {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   348
        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
   349
        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
   350
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   351
            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
   352
            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
   353
        } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   354
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   355
        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
   356
        {
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
             * 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
   359
             *  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
   360
             *  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
   361
             */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   362
            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
   363
                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
   364
            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
   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
                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
   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
                    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
   369
                    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
   370
                } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   371
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   372
                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
   373
                {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   374
                    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
   375
                    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
   376
                    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
   377
                    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
   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
        } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   381
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  /* 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
   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
            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
   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
                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
   387
                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
   388
                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
   389
            } /* if */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   390
            else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   391
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   392
                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
   393
                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
   394
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   395
        } /* else */
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
        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
   398
    } /* else */
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
    /* (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
   401
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   402
    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
   403
    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
   404
    {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   405
            /* 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
   406
        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
   407
            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
   408
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   409
            /* 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
   410
        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
   411
            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
   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
            /* 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
   414
        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
   415
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   416
            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
   417
            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
   418
                prevEntry--;
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   419
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   420
            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
   421
                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
   422
            else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   423
            {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   424
                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
   425
                    *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
   426
                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
   427
                    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
   428
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   429
                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
   430
            } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   431
        } /* 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
   432
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   433
        else
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   434
        {
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   435
            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
   436
        } /* else */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   437
    } /* while */
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   438
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   439
        /* 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
   440
    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
   441
    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
   442
        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
   443
be2efecec922 Rewrote __PHYSFS_platformRealPath() to be Cygwin AND Visual C friendly. I hope.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
   444
    return(retval);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
} /* __PHYSFS_platformRealPath */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
int __PHYSFS_platformMkDir(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   450
    DWORD rc = CreateDirectory(path, NULL);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
    BAIL_IF_MACRO(rc == 0, win32strerror(), 0);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
    return(1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
} /* __PHYSFS_platformMkDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
131
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
 * 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
   457
 *
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   458
 * 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
   459
 */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   460
static int doNTInit()
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   461
{
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   462
    DWORD pathsize = 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   463
    char TempProfileDirectory[1];
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   464
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   465
    /* 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
   466
    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
   467
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   468
        /* 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
   469
        return 0;
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
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   472
    /* 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
   473
    /*!!! 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
   474
    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
   475
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   476
        /* 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
   477
        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
   478
        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
   479
        /* 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
   480
        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
   481
        {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   482
            free(ProfileDirectory);
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   483
            return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   484
        }
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
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   487
    /* Everything initialized okay */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   488
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   489
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   490
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   491
/* 
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   492
 * 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
   493
 *
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   494
 * 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
   495
 */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   496
int getOSInfo(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
    /* Get OS info */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   499
    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
   500
    if(!GetVersionEx(&OSVersionInfo))
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
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   503
    }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   504
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   505
    /* 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
   506
    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
   507
        (OSVersionInfo.dwMajorVersion > 3);
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   508
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   509
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   510
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   511
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   512
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
   513
{
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   514
    if(!getOSInfo())
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   515
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   516
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   517
    }
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
    /* 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
   520
    ProcessID = GetCurrentProcessId();
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   521
    /* 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
   522
    ProcessHandle = GetCurrentProcess();
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
    if(ProcessHandle == NULL)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   525
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   526
        /* 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
   527
        return 0;
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
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   530
    /* 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
   531
    if(runningNT)
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
        if(!doNTInit())
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
            /* 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
   536
            return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   537
        }
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
    /* 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
   541
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   542
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   543
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
 * 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
   546
 *
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   547
 * 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
   548
 */
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   549
static int doNTDeinit()
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(AccessTokenHandle) != S_OK)
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   552
    {
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   553
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   554
    }
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   555
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   556
    free(ProfileDirectory);
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   557
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   558
    /* 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
   559
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   560
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   561
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   562
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
   563
{
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   564
    if(!doNTDeinit())
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   565
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   566
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   567
    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
   568
        return 0;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   569
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   570
    /* 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
   571
    return 1;
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   572
}
69b093825303 -Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents: 127
diff changeset
   573
159
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   574
void *__PHYSFS_platformOpenRead(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 read 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 on the file only. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   580
    FileHandle = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, 
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   581
        OPEN_EXISTING, 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_platformOpenWrite(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 write 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
        CREATE_ALWAYS, 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
        return NULL;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   602
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   603
    return (void *)FileHandle;
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
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   606
void *__PHYSFS_platformOpenAppend(const char *filename)
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
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   609
    
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   610
    /* 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
   611
       who request read access to the file only. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   612
    FileHandle = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, 
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   613
        TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
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
    /* If CreateFile() failed */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   616
    if(FileHandle == INVALID_HANDLE_VALUE)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   617
        /* 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
   618
           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
   619
        return __PHYSFS_platformOpenWrite(filename);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   620
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   621
    return (void *)FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   622
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   623
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   624
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   625
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
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
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   628
    DWORD CountOfBytesRead;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   629
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   630
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   631
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   632
    FileHandle = (HANDLE)opaque;
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
    /* Read data from the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   635
    /*!!! - uint32 might be a greater # than DWORD */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   636
    if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   637
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   638
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   639
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   640
        /* We errored out */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   641
        retval = -1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   642
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   643
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   644
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   645
        /* Return the number of "objects" read. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   646
        /* !!! - 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
   647
        retval = CountOfBytesRead / size;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   648
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   649
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   650
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   651
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   652
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   653
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, void *buffer,
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   654
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
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
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   657
    DWORD CountOfBytesWritten;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   658
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   659
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   660
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   661
    FileHandle = (HANDLE)opaque;
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
    /* Read data from the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   664
    /*!!! - uint32 might be a greater # than DWORD */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   665
    if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten, NULL))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   666
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   667
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   668
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   669
        /* We errored out */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   670
        retval = -1;
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
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   673
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   674
        /* Return the number of "objects" read. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   675
        /*!!! - 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
   676
        retval = CountOfBytesWritten / size;
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
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   679
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   680
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   681
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   682
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   683
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   684
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   685
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   686
    DWORD HighOrderPos;
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
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   689
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   690
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   691
    /* Get the high order 32-bits of the position */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   692
    HighOrderPos = HIGHORDER_UINT64(pos);
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
    /*!!! SetFilePointer needs a signed 64-bit value. */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   695
    /* Move pointer "pos" count from start of file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   696
    if((SetFilePointer(FileHandle, LOWORDER_UINT64(pos), &HighOrderPos, FILE_BEGIN)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   697
        == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
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
        /* An error occured.  Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   700
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   701
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   702
        retval = 0;
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
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   705
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   706
        /* No error occured */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   707
        retval = 1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   708
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   709
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   710
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   711
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   712
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   713
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   714
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   715
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   716
    DWORD HighOrderPos = 0; 
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   717
    DWORD LowOrderPos;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   718
    PHYSFS_sint64 retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   719
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   720
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   721
    FileHandle = (HANDLE)opaque;
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
    /* Get current position */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   724
    if(((LowOrderPos = SetFilePointer(FileHandle, 0, &HighOrderPos, FILE_CURRENT))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   725
        == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
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
        /* 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
   728
        retval = HighOrderPos;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   729
        retval = retval << 32;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   730
        retval |= LowOrderPos;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   731
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   732
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   733
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   734
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   735
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   736
        /* We errored out */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   737
        retval = 0;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   738
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   739
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   740
    /*!!! Can't find a file pointer routine?!?!?!!?!?*/
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   741
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   742
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   743
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   744
PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle)
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
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   747
    DWORD FileSizeHigh;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   748
    DWORD FileSizeLow;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   749
    PHYSFS_sint64 retval;
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
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   752
    FileHandle = (HANDLE)handle;
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
    if(((FileSizeLow = GetFileSize(FileHandle, &FileSizeHigh))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   755
        == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
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
        /* 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
   758
        retval = FileSizeHigh;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   759
        retval = retval << 32;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   760
        retval |= FileSizeLow;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   761
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   762
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   763
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   764
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   765
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   766
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   767
        retval = -1;
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
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   770
    return retval;
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
int __PHYSFS_platformEOF(void *opaque)
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
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   776
    PHYSFS_sint64 FilePosition;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   777
    int retval = 0;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   778
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   779
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   780
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   781
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   782
    /* Get the current position in the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   783
    if((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   784
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   785
        /* 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
   786
        retval = FilePosition == __PHYSFS_platformFileLength(opaque) - 1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   787
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   788
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   789
    return retval;
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
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   792
int __PHYSFS_platformFlush(void *opaque)
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
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   795
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   796
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   797
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   798
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   799
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   800
    /* Close the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   801
    if(!(retval = FlushFileBuffers(FileHandle)))
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   802
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   803
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   804
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   805
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   806
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   807
    return retval;
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
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   810
int __PHYSFS_platformClose(void *opaque)
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
    HANDLE FileHandle;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   813
    int retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   814
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   815
    /* Cast the generic handle to a Win32 handle */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   816
    FileHandle = (HANDLE)opaque;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   817
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   818
    /* Close the file */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   819
    if(!(retval = CloseHandle(FileHandle)))
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
        /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   822
        __PHYSFS_setError(win32strerror());
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   823
    }
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
    return 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
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   828
/*
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   829
 * 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
   830
 *  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
   831
 *  _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
   832
 *  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
   833
 *  or their contents.
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   834
 *
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   835
 * 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
   836
 *
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   837
 * 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
   838
 */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   839
int __PHYSFS_platformDelete(const char *path)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   840
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   841
    int retval;
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
    /* If filename is a folder */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   844
    if(GetFileAttributes(path) == FILE_ATTRIBUTE_DIRECTORY)
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
        retval = RemoveDirectory(path);
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
    else
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
        retval = DeleteFile(path);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   851
    }
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
    if(!retval)
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
            /* Set the error to GetLastError */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   856
        __PHYSFS_setError(win32strerror());
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
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   859
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   860
}
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
void *__PHYSFS_platformCreateMutex(void)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   863
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   864
    return (void *)CreateMutex(NULL, FALSE, NULL);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   865
}
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
void __PHYSFS_platformDestroyMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   868
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   869
    CloseHandle((HANDLE)mutex);
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
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   872
int __PHYSFS_platformGrabMutex(void *mutex)
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
    int retval;
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
    if(WaitForSingleObject((HANDLE)mutex, INFINITE) == WAIT_FAILED)
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
        /* Our wait failed for some unknown reason */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   879
        retval = 1;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   880
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   881
    else
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   882
    {
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   883
        /* Good to go */
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   884
        retval = 0;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   885
    }
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   886
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   887
    return retval;
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   888
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   889
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   890
void __PHYSFS_platformReleaseMutex(void *mutex)
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   891
{
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   892
    ReleaseMutex((HANDLE)mutex);
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   893
}
a893392b1628 -Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents: 131
diff changeset
   894
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   895
/* end of win32.c ... */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   896