src/physfs_platform_os2.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1620 f3459eaad51b
permissions -rw-r--r--
7z: Make error handling a little more robust.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * OS/2 support routines for PhysicsFS.
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#define __PHYSICSFS_INTERNAL__
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include "physfs_platforms.h"
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#ifdef PHYSFS_PLATFORM_OS2
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    14
#define INCL_DOSMODULEMGR
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#define INCL_DOSSEMAPHORES
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#define INCL_DOSDATETIME
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#define INCL_DOSFILEMGR
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#define INCL_DOSMODULEMGR
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#define INCL_DOSERRORS
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
#define INCL_DOSPROCESS
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#define INCL_DOSDEVICES
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#define INCL_DOSDEVIOCTL
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#define INCL_DOSMISC
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
#include <os2.h>
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    25
#include <uconv.h>
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#include <errno.h>
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#include <time.h>
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
#include <ctype.h>
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
#include "physfs_internal.h"
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    33
static HMODULE uconvdll = 0;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    34
static UconvObject uconv = 0;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    35
static int (_System *pUniCreateUconvObject)(UniChar *, UconvObject *) = NULL;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    36
static int (_System *pUniFreeUconvObject)(UconvObject *) = NULL;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    37
static int (_System *pUniUconvToUcs)(UconvObject,void **,size_t *, UniChar**, size_t *, size_t *) = NULL;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
    38
static int (_System *pUniUconvFromUcs)(UconvObject,UniChar **,size_t *,void **,size_t *,size_t *) = NULL;
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
    39
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
static PHYSFS_ErrorCode errcodeFromAPIRET(const APIRET rc)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    switch (rc)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
    {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
        case NO_ERROR: return PHYSFS_ERR_OK;  /* not an error. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
        case ERROR_INTERRUPT: return PHYSFS_ERR_OK;  /* not an error. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
        case ERROR_TIMEOUT: return PHYSFS_ERR_OK;  /* not an error. */
1397
bb23b71e059c Patched platform_os2.c to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1395
diff changeset
    47
        case ERROR_NOT_ENOUGH_MEMORY: return PHYSFS_ERR_OUT_OF_MEMORY;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
        case ERROR_FILE_NOT_FOUND: return PHYSFS_ERR_NOT_FOUND;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
        case ERROR_PATH_NOT_FOUND: return PHYSFS_ERR_NOT_FOUND;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
        case ERROR_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
        case ERROR_NOT_DOS_DISK: return PHYSFS_ERR_NOT_FOUND;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
        case ERROR_SHARING_VIOLATION: return PHYSFS_ERR_PERMISSION;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
        case ERROR_CANNOT_MAKE: return PHYSFS_ERR_IO;  /* maybe this is wrong? */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
        case ERROR_DEVICE_IN_USE: return PHYSFS_ERR_BUSY;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
        case ERROR_OPEN_FAILED: return PHYSFS_ERR_IO;  /* maybe this is wrong? */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
        case ERROR_DISK_FULL: return PHYSFS_ERR_NO_SPACE;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
        case ERROR_PIPE_BUSY: return PHYSFS_ERR_BUSY;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
        case ERROR_SHARING_BUFFER_EXCEEDED: return PHYSFS_ERR_IO;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
        case ERROR_FILENAME_EXCED_RANGE: return PHYSFS_ERR_BAD_FILENAME;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
        case ERROR_META_EXPANSION_TOO_LONG: return PHYSFS_ERR_BAD_FILENAME;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
        case ERROR_TOO_MANY_HANDLES: return PHYSFS_ERR_IO;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
        case ERROR_TOO_MANY_OPEN_FILES: return PHYSFS_ERR_IO;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
        case ERROR_NO_MORE_SEARCH_HANDLES: return PHYSFS_ERR_IO;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
        case ERROR_SEEK_ON_DEVICE: return PHYSFS_ERR_IO;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        case ERROR_NEGATIVE_SEEK: return PHYSFS_ERR_INVALID_ARGUMENT;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
        case ERROR_WRITE_PROTECT: return PHYSFS_ERR_PERMISSION;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        case ERROR_WRITE_FAULT: return PHYSFS_ERR_IO;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
        case ERROR_UNCERTAIN_MEDIA: return PHYSFS_ERR_IO;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
        case ERROR_PROTECTION_VIOLATION: return PHYSFS_ERR_IO;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
        case ERROR_BROKEN_PIPE: return PHYSFS_ERR_IO;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
        /* !!! FIXME: some of these might be PHYSFS_ERR_BAD_FILENAME, etc */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
        case ERROR_LOCK_VIOLATION:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
        case ERROR_GEN_FAILURE:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
        case ERROR_INVALID_PARAMETER:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
        case ERROR_INVALID_NAME:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
        case ERROR_INVALID_DRIVE:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
        case ERROR_INVALID_HANDLE:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
        case ERROR_INVALID_FUNCTION:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
        case ERROR_INVALID_LEVEL:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
        case ERROR_INVALID_CATEGORY:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
        case ERROR_DUPLICATE_NAME:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
        case ERROR_BUFFER_OVERFLOW:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
        case ERROR_BAD_LENGTH:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
        case ERROR_BAD_DRIVER_LEVEL:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
        case ERROR_DIRECT_ACCESS_HANDLE:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
        case ERROR_NOT_OWNER:
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
            return PHYSFS_ERR_OS_ERROR;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
        default: break;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
    } /* switch */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
    return PHYSFS_ERR_OTHER_ERROR;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
} /* errcodeFromAPIRET */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
1406
705cfcd6107e OS/2: actually working again, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 1405
diff changeset
    96
