platform/os2.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 06 Sep 2005 06:24:42 +0000
changeset 747 3da194b12f43
parent 717 ae8bc9888553
child 754 e7cd7411eadf
permissions -rw-r--r--
Don't use size_t in physfs.h, since it relies on C runtime headers.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * OS/2 support routines for PhysicsFS.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE in the source's root directory.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#if HAVE_CONFIG_H
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#  include <config.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#endif
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#if (defined OS2)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#define INCL_DOSSEMAPHORES
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#define INCL_DOSDATETIME
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#define INCL_DOSFILEMGR
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#define INCL_DOSMODULEMGR
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#define INCL_DOSERRORS
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    20
#define INCL_DOSPROCESS
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#define INCL_DOSDEVICES
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    22
#define INCL_DOSDEVIOCTL
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    23
#define INCL_DOSMISC
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
#include <os2.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
599
44af228dd59a Patched to compile on OS/2.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    26
#include <stdio.h>
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#include <stdlib.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#include <errno.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
#include <string.h>
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    30
#include <time.h>
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    31
#include <ctype.h>
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    32
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    33
#define __PHYSICSFS_INTERNAL__
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    34
#include "physfs_internal.h"
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    35
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    36
const char *__PHYSFS_platformDirSeparator = "\\";
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    39
static const char *get_os2_error_string(APIRET rc)
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
{
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    41
    switch (rc)
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    {
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    43
        case NO_ERROR: return(NULL);  /* not an error. */
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    44
        case ERROR_INTERRUPT: return(NULL);  /* not an error. */
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    45
        case ERROR_TIMEOUT: return(NULL);  /* not an error. */
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    46
        case ERROR_NOT_ENOUGH_MEMORY: return(ERR_OUT_OF_MEMORY);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    47
        case ERROR_FILE_NOT_FOUND: return(ERR_NO_SUCH_FILE);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    48
        case ERROR_PATH_NOT_FOUND: return(ERR_NO_SUCH_PATH);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    49
        case ERROR_ACCESS_DENIED: return(ERR_ACCESS_DENIED);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    50
        case ERROR_NOT_DOS_DISK: return(ERR_NOT_A_DOS_DISK);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    51
        case ERROR_SHARING_VIOLATION: return(ERR_SHARING_VIOLATION);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    52
        case ERROR_CANNOT_MAKE: return(ERR_CANNOT_MAKE);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    53
        case ERROR_DEVICE_IN_USE: return(ERR_DEV_IN_USE);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    54
        case ERROR_OPEN_FAILED: return(ERR_OPEN_FAILED);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    55
        case ERROR_DISK_FULL: return(ERR_DISK_FULL);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    56
        case ERROR_PIPE_BUSY: return(ERR_PIPE_BUSY);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    57
        case ERROR_SHARING_BUFFER_EXCEEDED: return(ERR_SHARING_BUF_EXCEEDED);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    58
        case ERROR_FILENAME_EXCED_RANGE: return(ERR_BAD_FILENAME);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    59
        case ERROR_META_EXPANSION_TOO_LONG: return(ERR_BAD_FILENAME);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    60
        case ERROR_TOO_MANY_HANDLES: return(ERR_TOO_MANY_HANDLES);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    61
        case ERROR_TOO_MANY_OPEN_FILES: return(ERR_TOO_MANY_HANDLES);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    62
        case ERROR_NO_MORE_SEARCH_HANDLES: return(ERR_TOO_MANY_HANDLES);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    63
        case ERROR_SEEK_ON_DEVICE: return(ERR_SEEK_ERROR);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    64
        case ERROR_NEGATIVE_SEEK: return(ERR_SEEK_OUT_OF_RANGE);
599
44af228dd59a Patched to compile on OS/2.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    65
        /*!!! FIXME: Where did this go?  case ERROR_DEL_CURRENT_DIRECTORY: return(ERR_DEL_CWD);*/
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    66
        case ERROR_WRITE_PROTECT: return(ERR_WRITE_PROTECT_ERROR);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    67
        case ERROR_WRITE_FAULT: return(ERR_WRITE_FAULT);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    68
        case ERROR_LOCK_VIOLATION: return(ERR_LOCK_VIOLATION);
599
44af228dd59a Patched to compile on OS/2.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
    69
        case ERROR_GEN_FAILURE: return(ERR_GEN_FAILURE);
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    70
        case ERROR_UNCERTAIN_MEDIA: return(ERR_UNCERTAIN_MEDIA);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    71
        case ERROR_PROTECTION_VIOLATION: return(ERR_PROT_VIOLATION);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    72
        case ERROR_BROKEN_PIPE: return(ERR_BROKEN_PIPE);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
        case ERROR_INVALID_PARAMETER:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
        case ERROR_INVALID_NAME:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
        case ERROR_INVALID_DRIVE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
        case ERROR_INVALID_HANDLE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
        case ERROR_INVALID_FUNCTION:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
        case ERROR_INVALID_LEVEL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
        case ERROR_INVALID_CATEGORY:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
        case ERROR_DUPLICATE_NAME:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
        case ERROR_BUFFER_OVERFLOW:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
        case ERROR_BAD_LENGTH:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
        case ERROR_BAD_DRIVER_LEVEL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
        case ERROR_DIRECT_ACCESS_HANDLE:
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    86
        case ERROR_NOT_OWNER:
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    87
            return(ERR_PHYSFS_BAD_OS_CALL);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    89
        default: return(ERR_OS2_GENERIC);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    90
    } /* switch */
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    92
    return(NULL);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    93
} /* get_os2_error_string */
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    96
static APIRET os2err(APIRET retval)
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    97
{
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    98
    char buf[128];
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
    99
    const char *err = get_os2_error_string(retval);
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
   100
    if (err == ERR_OS2_GENERIC)
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
   101
    {
599
44af228dd59a Patched to compile on OS/2.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   102
        snprintf(buf, sizeof (buf), ERR_OS2_GENERIC, (int) retval);
427
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
   103
        err = buf;
c38ace41039f Natural language #defines and build system support.
Ryan C. Gordon <icculus@icculus.org>
parents: 423
diff changeset
   104
    } /* if */
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
    if (err != NULL)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
        __PHYSFS_setError(err);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
599
44af228dd59a Patched to compile on OS/2.
Ryan C. Gordon <icculus@icculus.org>
parents: 596
diff changeset
   109
    return(retval);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
} /* os2err */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
420
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   113
/* (be gentle, this function isn't very robust.) */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   114
static void cvt_path_to_correct_case(char *buf)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   115
{
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   116
    char *fname = buf + 3;            /* point to first element. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   117
    char *ptr = strchr(fname, '\\');  /* find end of first element. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   118
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   119
    buf[0] = toupper(buf[0]);  /* capitalize drive letter. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   120
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   121
    /*
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   122
     * Go through each path element, and enumerate its parent dir until
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   123
     *  a case-insensitive match is found. If one is (and it SHOULD be)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   124
     *  then overwrite the original element with the correct case.
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   125
     * If there's an error, or the path has vanished for some reason, it
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   126
     *  won't hurt to have the original case, so we just keep going.
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   127
     */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   128
    while (fname != NULL)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   129
    {
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   130
        char spec[CCHMAXPATH];
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   131
        FILEFINDBUF3 fb;
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   132
        HDIR hdir = HDIR_CREATE;
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   133
        ULONG count = 1;
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   134
        APIRET rc;
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   135
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   136
        *(fname - 1) = '\0';  /* isolate parent dir string. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   137
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   138
        strcpy(spec, buf);      /* copy isolated parent dir... */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   139
        strcat(spec, "\\*.*");  /*  ...and add wildcard search spec. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   140
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   141
        if (ptr != NULL)  /* isolate element to find (fname is the start). */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   142
            *ptr = '\0';
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   143
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   144
        rc = DosFindFirst(spec, &hdir, FILE_DIRECTORY,
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   145
                          &fb, sizeof (fb), &count, FIL_STANDARD);
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   146
        if (rc == NO_ERROR)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   147
        {
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   148
            while (count == 1)  /* while still entries to enumerate... */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   149
            {
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   150
                if (__PHYSFS_platformStricmp(fb.achName, fname) == 0)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   151
                {
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   152
                    strcpy(fname, fb.achName);
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   153
                    break;  /* there it is. Overwrite and stop searching. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   154
                } /* if */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   155
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   156
                DosFindNext(hdir, &fb, sizeof (fb), &count);
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   157
            } /* while */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   158
            DosFindClose(hdir);
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   159
        } /* if */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   160
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   161
        *(fname - 1) = '\\';   /* unisolate parent dir. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   162
        fname = ptr;           /* point to next element. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   163
        if (ptr != NULL)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   164
        {
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   165
            *ptr = '\\';       /* unisolate element. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   166
            ptr = strchr(++fname, '\\');  /* find next element. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   167
        } /* if */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   168
    } /* while */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   169
} /* cvt_file_to_correct_case */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   170
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   171
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
static char *baseDir = NULL;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
int __PHYSFS_platformInit(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    char buf[CCHMAXPATH];
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    APIRET rc;
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   178
    PTIB ptib;
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   179
    PPIB ppib;
411
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   180
    PHYSFS_sint32 len;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
    assert(baseDir == NULL);
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   183
    BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, NULL, 0);
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   184
    rc = DosQueryModuleName(ppib->pib_hmte, sizeof (buf), (PCHAR) buf);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
411
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   187
    /* chop off filename, leave path. */
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   188
    for (len = strlen(buf) - 1; len >= 0; len--)
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   189
    {
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   190
        if (buf[len] == '\\')
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   191
        {
412
f743cf88c61f Minor patch.
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   192
            buf[len] = '\0';
411
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   193
            break;
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   194
        } /* if */
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   195
    } /* for */
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   196
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   197
    assert(len > 0);  /* should have been a "x:\\" on the front on string. */
411
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   198
420
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   199
    /* The string is capitalized! Figure out the REAL case... */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   200
    cvt_path_to_correct_case(buf);
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   201
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   202
    baseDir = (char *) allocator.Malloc(len + 1);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
    BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   204
    strcpy(baseDir, buf);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
    return(1);  /* success. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
} /* __PHYSFS_platformInit */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
int __PHYSFS_platformDeinit(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
    assert(baseDir != NULL);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   212
    allocator.Free(baseDir);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
    baseDir = NULL;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
    return(1);  /* success. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
} /* __PHYSFS_platformDeinit */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
static int disc_is_inserted(ULONG drive)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
    int rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
    char buf[20];
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
    DosError(FERR_DISABLEHARDERR | FERR_DISABLEEXCEPTION);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
    rc = DosQueryFSInfo(drive + 1, FSIL_VOLSER, buf, sizeof (buf));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    return(rc == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
} /* is_cdrom_inserted */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   229
/* looks like "CD01" in ASCII (littleendian)...used for an ioctl. */
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   230
#define CD01 0x31304443
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   231
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
static int is_cdrom_drive(ULONG drive)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
{
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   234
    PHYSFS_uint32 param, data;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
    ULONG ul1, ul2;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    APIRET rc;
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   237
    HFILE hfile = NULLHANDLE;
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   238
    char drivename[3] = { 'A' + drive, ':', '\0' };
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   240
    rc = DosOpen(drivename, &hfile, &ul1, 0, 0,
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   241
                 OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   242
                 OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR |
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   243
                 OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE, NULL);
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   244
    BAIL_IF_MACRO(rc != NO_ERROR, NULL, 0);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   246
    data = 0;
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   247
    param = PHYSFS_swapULE32(CD01);
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   248
    ul1 = ul2 = sizeof (PHYSFS_uint32);
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   249
    rc = DosDevIOCtl(hfile, IOCTL_CDROMDISK, CDROMDISK_GETDRIVER,
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   250
                     &param, sizeof (param), &ul1, &data, sizeof (data), &ul2);
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   251
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   252
    DosClose(hfile);
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   253
    return((rc == NO_ERROR) && (PHYSFS_swapULE32(data) == CD01));
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
} /* is_cdrom_drive */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   257
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
{
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   259
    ULONG dummy = 0;
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   260
    ULONG drivemap = 0;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
    ULONG i, bit;
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   262
    APIRET rc = DosQueryCurrentDisk(&dummy, &drivemap);
714
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   263
    if (os2err(rc) != NO_ERROR)
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   264
        return;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   266
    for (i = 0, bit = 1; i < 26; i++, bit <<= 1)
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
        if (drivemap & bit)  /* this logical drive exists. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
        {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
            if ((is_cdrom_drive(i)) && (disc_is_inserted(i)))
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
            {
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   272
                char drive[4] = "x:\\";
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   273
                drive[0] = ('A' + i);
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   274
                cb(data, drive);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
            } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
    } /* for */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
} /* __PHYSFS_platformDetectAvailableCDs */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
{
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   283
    char *retval = (char *) allocator.Malloc(strlen(baseDir) + 1);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
    strcpy(retval, baseDir); /* calculated at init time. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
} /* __PHYSFS_platformCalcBaseDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
char *__PHYSFS_platformGetUserName(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
    return(NULL);  /* (*shrug*) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
} /* __PHYSFS_platformGetUserName */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
char *__PHYSFS_platformGetUserDir(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
    return(__PHYSFS_platformCalcBaseDir(NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
} /* __PHYSFS_platformGetUserDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
int __PHYSFS_platformStricmp(const char *x, const char *y)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
    int ux, uy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
    do
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
        ux = toupper((int) *x);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
        uy = toupper((int) *y);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
        if (ux > uy)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
            return(1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
        else if (ux < uy)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
            return(-1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
        x++;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
        y++;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
    } while ((ux) && (uy));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
    return(0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
} /* __PHYSFS_platformStricmp */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
596
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   322
int __PHYSFS_platformStrnicmp(const char *x, const char *y, PHYSFS_uint32 len)
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   323
{
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   324
    int ux, uy;
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   325
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   326
    if (!len)
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   327
        return(0);
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   328
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   329
    do
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   330
    {
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   331
        ux = toupper((int) *x);
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   332
        uy = toupper((int) *y);
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   333
        if (ux > uy)
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   334
            return(1);
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   335
        else if (ux < uy)
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   336
            return(-1);
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   337
        x++;
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   338
        y++;
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   339
        len--;
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   340
    } while ((ux) && (uy) && (len));
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   341
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   342
    return(0);
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   343
} /* __PHYSFS_platformStrnicmp */
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   344
381b6ca0dd85 Added internal function __PHYSFS_platformStrnicmp().
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   345
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
int __PHYSFS_platformExists(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
    APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
    return(os2err(rc) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
} /* __PHYSFS_platformExists */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
int __PHYSFS_platformIsSymLink(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
    return(0);  /* no symlinks in OS/2. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
} /* __PHYSFS_platformIsSymlink */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
int __PHYSFS_platformIsDirectory(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
    APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
    return((fs.attrFile & FILE_DIRECTORY) != 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
} /* __PHYSFS_platformIsDirectory */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   369
/* !!! FIXME: can we lose the malloc here? */
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
char *__PHYSFS_platformCvtToDependent(const char *prepend,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
                                      const char *dirName,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
                                      const char *append)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
    int len = ((prepend) ? strlen(prepend) : 0) +
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
              ((append) ? strlen(append) : 0) +
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
              strlen(dirName) + 1;
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   377
    char *retval = allocator.Malloc(len);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
    char *p;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
    if (prepend)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
        strcpy(retval, prepend);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
    else
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
        retval[0] = '\0';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
    strcat(retval, dirName);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
    if (append)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
        strcat(retval, append);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
        *p = '\\';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
} /* __PHYSFS_platformCvtToDependent */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   399
void __PHYSFS_platformEnumerateFiles(const char *dirname,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   400
                                     int omitSymLinks,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   401
                                     PHYSFS_StringCallback callback,
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   402
                                     void *callbackdata)
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
    char spec[CCHMAXPATH];
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   405
    FILEFINDBUF3 fb;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
    HDIR hdir = HDIR_CREATE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
    ULONG count = 1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
    APIRET rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
714
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   410
    if (strlen(dirname) > sizeof (spec) - 5)
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   411
    {
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   412
        __PHYSFS_setError(ERR_BAD_FILENAME);
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   413
        return;
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   414
    } /* if */
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   415
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   416
    strcpy(spec, dirname);
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   417
    strcat(spec, (spec[strlen(spec) - 1] != '\\') ? "\\*.*" : "*.*");
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
    rc = DosFindFirst(spec, &hdir,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
                      FILE_DIRECTORY | FILE_ARCHIVED |
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
                      FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM,
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   422
                      &fb, sizeof (fb), &count, FIL_STANDARD);
714
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   423
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   424
    if (os2err(rc) != NO_ERROR)
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   425
        return;
03c2e2ee0905 Patched to compile on OS/2 again.
Ryan C. Gordon <icculus@icculus.org>
parents: 691
diff changeset
   426
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
    while (count == 1)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
    {
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   429
        if ((strcmp(fb.achName, ".") != 0) && (strcmp(fb.achName, "..") != 0))
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 599
diff changeset
   430
            callback(callbackdata, fb.achName);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
        DosFindNext(hdir, &fb, sizeof (fb), &count);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
    } /* while */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
    DosFindClose(hdir);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
} /* __PHYSFS_platformEnumerateFiles */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
char *__PHYSFS_platformCurrentDir(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
    char *retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
    ULONG currentDisk;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
    ULONG dummy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
    ULONG pathSize = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
    APIRET rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
    BYTE byte;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
    rc = DosQueryCurrentDisk(&currentDisk, &dummy);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
    /* The first call just tells us how much space we need for the string. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
    rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
    pathSize++; /* Add space for null terminator. */
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   454
    retval = (char *) allocator.Malloc(pathSize + 3);  /* plus "x:\\" */
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
    /* Actually get the string this time. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
    rc = DosQueryCurrentDir(currentDisk, (PBYTE) (retval + 3), &pathSize);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
    if (os2err(rc) != NO_ERROR)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
    {
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   461
        allocator.Free(retval);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
        return(NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
    } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
    retval[0] = ('A' + (currentDisk - 1));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
    retval[1] = ':';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
    retval[2] = '\\';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
} /* __PHYSFS_platformCurrentDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
char *__PHYSFS_platformRealPath(const char *path)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
    char buf[CCHMAXPATH];
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
    char *retval;
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   476
    APIRET rc = DosQueryPathInfo(path, FIL_QUERYFULLNAME, buf, sizeof (buf));
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
691
71d9affe0d8a All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   478
    retval = (char *) allocator.Malloc(strlen(buf) + 1);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
    strcpy(retval, buf);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
} /* __PHYSFS_platformRealPath */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
int __PHYSFS_platformMkDir(const char *path)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
    return(os2err(DosCreateDir(path, NULL)) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
} /* __PHYSFS_platformMkDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
void *__PHYSFS_platformOpenRead(const char *filename)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
    ULONG actionTaken = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
    HFILE hfile = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
     * File must be opened SHARE_DENYWRITE and ACCESS_READONLY, otherwise
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
    os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
                   OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
                   OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   503
                   OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
                   OPEN_ACCESS_READONLY, NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
    return((void *) hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
} /* __PHYSFS_platformOpenRead */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
void *__PHYSFS_platformOpenWrite(const char *filename)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
    ULONG actionTaken = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
    HFILE hfile = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
     * File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
    os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
                   OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
                   OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   522
                   OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
                   OPEN_ACCESS_READWRITE, NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
    return((void *) hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
} /* __PHYSFS_platformOpenWrite */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
void *__PHYSFS_platformOpenAppend(const char *filename)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
    ULONG dummy = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
    HFILE hfile = NULLHANDLE;
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   533
    APIRET rc;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   535
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   536
     * File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   538
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
    rc = os2err(DosOpen(filename, &hfile, &dummy, 0, FILE_NORMAL,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
                   OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
                   OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   542
                   OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
                   OPEN_ACCESS_READWRITE, NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
    if (rc == NO_ERROR)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
        if (os2err(DosSetFilePtr(hfile, 0, FILE_END, &dummy)) != NO_ERROR)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
        {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
            DosClose(hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
            hfile = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
    } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
    return((void *) hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
} /* __PHYSFS_platformOpenAppend */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
    PHYSFS_sint64 retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
    ULONG br;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
    for (retval = 0; retval < count; retval++)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
    {
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   567
        os2err(DosRead(hfile, buffer, size, &br));
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
        if (br < size)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
        {
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   570
            DosSetFilePtr(hfile, -br, FILE_CURRENT, &br); /* try to cleanup. */
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
            return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   574
        buffer = (void *) ( ((char *) buffer) + size );
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
    } /* for */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   578
} /* __PHYSFS_platformRead */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   583
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
    PHYSFS_sint64 retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
    ULONG bw;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   587
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
    for (retval = 0; retval < count; retval++)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   589
    {
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   590
        os2err(DosWrite(hfile, buffer, size, &bw));
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
        if (bw < size)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
        {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
            DosSetFilePtr(hfile, -bw, FILE_CURRENT, &bw); /* try to cleanup. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
            return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   597
        buffer = (void *) ( ((char *) buffer) + size );
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   598
    } /* for */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   599
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   600
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
} /* __PHYSFS_platformWrite */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   602
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   605
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   606
    ULONG dummy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
    LONG dist = (LONG) pos;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
    /* hooray for 32-bit filesystem limits!  :) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
    BAIL_IF_MACRO((PHYSFS_uint64) dist != pos, ERR_SEEK_OUT_OF_RANGE, 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
    return(os2err(DosSetFilePtr(hfile, dist, FILE_BEGIN, &dummy)) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
} /* __PHYSFS_platformSeek */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   617
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   619
    ULONG pos;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
    APIRET rc = os2err(DosSetFilePtr(hfile, 0, FILE_CURRENT, &pos));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
    BAIL_IF_MACRO(rc != NO_ERROR, NULL, -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   623
    return((PHYSFS_sint64) pos);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   624
} /* __PHYSFS_platformTell */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   629
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   630
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
    APIRET rc = DosQueryFileInfo(hfile, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
    return((PHYSFS_sint64) fs.cbFile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
} /* __PHYSFS_platformFileLength */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   635
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
int __PHYSFS_platformEOF(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
    PHYSFS_sint64 len, pos;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
    len = __PHYSFS_platformFileLength(opaque);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
    BAIL_IF_MACRO(len == -1, NULL, 1);  /* (*shrug*) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
    pos = __PHYSFS_platformTell(opaque);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   644
    BAIL_IF_MACRO(pos == -1, NULL, 1);  /* (*shrug*) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
    return(pos >= len);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
} /* __PHYSFS_platformEOF */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
int __PHYSFS_platformFlush(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
{
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   652
    return(os2err(DosResetBuffer((HFILE) opaque) == NO_ERROR));
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
} /* __PHYSFS_platformFlush */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
int __PHYSFS_platformClose(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
    return(os2err(DosClose((HFILE) opaque) == NO_ERROR));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
} /* __PHYSFS_platformClose */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
int __PHYSFS_platformDelete(const char *path)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   664
    if (__PHYSFS_platformIsDirectory(path))
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   665
        return(os2err(DosDeleteDir(path)) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   666
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   667
    return(os2err(DosDelete(path) == NO_ERROR));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
} /* __PHYSFS_platformDelete */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   669
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   670
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   671
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   672
{
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   673
    PHYSFS_sint64 retval;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   674
    struct tm tm;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   676
    APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   677
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   678
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   679
    /* Convert to a format that mktime() can grok... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   680
    tm.tm_sec = ((PHYSFS_uint32) fs.ftimeLastWrite.twosecs) * 2;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   681
    tm.tm_min = fs.ftimeLastWrite.minutes;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   682
    tm.tm_hour = fs.ftimeLastWrite.hours;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   683
    tm.tm_mday = fs.fdateLastWrite.day;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   684
    tm.tm_mon = fs.fdateLastWrite.month;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   685
    tm.tm_year = ((PHYSFS_uint32) fs.fdateLastWrite.year) + 80;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   686
    tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   687
    tm.tm_yday = -1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   688
    tm.tm_isdst = -1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   689
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   690
    /* Convert to a format PhysicsFS can grok... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   691
    retval = (PHYSFS_sint64) mktime(&tm);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   692
    BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   693
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   694
} /* __PHYSFS_platformGetLastModTime */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   695
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   696
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   697
/* Much like my college days, try to sleep for 10 milliseconds at a time... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   698
void __PHYSFS_platformTimeslice(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   699
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   700
    DosSleep(10);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   701
} /* __PHYSFS_platformTimeslice(void) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   702
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   703
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   704
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   705
{
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   706
    PTIB ptib;
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   707
    PPIB ppib;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   708
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   709
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   710
     * Allegedly, this API never fails, but we'll punt and return a
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   711
     *  default value (zero might as well do) if it does.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   712
     */
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   713
    BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, 0, 0);
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   714
    return((PHYSFS_uint64) ptib->tib_ordinal);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   715
} /* __PHYSFS_platformGetThreadID */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   716
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   717
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   718
void *__PHYSFS_platformCreateMutex(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   719
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   720
    HMTX hmtx = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   721
    os2err(DosCreateMutexSem(NULL, &hmtx, 0, 0));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   722
    return((void *) hmtx);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   723
} /* __PHYSFS_platformCreateMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   724
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   725
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   726
void __PHYSFS_platformDestroyMutex(void *mutex)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   727
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   728
    DosCloseMutexSem((HMTX) mutex);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   729
} /* __PHYSFS_platformDestroyMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   730
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   731
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   732
int __PHYSFS_platformGrabMutex(void *mutex)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   733
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   734
    /* Do _NOT_ call os2err() (which sets the physfs error msg) in here! */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   735
    return(DosRequestMutexSem((HMTX) mutex, SEM_INDEFINITE_WAIT) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   736
} /* __PHYSFS_platformGrabMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   737
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   738
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   739
void __PHYSFS_platformReleaseMutex(void *mutex)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   740
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   741
    DosReleaseMutexSem((HMTX) mutex);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   742
} /* __PHYSFS_platformReleaseMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   743
717
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   744
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   745
int __PHYSFS_platformAllocatorInit(void)
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   746
{
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   747
    return(1);  /* always succeeds. */
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   748
} /* __PHYSFS_platformAllocatorInit */
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   749
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   750
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   751
void __PHYSFS_platformAllocatorDeinit(void)
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   752
{
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   753
    /* no-op */
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   754
} /* __PHYSFS_platformAllocatorInit */
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   755
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   756
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 717
diff changeset
   757
void *__PHYSFS_platformAllocatorMalloc(PHYSFS_uint64 s)
717
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   758
{
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 717
diff changeset
   759
    /* make sure s isn't larger than the address space of the platform... */
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 717
diff changeset
   760
    if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) )
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 717
diff changeset
   761
        BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
717
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   762
    #undef malloc
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 717
diff changeset
   763
    return(malloc((size_t) s));
717
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   764
} /* __PHYSFS_platformMalloc */
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   765
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   766
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 717
diff changeset
   767
void *__PHYSFS_platformAllocatorRealloc(void *ptr, PHYSFS_uint64 s)
717
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   768
{
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 717
diff changeset
   769
    /* make sure s isn't larger than the address space of the platform... */
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 717
diff changeset
   770
    if ( s > (0xFFFFFFFFFFFFFFFF >> (64-(sizeof (size_t) * 8))) )
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 717
diff changeset
   771
        BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
717
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   772
    #undef realloc
747
3da194b12f43 Don't use size_t in physfs.h, since it relies on C runtime headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 717
diff changeset
   773
    return(realloc(ptr, (size_t) s));
717
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   774
} /* __PHYSFS_platformRealloc */
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   775
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   776
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   777
void __PHYSFS_platformAllocatorFree(void *ptr)
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   778
{
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   779
    #undef free
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   780
    free(ptr);
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   781
} /* __PHYSFS_platformAllocatorFree */
ae8bc9888553 More minor OS/2 tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 714
diff changeset
   782
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   783
#endif  /* defined OS2 */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   784
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   785
/* end of os2.c ... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   786