platform/os2.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 27 Jul 2002 01:27:19 +0000
changeset 404 d08723d994c1
child 407 81646aa3f6f8
permissions -rw-r--r--
Initial add.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * OS/2 support routines for PhysicsFS.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE in the source's root directory.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#if HAVE_CONFIG_H
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#  include <config.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#endif
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#if (defined OS2)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#define INCL_DOSSEMAPHORES
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#define INCL_DOSDATETIME
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#define INCL_DOSFILEMGR
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#define INCL_DOSMODULEMGR
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#define INCL_DOSERRORS
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
#define INCL_DOSDEVICES
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#include <os2.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#include <stdlib.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
#include <errno.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
#include <string.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#include <assert.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
static APIRET os2err(APIRET retval)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
    const char *err = NULL;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
     * The ones that say "OS/2 reported" are more for PhysicsFS developer
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
     *  debugging. We give more generic messages for ones that are likely to
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
     *  fall through to an application.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
    switch (retval)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
        case NO_ERROR: /* Don't set the PhysicsFS error message for these... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
        case ERROR_INTERRUPT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
        case ERROR_TIMEOUT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
        case ERROR_NOT_ENOUGH_MEMORY:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
            err = ERR_OUT_OF_MEMORY;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
        case ERROR_FILE_NOT_FOUND:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
            err = "File not found";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
        case ERROR_PATH_NOT_FOUND:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
            err = "Path not found";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
        case ERROR_ACCESS_DENIED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
            err = "Access denied";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
        case ERROR_NOT_DOS_DISK:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
            err = "Not a DOS disk";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        case ERROR_DRIVE_LOCKED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
            err = "Drive is locked";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
        case ERROR_SHARING_VIOLATION:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
            err = "Sharing violation";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
        case ERROR_CANNOT_MAKE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
            err = "Cannot make";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
        case ERROR_DEVICE_IN_USE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
            err = "Device already in use";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
        case ERROR_DRIVE_LOCKED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
            err = "Drive is locked";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
        case ERROR_OPEN_FAILED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
            err = "Open failed";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
        case ERROR_DISK_FULL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
            err = "Disk is full";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
        case ERROR_DISK_FULL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
            err = "Pipe busy";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
        case ERROR_SHARING_BUFFER_EXCEEDED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
            err = "Sharing buffer exceeded";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
        case ERROR_FILENAME_EXCED_RANGE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
        case ERROR_META_EXPANSION_TOO_LONG:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
            err = "Filename too big";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
        case ERROR_TOO_MANY_HANDLES:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
        case ERROR_TOO_OPEN_FILES:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
        case ERROR_NO_MORE_SEARCH_HANDLES:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
            err = "Too many open handles";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
        case ERROR_SEEK_ON_DEVICE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
            err = "Seek error";  /* Is that what this error means? */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
        case ERROR_NEGATIVE_SEEK:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
            err = "Seek past start of file";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
        case ERROR_CURRENT_DIRECTORY:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
            err = "Trying to delete current working directory";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
        case ERROR_WRITE_PROTECT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
            err = "Write protect error";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
        case ERROR_WRITE_FAULT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
            err = "Write fault";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
        case ERROR_LOCK_VIOLATION:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
            err = "Lock violation";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
        case ERROR_GEN_FAILURE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
            err = "General failure";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
        case ERROR_UNCERTAIN_MEDIA:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
            err = "Uncertain media";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
        case ERROR_PROTECTION_VIOLATION:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
            err = "Protection violation";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
        case ERROR_INVALID_PARAMETER:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
        case ERROR_INVALID_NAME:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
        case ERROR_INVALID_DRIVE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
        case ERROR_INVALID_HANDLE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
        case ERROR_INVALID_FUNCTION:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
        case ERROR_INVALID_LEVEL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
        case ERROR_INVALID_CATEGORY:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
        case ERROR_DUPLICATE_NAME:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
        case ERROR_BUFFER_OVERFLOW:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
        case ERROR_BAD_LENGTH:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
        case ERROR_BAD_DRIVER_LEVEL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
        case ERROR_DIRECT_ACCESS_HANDLE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
            err = "OS/2 reported an invalid parameter to an API function";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
        case ERROR_NO_VOLUME_LABEL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
            err = "OS/2 reported no volume label";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
        case ERROR_NO_MORE_FILES:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
            err = "OS/2 reported no more files";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
        case ERROR_MONITORS_NOT_SUPPORTED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
            err = "OS/2 reported monitors not supported";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
        case ERROR_BROKEN_PIPE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
            err = "OS/2 reported a broken pipe";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
        case ERROR_MORE_DATA:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
            err = "OS/2 reported \"more data\" (?)";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
        case ERROR_EAS_DIDNT_FIT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
            err = "OS/2 reported Extended Attributes didn't fit";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
        case ERROR_INVALID_EA_NAME:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
            err = "OS/2 reported an invalid Extended Attribute name";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
        case ERROR_EA_LIST_INCONSISTENT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
            err = "OS/2 reported an inconsistent Extended Attribute list";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
        case ERROR_EA_VALUE_UNSUPPORTABLE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
            err = "OS/2 reported an unsupportable Extended Attribute value";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
        case ERROR_SEM_OWNER_DIED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
            err = "OS/2 reported that semaphore owner died";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
        case ERROR_TOO_MANY_SEM_REQUESTS:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
            err = "OS/2 reported too many semaphore requests";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
        case ERROR_SEM_BUSY:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
            err = "OS/2 reported a blocked semaphore";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
        case ERROR_NOT_OWNER:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
            err = "OS/2 reported that we used a resource we don't own.";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
        default:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
            err = "OS/2 reported back with unrecognized error code";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
    } /* switch */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
    if (err != NULL)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
        __PHYSFS_setError(err);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
} /* os2err */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
static char *baseDir = NULL;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
int __PHYSFS_platformInit(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
    char buf[CCHMAXPATH];
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
    APIRET rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    TIB tib;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
    PIB pib;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    assert(baseDir == NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
    BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&tib, &pib)) != NO_ERROR, NULL, 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
    rc = DosQueryModuleName(pib.pib_hmte, sizeof (buf), (PCHAR) buf);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
    baseDir = (char *) malloc(strlen(buf) + 1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
    BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
    strcpy(baseDir);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
    return(1);  /* success. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
} /* __PHYSFS_platformInit */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
int __PHYSFS_platformDeinit(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
    assert(baseDir != NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
    free(baseDir);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
    baseDir = NULL;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
    return(1);  /* success. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
} /* __PHYSFS_platformDeinit */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
static int disc_is_inserted(ULONG drive)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
    int rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
    char buf[20];
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
    DosError(FERR_DISABLEHARDERR | FERR_DISABLEEXCEPTION);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
    rc = DosQueryFSInfo(drive + 1, FSIL_VOLSER, buf, sizeof (buf));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
    DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    return(rc == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
} /* is_cdrom_inserted */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
static int is_cdrom_drive(ULONG drive)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
    PHYSFS_uint16 cmd = (((drive & 0xFF) << 8) | 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
    BIOSPARAMETERBLOCK bpb;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
    ULONG ul1, ul2;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
    APIRET rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
    rc = DosDevIOCtl((HFILE) -1, IOCTL_DISK,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
                     DSK_GETDEVICEPARAMS,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
                     &cmd, sizeof (cmd), &ul1,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
                     &bpb, sizeof (bpb), &u2);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
     * !!! FIXME: Note that this tells us that the media is REMOVABLE...
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
     * !!! FIXME:  but it might not be a CD-ROM...check driver name?
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
    return((rc == NO_ERROR) && ((DiskData.fsDeviceAttr & 0x0001) == 0));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
} /* is_cdrom_drive */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
char **__PHYSFS_platformDetectAvailableCDs(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
    ULONG dummy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
    ULONG drivemap;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
    ULONG i, bit;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
    APIRET rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
    char **retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
    PHYSFS_uint32 cd_count = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
    retval = (char **) malloc(sizeof (char *));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
    *retval = NULL;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
    rc = DosQueryCurrentDisk(&dummy, &drivemap);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
    /* !!! FIXME: the a, b, and c drives are almost certainly NOT cdroms... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
    for (i = 0, bit = 1; i < 26; i++, bit << 1)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
        if (drivemap & bit)  /* this logical drive exists. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
        {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
            if ((is_cdrom_drive(i)) && (disc_is_inserted(i)))
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
            {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
                char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
                if (tmp)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
                {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
                    char *str = (char *) malloc(4);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
                    retval = tmp;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
                    retval[cd_count - 1] = str;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
                    if (str)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
                    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
                        str[0] = ('A' + i);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
                        str[1] = ':';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
                        str[2] = '\\';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
                        str[3] = '\0';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
                        cd_count++;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
                    } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
                } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
            } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
    } /* for */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
} /* __PHYSFS_platformDetectAvailableCDs */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
    char *retval = (char *) malloc(strlen(baseDir) + 1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
    strcpy(retval, baseDir); /* calculated at init time. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
} /* __PHYSFS_platformCalcBaseDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
char *__PHYSFS_platformGetUserName(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
    return(NULL);  /* (*shrug*) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
} /* __PHYSFS_platformGetUserName */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
char *__PHYSFS_platformGetUserDir(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
    return(__PHYSFS_platformCalcBaseDir(NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
} /* __PHYSFS_platformGetUserDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
int __PHYSFS_platformStricmp(const char *x, const char *y)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
    int ux, uy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
    do
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
        ux = toupper((int) *x);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
        uy = toupper((int) *y);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
        if (ux > uy)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
            return(1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
        else if (ux < uy)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
            return(-1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
        x++;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
        y++;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
    } while ((ux) && (uy));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
    return(0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
} /* __PHYSFS_platformStricmp */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
int __PHYSFS_platformExists(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
    APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
    return(os2err(rc) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
} /* __PHYSFS_platformExists */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
int __PHYSFS_platformIsSymLink(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
    return(0);  /* no symlinks in OS/2. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
} /* __PHYSFS_platformIsSymlink */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
int __PHYSFS_platformIsDirectory(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
    APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
    return((fs.attrFile & FILE_DIRECTORY) != 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
} /* __PHYSFS_platformIsDirectory */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
char *__PHYSFS_platformCvtToDependent(const char *prepend,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
                                      const char *dirName,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
                                      const char *append)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
    int len = ((prepend) ? strlen(prepend) : 0) +
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
              ((append) ? strlen(append) : 0) +
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
              strlen(dirName) + 1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
    char *retval = malloc(len);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
    char *p;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
    if (prepend)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
        strcpy(retval, prepend);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
    else
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
        retval[0] = '\0';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
    strcat(retval, dirName);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
    if (append)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
        strcat(retval, append);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
        *p = '\\';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
} /* __PHYSFS_platformCvtToDependent */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
                                                  int omitSymLinks)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
    char spec[CCHMAXPATH];
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
    LinkedStringList *retval = NULL, *p = NULL;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
    FINDFILEBUF3 fb;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
    HDIR hdir = HDIR_CREATE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
    ULONG count = 1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
    APIRET rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
    BAIL_IF_MACRO(strlen(dirname) > sizeof (spec) - 4, ERR_OS_ERROR, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
    strcpy(spec, dname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
    strcat(spec, "*.*");
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
    rc = DosFindFirst(spec, &hdir,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
                      FILE_DIRECTORY | FILE_ARCHIVED |
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
                      FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
                      &fb, sizeof (fb), &count, FIL_STANDARD)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
    while (count == 1)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
        if (strcmp(fb.achName, ".") == 0)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
            continue;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
        if (strcmp(fb.achName, "..") == 0)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
            continue;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
        retval = __PHYSFS_addToLinkedStringList(retval, &p, fb.achName, -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
        DosFindNext(hdir, &fb, sizeof (fb), &count);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
    } /* while */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
    DosFindClose(hdir);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
} /* __PHYSFS_platformEnumerateFiles */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
char *__PHYSFS_platformCurrentDir(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
    char *retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
    ULONG currentDisk;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
    ULONG dummy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
    ULONG pathSize = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
    APIRET rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
    BYTE byte;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
    rc = DosQueryCurrentDisk(&currentDisk, &dummy);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
    /* The first call just tells us how much space we need for the string. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
    rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
    pathSize++; /* Add space for null terminator. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
    retval = (char *) malloc(pathSize + 3);  /* plus "x:\\" */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
    /* Actually get the string this time. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
    rc = DosQueryCurrentDir(currentDisk, (PBYTE) (retval + 3), &pathSize);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486
    if (os2err(rc) != NO_ERROR)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
        free(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
        return(NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
    } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
    retval[0] = ('A' + (currentDisk - 1));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
    retval[1] = ':';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
    retval[2] = '\\';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
} /* __PHYSFS_platformCurrentDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
char *__PHYSFS_platformRealPath(const char *path)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
    char buf[CCHMAXPATH];
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
    char *retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
    APIRET rc = DosQueryPathInfo(fname, FIL_QUERYFULLNAME, buf, sizeof (buf));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
    retval = (char *) malloc(strlen(buf) + 1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
    strcpy(retval, buf);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
} /* __PHYSFS_platformRealPath */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
int __PHYSFS_platformMkDir(const char *path)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
    return(os2err(DosCreateDir(path, NULL)) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
} /* __PHYSFS_platformMkDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
void *__PHYSFS_platformOpenRead(const char *filename)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
    ULONG actionTaken = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
    HFILE hfile = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
     * File must be opened SHARE_DENYWRITE and ACCESS_READONLY, otherwise
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
    os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
                   OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
                   OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
                   OPEN_FLAGS_NO_INHERIT | OPEN_SHARE_DENYWRITE |
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
                   OPEN_ACCESS_READONLY, NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
    return((void *) hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
} /* __PHYSFS_platformOpenRead */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   535
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   536
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
void *__PHYSFS_platformOpenWrite(const char *filename)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   538
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
    ULONG actionTaken = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
    HFILE hfile = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
     * File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
    os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
                   OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
                   OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
                   OPEN_FLAGS_NO_INHERIT | OPEN_SHARE_DENYWRITE |
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
                   OPEN_ACCESS_READWRITE, NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
    return((void *) hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
} /* __PHYSFS_platformOpenWrite */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
void *__PHYSFS_platformOpenAppend(const char *filename)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
    ULONG dummy = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
    HFILE hfile = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
     * File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
    rc = os2err(DosOpen(filename, &hfile, &dummy, 0, FILE_NORMAL,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
                   OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
                   OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
                   OPEN_FLAGS_NO_INHERIT | OPEN_SHARE_DENYWRITE |
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
                   OPEN_ACCESS_READWRITE, NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
    if (rc == NO_ERROR)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
        if (os2err(DosSetFilePtr(hfile, 0, FILE_END, &dummy)) != NO_ERROR)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
        {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
            DosClose(hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
            hfile = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   578
    } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
    return((void *) hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
} /* __PHYSFS_platformOpenAppend */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   583
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   587
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
    PHYSFS_sint64 retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   589
    ULONG br;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   590
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
    for (retval = 0; retval < count; retval++)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
        APIRET rc = os2err(DosRead(hfile, buffer, size, &br));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
        if (br < size)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
        {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
            DosSetFilePtr(hfile, -bw, FILE_CURRENT, &br); /* try to cleanup. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   597
            return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   598
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   599
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   600
        buffer = (void *) ( ((char *) buffer) + size) );
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
    } /* for */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   602
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
} /* __PHYSFS_platformRead */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   605
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   606
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
    PHYSFS_sint64 retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
    ULONG bw;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
    for (retval = 0; retval < count; retval++)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
        APIRET rc = os2err(DosWrite(hfile, buffer, size, &bw));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   617
        if (bw < size)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
        {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   619
            DosSetFilePtr(hfile, -bw, FILE_CURRENT, &bw); /* try to cleanup. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
            return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   623
        buffer = (void *) ( ((char *) buffer) + size) );
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   624
    } /* for */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
} /* __PHYSFS_platformWrite */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   629
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   630
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
    ULONG dummy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
    LONG dist = (LONG) pos;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   635
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
    /* hooray for 32-bit filesystem limits!  :) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
    BAIL_IF_MACRO((PHYSFS_uint64) dist != pos, ERR_SEEK_OUT_OF_RANGE, 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
    return(os2err(DosSetFilePtr(hfile, dist, FILE_BEGIN, &dummy)) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
} /* __PHYSFS_platformSeek */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   644
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
    ULONG pos;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
    APIRET rc = os2err(DosSetFilePtr(hfile, 0, FILE_CURRENT, &pos));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
    BAIL_IF_MACRO(rc != NO_ERROR, NULL, -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
    return((PHYSFS_sint64) pos);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
} /* __PHYSFS_platformTell */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
    APIRET rc = DosQueryFileInfo(hfile, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
    return((PHYSFS_sint64) fs.cbFile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
} /* __PHYSFS_platformFileLength */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663
int __PHYSFS_platformEOF(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   664
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   665
    PHYSFS_sint64 len, pos;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   666
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   667
    len = __PHYSFS_platformFileLength(opaque);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
    BAIL_IF_MACRO(len == -1, NULL, 1);  /* (*shrug*) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   669
    pos = __PHYSFS_platformTell(opaque);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   670
    BAIL_IF_MACRO(pos == -1, NULL, 1);  /* (*shrug*) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   671
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   672
    return(pos >= len);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   673
} /* __PHYSFS_platformEOF */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   674
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   676
int __PHYSFS_platformFlush(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   677
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   678
    return(os2err(DosResetBuffers((HFILE) opaque) == NO_ERROR));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   679
} /* __PHYSFS_platformFlush */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   680
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   681
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   682
int __PHYSFS_platformClose(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   683
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   684
    return(os2err(DosClose((HFILE) opaque) == NO_ERROR));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   685
} /* __PHYSFS_platformClose */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   686
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   687
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   688
int __PHYSFS_platformDelete(const char *path)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   689
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   690
    if (__PHYSFS_platformIsDirectory(path))
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   691
        return(os2err(DosDeleteDir(path)) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   692
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   693
    return(os2err(DosDelete(path) == NO_ERROR));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   694
} /* __PHYSFS_platformDelete */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   695
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   696
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   697
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   698
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   699
    struct tm tm;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   700
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   701
    APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   702
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   703
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   704
    /* Convert to a format that mktime() can grok... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   705
    tm.tm_sec = ((PHYSFS_uint32) fs.ftimeLastWrite.twosecs) * 2;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   706
    tm.tm_min = fs.ftimeLastWrite.minutes;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   707
    tm.tm_hour = fs.ftimeLastWrite.hours;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   708
    tm.tm_mday = fs.fdateLastWrite.day;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   709
    tm.tm_mon = fs.fdateLastWrite.month;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   710
    tm.tm_year = ((PHYSFS_uint32) fs.fdateLastWrite.year) + 80;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   711
    tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   712
    tm.tm_yday = -1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   713
    tm.tm_isdst = -1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   714
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   715
    /* Convert to a format PhysicsFS can grok... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   716
    retval = (PHYSFS_sint64) mktime(&tm);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   717
    BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   718
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   719
} /* __PHYSFS_platformGetLastModTime */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   720
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   721
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   722
/* Much like my college days, try to sleep for 10 milliseconds at a time... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   723
void __PHYSFS_platformTimeslice(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   724
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   725
    DosSleep(10);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   726
} /* __PHYSFS_platformTimeslice(void) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   727
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   728
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   729
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   730
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   731
    TIB tib;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   732
    PIB pib;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   733
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   734
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   735
     * Allegedly, this API never fails, but we'll punt and return a
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   736
     *  default value (zero might as well do) if it does.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   737
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   738
    BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&tib, &pib)) != NO_ERROR, 0, 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   739
    return((PHYSFS_uint64) tib.tib_ordinal);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   740
} /* __PHYSFS_platformGetThreadID */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   741
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   742
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   743
void *__PHYSFS_platformCreateMutex(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   744
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   745
    HMTX hmtx = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   746
    os2err(DosCreateMutexSem(NULL, &hmtx, 0, 0));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   747
    return((void *) hmtx);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   748
} /* __PHYSFS_platformCreateMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   749
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   750
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   751
void __PHYSFS_platformDestroyMutex(void *mutex)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   752
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   753
    DosCloseMutexSem((HMTX) mutex);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   754
} /* __PHYSFS_platformDestroyMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   755
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   756
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   757
int __PHYSFS_platformGrabMutex(void *mutex)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   758
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   759
    /* Do _NOT_ call os2err() (which sets the physfs error msg) in here! */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   760
    return(DosRequestMutexSem((HMTX) mutex, SEM_INDEFINITE_WAIT) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   761
} /* __PHYSFS_platformGrabMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   762
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   763
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   764
void __PHYSFS_platformReleaseMutex(void *mutex)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   765
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   766
    DosReleaseMutexSem((HMTX) mutex);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   767
} /* __PHYSFS_platformReleaseMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   768
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   769
#endif  /* defined OS2 */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   770
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   771
/* end of os2.c ... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   772