static char *cvtUtf8ToCodepage(const char *utf8str)
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
    97
{
1601
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
    98
    const size_t len = strlen(utf8str) + 1;
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
    99
    const size_t uc2buflen = len * sizeof (UniChar);
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   100
    UniChar *uc2ptr = (UniChar *) __PHYSFS_smallAlloc(uc2buflen);
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   101
    UniChar *uc2str = uc2ptr;
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   102
    char *cpptr = NULL;
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   103
    char *cpstr = NULL;
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   104
    size_t subs = 0;
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   105
    size_t unilen;
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   106
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   107
    BAIL_IF(!uc2str, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   108
    PHYSFS_utf8ToUcs2(utf8str, (PHYSFS_uint16 *) uc2str, uc2buflen);
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   109
    for (unilen = 0; uc2str[unilen]; unilen++) { /* spin */ }
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   110
    unilen++;  /* null terminator. */
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   111
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   112
    if (!uconvdll)
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   113
    {
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   114
        /* There's really not much we can do on older OS/2s except pray this
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   115
           is latin1-compatible. */
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   116
        size_t i;
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   117
        cpptr = (char *) allocator.Malloc(unilen);
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   118
        cpstr = cpptr;
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   119
        GOTO_IF(!cpptr, PHYSFS_ERR_OUT_OF_MEMORY, failed);
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   120
        for (i = 0; i < unilen; i++)
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   121
        {
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   122
            const UniChar ch = uc2str[i];
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   123
            GOTO_IF(ch > 0xFF, PHYSFS_ERR_BAD_FILENAME, failed);
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   124
            cpptr[i] = (char) ((unsigned char) ch);
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   125
        } /* for */
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   126
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   127
        __PHYSFS_smallFree(uc2ptr);
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   128
        return cpstr;
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   129
    } /* if */
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   130
    else
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   131
    {
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   132
        int rc;
1602
3b7e318f978c OS/2: Patched to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1601
diff changeset
   133
        size_t cplen = unilen * 4; /* overallocate, just in case. */
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   134
        cpptr = (char *) allocator.Malloc(cplen);
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   135
        GOTO_IF(!cpptr, PHYSFS_ERR_OUT_OF_MEMORY, failed);
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   136
        cpstr = cpptr;
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   137
1406
705cfcd6107e OS/2: actually working again, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 1405
diff changeset
   138
        rc = pUniUconvFromUcs(uconv, &uc2str, &unilen, (void **) &cpstr, &cplen, &subs);
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   139
        GOTO_IF(rc != ULS_SUCCESS, PHYSFS_ERR_BAD_FILENAME, failed);
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   140
        GOTO_IF(subs > 0, PHYSFS_ERR_BAD_FILENAME, failed);
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   141
        assert(unilen == 0);
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   142
1601
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   143
        __PHYSFS_smallFree(uc2ptr);
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   144
        return cpptr;
1601
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   145
    } /* else */
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   146
1601
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   147
failed:
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   148
    __PHYSFS_smallFree(uc2ptr);
396f0f3d230f OS/2: Deal with UTF-8 -> codepage conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1600
diff changeset
   149
    allocator.Free(cpptr);
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   150
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   151
    return NULL;
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   152
} /* cvtUtf8ToCodepage */
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   153
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   154
static char *cvtCodepageToUtf8(const char *cpstr)
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   155
{
1600
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   156
    const size_t len = strlen(cpstr) + 1;
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   157
    char *retvalbuf = (char *) allocator.Malloc(len * 4);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   158
    char *retval = NULL;
1600
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   159
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   160
    BAIL_IF(!retvalbuf, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   161
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   162
    if (!uconvdll)
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   163
    {
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   164
        /* There's really not much we can do on older OS/2s except pray this
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   165
           is latin1-compatible. */
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   166
        retval = retvalbuf;
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   167
        PHYSFS_utf8FromLatin1(cpstr, retval, len * 4);
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   168
    } /* if */
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   169
    else
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   170
    {
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   171
        int rc;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   172
        size_t cplen = len;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   173
        size_t unilen = len;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   174
        size_t subs = 0;
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   175
        UniChar *uc2ptr = __PHYSFS_smallAlloc(len * sizeof (UniChar));
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   176
        UniChar *uc2str = uc2ptr;
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   177
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   178
        BAIL_IF(!uc2ptr, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   179
        rc = pUniUconvToUcs(uconv, (void **) &cpstr, &cplen, &uc2str, &unilen, &subs);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   180
        GOTO_IF(rc != ULS_SUCCESS, PHYSFS_ERR_BAD_FILENAME, done);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   181
        GOTO_IF(subs > 0, PHYSFS_ERR_BAD_FILENAME, done);
1406
705cfcd6107e OS/2: actually working again, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 1405
diff changeset
   182
        assert(cplen == 0);
1600
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   183
        retval = retvalbuf;
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   184
        PHYSFS_utf8FromUcs2((const PHYSFS_uint16 *) uc2ptr, retval, len * 4);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   185
        done:
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   186
        __PHYSFS_smallFree(uc2ptr);
1600
3d3242c2aa2f OS/2: don't report failures on Unicode conversion on older OS/2 installs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1594
diff changeset
   187
    } /* else */
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   188
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   189
    return retval;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   190
} /* cvtCodepageToUtf8 */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   191
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
/* (be gentle, this function isn't very robust.) */
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   194
static char *cvtPathToCorrectCase(char *buf)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
{
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   196
    char *retval = buf;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    char *fname = buf + 3;            /* point to first element. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
    char *ptr = strchr(fname, '\\');  /* find end of first element. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
    buf[0] = toupper(buf[0]);  /* capitalize drive letter. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
    /*
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
     * Go through each path element, and enumerate its parent dir until
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
     *  a case-insensitive match is found. If one is (and it SHOULD be)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
     *  then overwrite the original element with the correct case.
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
     * If there's an error, or the path has vanished for some reason, it
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
     *  won't hurt to have the original case, so we just keep going.
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
     */
1406
705cfcd6107e OS/2: actually working again, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 1405
diff changeset
   209
    while ((fname != NULL) && (*fname != '\0'))
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
    {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
        char spec[CCHMAXPATH];
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
        FILEFINDBUF3 fb;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
        HDIR hdir = HDIR_CREATE;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
        ULONG count = 1;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
        APIRET rc;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
        *(fname - 1) = '\0';  /* isolate parent dir string. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
        strcpy(spec, buf);      /* copy isolated parent dir... */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
        strcat(spec, "\\*.*");  /*  ...and add wildcard search spec. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
        if (ptr != NULL)  /* isolate element to find (fname is the start). */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
            *ptr = '\0';
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
        rc = DosFindFirst((unsigned char *) spec, &hdir, FILE_DIRECTORY,
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
                          &fb, sizeof (fb), &count, FIL_STANDARD);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
        if (rc == NO_ERROR)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
        {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
            while (count == 1)  /* while still entries to enumerate... */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
            {
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   231
                int cmp;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   232
                char *utf8 = cvtCodepageToUtf8(fb.achName);
1558
f910eacfda41 Removed __PHYSFS_stricmpASCII functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1555
diff changeset
   233
                if (!utf8) /* ugh, maybe we'll get lucky with the C runtime. */
1594
750265d0c779 OS/2: Fixed NULL pointer dereference.
Ryan C. Gordon <icculus@icculus.org>
parents: 1591
diff changeset
   234
                    cmp = stricmp(fb.achName, fname);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   235
                else
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   236
                {
1555
5495a0e50b5e utf8: big improvements to case-insensitive UTF-8 string compare.
Ryan C. Gordon <icculus@icculus.org>
parents: 1544
diff changeset
   237
                    cmp = PHYSFS_utf8stricmp(utf8, fname);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   238
                    allocator.Free(utf8);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   239
                } /* else */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   240
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   241
                if (cmp == 0)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
                {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
                    strcpy(fname, fb.achName);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
                    break;  /* there it is. Overwrite and stop searching. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
                } /* if */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
                DosFindNext(hdir, &fb, sizeof (fb), &count);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
            } /* while */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
            DosFindClose(hdir);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
        } /* if */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
        *(fname - 1) = '\\';   /* unisolate parent dir. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
        fname = ptr;           /* point to next element. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
        if (ptr != NULL)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
        {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
            *ptr = '\\';       /* unisolate element. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
            ptr = strchr(++fname, '\\');  /* find next element. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
        } /* if */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
    } /* while */
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   260
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   261
    return retval;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   262
} /* cvtPathToCorrectCase */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   263
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   264
static void prepUnicodeSupport(void)
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   265
{
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   266
    /* really old OS/2 might not have Unicode support _at all_, so load
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   267
       the system library and do without if it doesn't exist. */
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   268
    int ok = 0;                                                   
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   269
    char buf[CCHMAXPATH];
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   270
    UniChar defstr[] = { 0 };
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   271
    if (DosLoadModule(buf, sizeof (buf) - 1, "uconv", &uconvdll) == NO_ERROR)
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   272
    {
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   273
        #define LOAD(x) (DosQueryProcAddr(uconvdll,0,#x,(PFN*)&p##x)==NO_ERROR)
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   274
        ok = LOAD(UniCreateUconvObject) &&
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   275
             LOAD(UniFreeUconvObject) &&
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   276
             LOAD(UniUconvToUcs) &&
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   277
             LOAD(UniUconvFromUcs);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   278
        #undef LOAD
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   279
    } /* else */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   280
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   281
    if (!ok || (pUniCreateUconvObject(defstr, &uconv) != ULS_SUCCESS))
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   282
    {
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   283
        /* oh well, live without it. */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   284
        if (uconvdll)
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   285
        {
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   286
            if (uconv)
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   287
                pUniFreeUconvObject(uconv);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   288
            DosFreeModule(uconvdll);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   289
            uconvdll = 0;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   290
        } /* if */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   291
    } /* if */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   292
} /* prepUnicodeSupport */
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
int __PHYSFS_platformInit(void)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
{
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   297
    prepUnicodeSupport();
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   298
    return 1;  /* ready to go! */
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
} /* __PHYSFS_platformInit */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
1536
c791c9aaa2a2 __PHYSFS_platformDeinit() should return void.
Ryan C. Gordon <icculus@icculus.org>
parents: 1533
diff changeset
   302
void __PHYSFS_platformDeinit(void)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
{
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   304
    if (uconvdll)
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   305
    {
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   306
        pUniFreeUconvObject(uconv);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   307
        uconv = 0;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   308
        DosFreeModule(uconvdll);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   309
        uconvdll = 0;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   310
    } /* if */
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
} /* __PHYSFS_platformDeinit */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   314
static int discIsInserted(ULONG drive)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
    int rc;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
    char buf[20];
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
    DosError(FERR_DISABLEHARDERR | FERR_DISABLEEXCEPTION);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
    rc = DosQueryFSInfo(drive + 1, FSIL_VOLSER, buf, sizeof (buf));
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
    DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
    return (rc == NO_ERROR);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
} /* is_cdrom_inserted */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
/* looks like "CD01" in ASCII (littleendian)...used for an ioctl. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
#define CD01 0x31304443
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   328
static int isCdRomDrive(ULONG drive)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
    PHYSFS_uint32 param, data;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
    ULONG ul1, ul2;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
    APIRET rc;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
    HFILE hfile = NULLHANDLE;
1397
bb23b71e059c Patched platform_os2.c to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1395
diff changeset
   334
    unsigned char drivename[3] = { 0, ':', '\0' };
1400
dd94c7ca158b Fix some endlines.
Ryan C. Gordon <icculus@icculus.org>
parents: 1399
diff changeset
   335
dd94c7ca158b Fix some endlines.
Ryan C. Gordon <icculus@icculus.org>
parents: 1399
diff changeset
   336
    drivename[0] = 'A' + drive;
dd94c7ca158b Fix some endlines.
Ryan C. Gordon <icculus@icculus.org>
parents: 1399
diff changeset
   337
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
    rc = DosOpen(drivename, &hfile, &ul1, 0, 0,
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
                 OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
                 OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR |
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
                 OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE, NULL);
1400
dd94c7ca158b Fix some endlines.
Ryan C. Gordon <icculus@icculus.org>
parents: 1399
diff changeset
   342
    if (rc != NO_ERROR)
dd94c7ca158b Fix some endlines.
Ryan C. Gordon <icculus@icculus.org>
parents: 1399
diff changeset
   343
        return 0;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
    data = 0;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
    param = PHYSFS_swapULE32(CD01);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
    ul1 = ul2 = sizeof (PHYSFS_uint32);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
    rc = DosDevIOCtl(hfile, IOCTL_CDROMDISK, CDROMDISK_GETDRIVER,
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
                     &param, sizeof (param), &ul1, &data, sizeof (data), &ul2);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
    DosClose(hfile);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
    return ((rc == NO_ERROR) && (PHYSFS_swapULE32(data) == CD01));
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   353
} /* isCdRomDrive */
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
    ULONG dummy = 0;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
    ULONG drivemap = 0;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
    ULONG i, bit;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
    const APIRET rc = DosQueryCurrentDisk(&dummy, &drivemap);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   362
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc),);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
    for (i = 0, bit = 1; i < 26; i++, bit <<= 1)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
    {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
        if (drivemap & bit)  /* this logical drive exists. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
        {
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   368
            if ((isCdRomDrive(i)) && (discIsInserted(i)))
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
            {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
                char drive[4] = "x:\\";
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
                drive[0] = ('A' + i);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
                cb(data, drive);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
            } /* if */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
        } /* if */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
    } /* for */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
} /* __PHYSFS_platformDetectAvailableCDs */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   380
{
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   381
    char *retval = NULL;
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   382
    char buf[CCHMAXPATH];
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   383
    APIRET rc;
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   384
    PTIB ptib;
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   385
    PPIB ppib;
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   386
    PHYSFS_sint32 len;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   388
    rc = DosGetInfoBlocks(&ptib, &ppib);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   389
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), 0);
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   390
    rc = DosQueryModuleName(ppib->pib_hmte, sizeof (buf), (PCHAR) buf);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   391
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), 0);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   392
    retval = cvtCodepageToUtf8(buf);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   393
    BAIL_IF_ERRPASS(!retval, NULL);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   395
    /* chop off filename, leave path. */
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   396
    for (len = strlen(retval) - 1; len >= 0; len--)
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   397
    {
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   398
        if (retval[len] == '\\')
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
        {
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   400
            retval[len + 1] = '\0';
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   401
            break;
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   402
        } /* if */
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   403
    } /* for */
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   405
    assert(len > 0);  /* should have been a "x:\\" on the front on string. */
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   407
    /* The string is capitalized! Figure out the REAL case... */
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   408
    return cvtPathToCorrectCase(retval);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
} /* __PHYSFS_platformCalcBaseDir */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   411
char *__PHYSFS_platformCalcUserDir(void)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
{
1570
3bd8afc43ee3 Reduced some FIXME-3.0 tags to normal FIXME. They can wait.
Ryan C. Gordon <icculus@icculus.org>
parents: 1564
diff changeset
   413
    return __PHYSFS_platformCalcBaseDir(NULL);  /* !!! FIXME: ? */
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   414
} /* __PHYSFS_platformCalcUserDir */
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
1399
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   416
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
293e54f0102f OS/2: fix up the base/user/pref dir code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1397
diff changeset
   417
{
1570
3bd8afc43ee3 Reduced some FIXME-3.0 tags to normal FIXME. They can wait.
Ryan C. Gordon <icculus@icculus.org>
parents: 1564
diff changeset
   418
    return __PHYSFS_platformCalcBaseDir(NULL);  /* !!! FIXME: ? */
1544
7f6020ee746c Marked a bunch of things as "FIXME-3.0" that I want resolved before 3.0 ships.
Ryan C. Gordon <icculus@icculus.org>
parents: 1536
diff changeset
   419
} /* __PHYSFS_platformCalcPrefDir */
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1570
diff changeset
   421
