platform/win32.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 29 Aug 2001 14:33:17 +0000
changeset 83 4b0f4bd6ee16
parent 76 d6405544e896
child 87 be2efecec922
permissions -rw-r--r--
Attempts to calculate basedir with GetModuleFileName() first, and made a CygWin fix (_MAX_PATH becomes MAX_PATH).
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>
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <stdio.h>
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
    15
#include <stdlib.h>
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
    16
#include <ctype.h>
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#define __PHYSICSFS_INTERNAL__
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#include "physfs_internal.h"
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
const char *__PHYSFS_platformDirSeparator = "\\";
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
static const char *win32strerror(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    27
    static TCHAR msgbuf[255];
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
    FormatMessage(
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
        FORMAT_MESSAGE_FROM_SYSTEM |
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
        FORMAT_MESSAGE_IGNORE_INSERTS,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
        NULL,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
        GetLastError(),
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    34
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    35
        msgbuf,
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    36
        sizeof (msgbuf) / sizeof (TCHAR),
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
        NULL 
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
    );
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
    40
    return((const char *) msgbuf);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
} /* win32strerror */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
char **__PHYSFS_platformDetectAvailableCDs(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
    char **retval = (char **) malloc(sizeof (char *));
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    int cd_count = 1;  /* We count the NULL entry. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
    char drive_str[4] = "x:\\";
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
    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
    51
    {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
        if (GetDriveType(drive_str) == DRIVE_CDROM)
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
            char **tmp = realloc(retval, sizeof (char *) * cd_count + 1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
            if (tmp)
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
                retval = tmp;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
                retval[cd_count-1] = (char *) malloc(4);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
                if (retval[cd_count-1])
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
                    strcpy(retval[cd_count-1], drive_str);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
                    cd_count++;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
                } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
            } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    } /* for */
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[cd_count - 1] = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
} /* __PHYSFS_detectAvailableCDs */
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
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
    DWORD buflen = 0;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
    char *retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    char *filepart = NULL;
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
    if (strchr(argv0, '\\') != NULL)   /* default behaviour can handle this. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
        return(NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
83
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    82
    retval = (char *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    83
    buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    84
    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
    85
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    86
        /* 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
    87
    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
    88
    {
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    89
        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
    90
        if (ptr != NULL)
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    91
        {
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    92
            *(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
    93
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    94
            /* 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
    95
            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
    96
            if (retval != NULL)
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    97
                return(retval);
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    98
        } /* if */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    99
    } /* if */
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   100
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   101
    /* 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
   102
    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
   103
    retval = (char *) realloc(retval, buflen);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
    BAIL_IF_MACRO(!retval, ERR_OUT_OF_MEMORY, NULL);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   105
    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
   106
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
} /* __PHYSFS_platformCalcBaseDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
char *__PHYSFS_platformGetUserName(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   113
    DWORD bufsize = 0;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
    LPTSTR retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
    if (GetUserName(NULL, &bufsize) == 0)  /* This SHOULD fail. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
    {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
        retval = (LPTSTR) malloc(bufsize);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
        BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
        if (GetUserName(retval, &bufsize) == 0)  /* ?! */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
        {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
            free(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
            retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
        } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
    return((char *) retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
} /* __PHYSFS_platformGetUserName */
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
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   131
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
   132
{
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   133
    const char *envr = getenv(varname);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   134
    char *retval = NULL;
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   135
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   136
    if (envr != NULL)
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   137
    {
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   138
        retval = malloc(strlen(envr) + 1);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   139
        if (retval != NULL)
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   140
            strcpy(retval, envr);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   141
    } /* if */
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   142
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   143
    return(retval);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   144
} /* copyEnvironmentVariable */
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   145
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   146
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
char *__PHYSFS_platformGetUserDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
{
76
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   149
    char *home = copyEnvironmentVariable("HOME");
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   150
    const char *homedrive = getenv("HOMEDRIVE");
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   151
    const char *homepath = getenv("HOMEPATH");
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   152
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   153
    if (home != NULL)
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   154
        return(home);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   155
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   156
    if ((homedrive != NULL) && (homepath != NULL))
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   157
    {
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   158
        char *retval = (char *) malloc(strlen(homedrive)+strlen(homepath)+2);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   159
        if (retval != NULL)
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   160
        {
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   161
            strcpy(retval, homedrive);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   162
            if ((homepath[0] != '\\') &&
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   163
                (homedrive[strlen(homedrive)-1] != '\\'))
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   164
            {
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   165
                strcat(retval, "\\");
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   166
            } /* if */
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   167
            strcat(retval, homepath);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   168
            return(retval);
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   169
        } /* if */
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   170
    } /* if */
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   171
d6405544e896 __PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents: 71
diff changeset
   172
    return(NULL);  /* fall through to default rules. */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
} /* __PHYSFS_platformGetUserDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
int __PHYSFS_platformGetThreadID(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    return((int) GetCurrentThreadId());
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
} /* __PHYSFS_platformGetThreadID */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   182
/* ...make this Cygwin AND Visual C friendly... */
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
int __PHYSFS_platformStricmp(const char *x, const char *y)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   185
    int ux, uy;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   186
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   187
    do
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   188
    {
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   189
        ux = toupper((int) *x);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   190
        uy = toupper((int) *y);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   191
        if (ux > uy)
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   192
            return(1);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   193
        else if (ux < uy)
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   194
            return(-1);
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   195
        x++;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   196
        y++;
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   197
    } while ((ux) && (uy));
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   198
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   199
    return(0);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
} /* __PHYSFS_platformStricmp */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
int __PHYSFS_platformExists(const char *fname)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
    return(GetFileAttributes(fname) != 0xffffffff);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
} /* __PHYSFS_platformExists */
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_platformIsSymLink(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(0);  /* no symlinks on win32. */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
} /* __PHYSFS_platformIsSymlink */
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_platformIsDirectory(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((GetFileAttributes(fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
} /* __PHYSFS_platformIsDirectory */
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
char *__PHYSFS_platformCvtToDependent(const char *prepend,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
                                      const char *dirName,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
                                      const char *append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    int len = ((prepend) ? strlen(prepend) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
              ((append) ? strlen(append) : 0) +
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
              strlen(dirName) + 1;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
    char *retval = malloc(len);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   229
    char *p;
68
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
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    if (prepend)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
        strcpy(retval, prepend);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
    else
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
        retval[0] = '\0';
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
    strcat(retval, dirName);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
    if (append)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
        strcat(retval, append);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
        *p = '\\';
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
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
} /* __PHYSFS_platformCvtToDependent */
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
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
/* 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
   251
void __PHYSFS_platformTimeslice(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
    Sleep(10);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
} /* __PHYSFS_platformTimeslice */
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
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
                                                  int omitSymLinks)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
    LinkedStringList *retval = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
    LinkedStringList *l = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
    LinkedStringList *prev = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
    HANDLE dir;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
    WIN32_FIND_DATA ent;
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
    dir = FindFirstFile(dirname, &ent);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
    BAIL_IF_MACRO(dir == INVALID_HANDLE_VALUE, win32strerror(), NULL);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   269
    for (; FindNextFile(dir, &ent) != 0; )
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
    {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
        if (strcmp(ent.cFileName, ".") == 0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
            continue;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
        if (strcmp(ent.cFileName, "..") == 0)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
            continue;
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
        l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
        if (l == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
            break;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
        l->str = (char *) malloc(strlen(ent.cFileName) + 1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
        if (l->str == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
        {
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
            free(l);
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
        } /* if */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
        strcpy(l->str, ent.cFileName);
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
        if (retval == NULL)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
            retval = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
        else
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
            prev->next = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
        prev = l;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
        l->next = NULL;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
    } /* while */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
    FindClose(dir);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
} /* __PHYSFS_platformEnumerateFiles */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
int __PHYSFS_platformFileLength(FILE *handle)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
{
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
    fpos_t curpos;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
    int retval;
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
    fgetpos(handle, &curpos);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
    fseek(handle, 0, SEEK_END);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
    retval = ftell(handle);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
    fsetpos(handle, &curpos);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
    return(retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
} /* __PHYSFS_platformFileLength */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
char *__PHYSFS_platformCurrentDir(void)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   319
    LPTSTR retval;
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
    DWORD buflen = 0;
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   322
    buflen = GetCurrentDirectory(buflen, NULL);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
    retval = (LPTSTR) malloc(buflen);
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   324
    GetCurrentDirectory(buflen, retval);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
    return((char *) retval);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
} /* __PHYSFS_platformCurrentDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
char *__PHYSFS_platformRealPath(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   331
    /* !!! FIXME: This isn't supported on CygWin! */
83
4b0f4bd6ee16 Attempts to calculate basedir with GetModuleFileName() first, and made a
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
   332
    return(_fullpath(NULL, path, MAX_PATH));
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
} /* __PHYSFS_platformRealPath */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
int __PHYSFS_platformMkDir(const char *path)
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
{
71
105bdb041c03 More win32 updates.
Ryan C. Gordon <icculus@icculus.org>
parents: 68
diff changeset
   338
    DWORD rc = CreateDirectory(path, NULL);
68
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
    BAIL_IF_MACRO(rc == 0, win32strerror(), 0);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
    return(1);
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
} /* __PHYSFS_platformMkDir */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
/* end of win32.c ... */
c9a10b5d5f4f Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344