PHYSFS_EnumerateCallbackResult __PHYSFS_platformEnumerate(const char *dirname,
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   422
                               PHYSFS_EnumerateCallback callback,
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   423
                               const char *origdir, void *callbackdata)
1397
bb23b71e059c Patched platform_os2.c to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1395
diff changeset
   424
{                                        
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1570
diff changeset
   425
    PHYSFS_EnumerateCallbackResult retval = PHYSFS_ENUM_OK;
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   426
    size_t utf8len = strlen(dirname);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   427
    char *utf8 = (char *) __PHYSFS_smallAlloc(utf8len + 5);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   428
    char *cpspec = NULL;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
    FILEFINDBUF3 fb;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
    HDIR hdir = HDIR_CREATE;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
    ULONG count = 1;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
    APIRET rc;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1570
diff changeset
   434
    BAIL_IF(!utf8, PHYSFS_ERR_OUT_OF_MEMORY, PHYSFS_ENUM_ERROR);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   436
    strcpy(utf8, dirname);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   437
    if (utf8[utf8len - 1] != '\\')
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   438
        strcpy(utf8 + utf8len, "\\*.*");
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   439
    else
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   440
        strcpy(utf8 + utf8len, "*.*");
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   442
    cpspec = cvtUtf8ToCodepage(utf8);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   443
    __PHYSFS_smallFree(utf8);
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1570
diff changeset
   444
    BAIL_IF_ERRPASS(!cpspec, PHYSFS_ENUM_ERROR);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   445
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   446
    rc = DosFindFirst((unsigned char *) cpspec, &hdir,
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
                      FILE_DIRECTORY | FILE_ARCHIVED |
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
                      FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM,
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
                      &fb, sizeof (fb), &count, FIL_STANDARD);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   450
    allocator.Free(cpspec);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1570
diff changeset
   452
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), PHYSFS_ENUM_ERROR);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
    while (count == 1)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
    {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
        if ((strcmp(fb.achName, ".") != 0) && (strcmp(fb.achName, "..") != 0))
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   457
        {
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   458
            utf8 = cvtCodepageToUtf8(fb.achName);
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   459
            if (!utf8)
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1570
diff changeset
   460
                retval = PHYSFS_ENUM_ERROR;
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   461
            else
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   462
            {
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   463
                retval = callback(callbackdata, origdir, utf8);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   464
                allocator.Free(utf8);
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1570
diff changeset
   465
                if (retval == PHYSFS_ENUM_ERROR)
1564
62c27f6efeed Patched to compile on various platforms and compilers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1559
diff changeset
   466
                    PHYSFS_setErrorCode(PHYSFS_ERR_APP_CALLBACK);
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   467
            } /* else */
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   468
        } /* if */
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   469
1591
97d3641bfba3 Make PHYSFS_EnumerateCallback return an enum instead of an int.
Ryan C. Gordon <icculus@icculus.org>
parents: 1570
diff changeset
   470
        if (retval != PHYSFS_ENUM_OK)
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   471
            break;
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   472
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
        DosFindNext(hdir, &fb, sizeof (fb), &count);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
    } /* while */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
    DosFindClose(hdir);
1559
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   477
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   478
    return retval;
aaee2b83291f Reworked enumeration to be more powerful.
Ryan C. Gordon <icculus@icculus.org>
parents: 1558
diff changeset
   479
} /* __PHYSFS_platformEnumerate */
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
char *__PHYSFS_platformCurrentDir(void)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
    char *retval;
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   485
    char *cpstr;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   486
    char *utf8;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
    ULONG currentDisk;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
    ULONG dummy;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
    ULONG pathSize = 0;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
    APIRET rc;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
    BYTE byte;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
    rc = DosQueryCurrentDisk(&currentDisk, &dummy);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   494
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), NULL);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
    /* The first call just tells us how much space we need for the string. */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
    rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
    pathSize++; /* Add space for null terminator. */
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   499
    cpstr = (char *) __PHYSFS_smallAlloc(pathSize);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   500
    BAIL_IF(cpstr == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
    /* Actually get the string this time. */
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   503
    rc = DosQueryCurrentDir(currentDisk, (PBYTE) cpstr, &pathSize);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
    if (rc != NO_ERROR)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
    {
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   506
        __PHYSFS_smallFree(cpstr);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   507
        BAIL(errcodeFromAPIRET(rc), NULL);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
    } /* if */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   510
    utf8 = cvtCodepageToUtf8(cpstr);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   511
    __PHYSFS_smallFree(cpstr);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   512
    BAIL_IF_ERRPASS(utf8 == NULL, NULL);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   513
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   514
    /* +4 for "x:\\" drive selector and null terminator. */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   515
    retval = (char *) allocator.Malloc(strlen(utf8) + 4);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   516
    if (retval == NULL)
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   517
    {
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   518
        allocator.Free(utf8);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   519
        BAIL(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   520
    } /* if */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   521
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
    retval[0] = ('A' + (currentDisk - 1));
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
    retval[1] = ':';
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
    retval[2] = '\\';
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   525
    strcpy(retval + 3, utf8);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   526
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   527
    allocator.Free(utf8);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   528
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
    return retval;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
} /* __PHYSFS_platformCurrentDir */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   533
int __PHYSFS_platformMkDir(const char *filename)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
{
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   535
    APIRET rc;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   536
    char *cpstr = cvtUtf8ToCodepage(filename);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   537
    BAIL_IF_ERRPASS(!cpstr, 0);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   538
    rc = DosCreateDir((unsigned char *) cpstr, NULL);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   539
    allocator.Free(cpstr);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   540
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), 0);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
    return 1;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
} /* __PHYSFS_platformMkDir */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   545
static HFILE openFile(const char *filename, const ULONG flags, const ULONG mode)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
{
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   547
    char *cpfname = cvtUtf8ToCodepage(filename);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   548
    ULONG action = 0;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
    HFILE hfile = NULLHANDLE;
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   550
    APIRET rc;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   552
    BAIL_IF_ERRPASS(!cpfname, 0);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   553
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   554
    rc = DosOpen(cpfname, &hfile, &action, 0, FILE_NORMAL, flags, mode, NULL);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   555
    allocator.Free(cpfname);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   556
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), 0);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   557
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   558
    return hfile;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   559
} /* openFile */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   560
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   561
void *__PHYSFS_platformOpenRead(const char *filename)
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   562
{
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
    /*
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
     * File must be opened SHARE_DENYWRITE and ACCESS_READONLY, otherwise
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
     */
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   567
    return (void *) openFile(filename,
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   568
                        OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   569
                        OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   570
                        OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   571
                        OPEN_ACCESS_READONLY);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
} /* __PHYSFS_platformOpenRead */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   575
void *__PHYSFS_platformOpenWrite(const char *filename)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
{
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   577
    return (void *) openFile(filename,
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   578
                        OPEN_ACTION_REPLACE_IF_EXISTS |
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   579
                        OPEN_ACTION_CREATE_IF_NEW,
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   580
                        OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   581
                        OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   582
} /* __PHYSFS_platformOpenWrite */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   583
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   584
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   585
void *__PHYSFS_platformOpenAppend(const char *filename)
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   586
{
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   587
    APIRET rc;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   588
    ULONG dummy = 0;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   589
    HFILE hfile;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   590
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
    /*
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
     * File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
     */
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   595
    hfile = openFile(filename,
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   596
                        OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   597
                        OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   598
                        OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   599
                        OPEN_ACCESS_READWRITE);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   600
    BAIL_IF_ERRPASS(!hfile, NULL);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   602
    rc = DosSetFilePtr(hfile, 0, FILE_END, &dummy);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
    if (rc != NO_ERROR)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
    {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   605
        DosClose(hfile);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   606
        BAIL(errcodeFromAPIRET(rc), NULL);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
    } /* if */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
    return ((void *) hfile);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
} /* __PHYSFS_platformOpenAppend */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
    ULONG br = 0;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
    APIRET rc;
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   617
    BAIL_IF(!__PHYSFS_ui64FitsAddressSpace(len),PHYSFS_ERR_INVALID_ARGUMENT,-1);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
    rc = DosRead((HFILE) opaque, buf, (ULONG) len, &br);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   619
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), (br > 0) ? ((PHYSFS_sint64) br) : -1);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
    return (PHYSFS_sint64) br;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
} /* __PHYSFS_platformRead */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   623
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   624
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buf,
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
                                     PHYSFS_uint64 len)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
    ULONG bw = 0;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
    APIRET rc;
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   629
    BAIL_IF(!__PHYSFS_ui64FitsAddressSpace(len),PHYSFS_ERR_INVALID_ARGUMENT,-1);
1397
bb23b71e059c Patched platform_os2.c to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1395
diff changeset
   630
    rc = DosWrite((HFILE) opaque, (void *) buf, (ULONG) len, &bw);    
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   631
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), (bw > 0) ? ((PHYSFS_sint64) bw) : -1);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
    return (PHYSFS_sint64) bw;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
} /* __PHYSFS_platformWrite */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   635
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
    ULONG dummy;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
    HFILE hfile = (HFILE) opaque;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
    LONG dist = (LONG) pos;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
    APIRET rc;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
    /* hooray for 32-bit filesystem limits!  :) */
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   644
    BAIL_IF((PHYSFS_uint64) dist != pos, PHYSFS_ERR_INVALID_ARGUMENT, 0);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
    rc = DosSetFilePtr(hfile, dist, FILE_BEGIN, &dummy);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   646
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), 0);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
    return 1;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
} /* __PHYSFS_platformSeek */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
    ULONG pos;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
    HFILE hfile = (HFILE) opaque;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
    const APIRET rc = DosSetFilePtr(hfile, 0, FILE_CURRENT, &pos);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   656
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), -1);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
    return ((PHYSFS_sint64) pos);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
} /* __PHYSFS_platformTell */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663
    FILESTATUS3 fs;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   664
    HFILE hfile = (HFILE) opaque;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   665
    const APIRET rc = DosQueryFileInfo(hfile, FIL_STANDARD, &fs, sizeof (fs));
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   666
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), -1);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   667
    return ((PHYSFS_sint64) fs.cbFile);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
} /* __PHYSFS_platformFileLength */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   669
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   670
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   671
int __PHYSFS_platformFlush(void *opaque)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   672
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   673
    const APIRET rc = DosResetBuffer((HFILE) opaque);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   674
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), 0);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
    return 1;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   676
} /* __PHYSFS_platformFlush */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   677
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   678
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   679
void __PHYSFS_platformClose(void *opaque)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   680
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   681
    DosClose((HFILE) opaque);  /* ignore errors. You should have flushed! */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   682
} /* __PHYSFS_platformClose */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   683
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   684
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   685
int __PHYSFS_platformDelete(const char *path)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   686
{
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   687
    char *cppath = cvtUtf8ToCodepage(path);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   688
    FILESTATUS3 fs;
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   689
    APIRET rc;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   690
    int retval = 0;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   691
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   692
    BAIL_IF_ERRPASS(!cppath, 0);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   693
    rc = DosQueryPathInfo(cppath, FIL_STANDARD, &fs, sizeof (fs));
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   694
    GOTO_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), done);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   695
    rc = (fs.attrFile & FILE_DIRECTORY) ? DosDeleteDir(path) : DosDelete(path);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   696
    GOTO_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), done);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   697
    retval = 1;  /* success */
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   698
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   699
done:
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   700
    allocator.Free(cppath);
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   701
    return retval;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   702
} /* __PHYSFS_platformDelete */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   703
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   704
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   705
/* Convert to a format PhysicsFS can grok... */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   706
PHYSFS_sint64 os2TimeToUnixTime(const FDATE *date, const FTIME *time)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   707
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   708
    struct tm tm;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   709
1397
bb23b71e059c Patched platform_os2.c to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1395
diff changeset
   710
    tm.tm_sec = ((PHYSFS_uint32) time->twosecs) * 2;                        
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   711
    tm.tm_min = time->minutes;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   712
    tm.tm_hour = time->hours;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   713
    tm.tm_mday = date->day;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   714
    tm.tm_mon = date->month;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   715
    tm.tm_year = ((PHYSFS_uint32) date->year) + 80;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   716
    tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   717
    tm.tm_yday = -1;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   718
    tm.tm_isdst = -1;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   719
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   720
    return (PHYSFS_sint64) mktime(&tm);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   721
} /* os2TimeToUnixTime */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   722
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   723
1620
f3459eaad51b Fixed mounting a symlink to a real directory.
Ryan C. Gordon <icculus@icculus.org>
parents: 1602
diff changeset
   724
int __PHYSFS_platformStat(const char *filename, PHYSFS_Stat *stat, const int follow)
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   725
{
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   726
    char *cpfname = cvtUtf8ToCodepage(filename);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   727
    FILESTATUS3 fs;
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   728
    int retval = 0;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   729
    APIRET rc;
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   730
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   731
    BAIL_IF_ERRPASS(!cpfname, 0);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   732
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   733
    rc = DosQueryPathInfo(cpfname, FIL_STANDARD, &fs, sizeof (fs));
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   734
    GOTO_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), done);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   735
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   736
    if (fs.attrFile & FILE_DIRECTORY)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   737
    {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   738
        stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   739
        stat->filesize = 0;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   740
    } /* if */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   741
    else
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   742
    {
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   743
        stat->filetype = PHYSFS_FILETYPE_REGULAR;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   744
        stat->filesize = fs.cbFile;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   745
    } /* else */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   746
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   747
    stat->modtime = os2TimeToUnixTime(&fs.fdateLastWrite, &fs.ftimeLastWrite);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   748
    if (stat->modtime < 0)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   749
        stat->modtime = 0;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   750
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   751
    stat->accesstime = os2TimeToUnixTime(&fs.fdateLastAccess, &fs.ftimeLastAccess);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   752
    if (stat->accesstime < 0)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   753
        stat->accesstime = 0;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   754
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   755
    stat->createtime = os2TimeToUnixTime(&fs.fdateCreation, &fs.ftimeCreation);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   756
    if (stat->createtime < 0)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   757
        stat->createtime = 0;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   758
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   759
    stat->readonly = ((fs.attrFile & FILE_READONLY) == FILE_READONLY);
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   760
    return 1;  /* success */
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   761
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   762
done:
1405
0035557bd1f7 OS/2: more work on getting this to compile.
Ryan C. Gordon <icculus@icculus.org>
parents: 1403
diff changeset
   763
    allocator.Free(cpfname); 
1403
268fa0053d9f OS/2: implemented Unicode support, modernized platform_os2.c's code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   764
    return retval;
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   765
} /* __PHYSFS_platformStat */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   766
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   767
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   768
void *__PHYSFS_platformGetThreadID(void)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   769
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   770
    PTIB ptib;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   771
    PPIB ppib;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   772
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   773
    /*
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   774
     * Allegedly, this API never fails, but we'll punt and return a
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   775
     *  default value (zero might as well do) if it does.
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   776
     */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   777
    const APIRET rc = DosGetInfoBlocks(&ptib, &ppib);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   778
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), 0);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   779
    return ((void *) ptib->tib_ordinal);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   780
} /* __PHYSFS_platformGetThreadID */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   781
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   782
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   783
void *__PHYSFS_platformCreateMutex(void)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   784
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   785
    HMTX hmtx = NULLHANDLE;
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   786
    const APIRET rc = DosCreateMutexSem(NULL, &hmtx, 0, 0);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1401
diff changeset
   787
    BAIL_IF(rc != NO_ERROR, errcodeFromAPIRET(rc), NULL);
1395
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   788
    return ((void *) hmtx);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   789
} /* __PHYSFS_platformCreateMutex */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   790
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   791
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   792
void __PHYSFS_platformDestroyMutex(void *mutex)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   793
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   794
    DosCloseMutexSem((HMTX) mutex);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   795
} /* __PHYSFS_platformDestroyMutex */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   796
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   797
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   798
int __PHYSFS_platformGrabMutex(void *mutex)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   799
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   800
    /* Do _NOT_ set the physfs error message in here! */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   801
    return (DosRequestMutexSem((HMTX) mutex, SEM_INDEFINITE_WAIT) == NO_ERROR);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   802
} /* __PHYSFS_platformGrabMutex */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   803
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   804
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   805
void __PHYSFS_platformReleaseMutex(void *mutex)
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   806
{
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   807
    DosReleaseMutexSem((HMTX) mutex);
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   808
} /* __PHYSFS_platformReleaseMutex */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   809
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   810
#endif  /* PHYSFS_PLATFORM_OS2 */
2b5c79f64d59 os2: added OS/2 support back in.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   811
1507
8953b8a171e7 Update filename comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1506
diff changeset
   812
/* end of physfs_platform_os2.c ... */