platform/os2.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 28 Jul 2002 04:02:06 +0000
changeset 420 8869f1432112
parent 416 eadb08626c80
child 423 524e087944b4
permissions -rw-r--r--
Determines correct case for basedir.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * OS/2 support routines for PhysicsFS.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Please see the file LICENSE in the source's root directory.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#if HAVE_CONFIG_H
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#  include <config.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#endif
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#if (defined OS2)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#define INCL_DOSSEMAPHORES
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#define INCL_DOSDATETIME
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#define INCL_DOSFILEMGR
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#define INCL_DOSMODULEMGR
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#define INCL_DOSERRORS
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    20
#define INCL_DOSPROCESS
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#define INCL_DOSDEVICES
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    22
#define INCL_DOSDEVIOCTL
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    23
#define INCL_DOSMISC
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
#include <os2.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#include <stdlib.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#include <errno.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#include <string.h>
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
#include <assert.h>
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    30
#include <time.h>
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    31
#include <ctype.h>
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    32
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    33
#define __PHYSICSFS_INTERNAL__
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    34
#include "physfs_internal.h"
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    35
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    36
const char *__PHYSFS_platformDirSeparator = "\\";
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
static APIRET os2err(APIRET retval)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
    const char *err = NULL;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
     * The ones that say "OS/2 reported" are more for PhysicsFS developer
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
     *  debugging. We give more generic messages for ones that are likely to
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
     *  fall through to an application.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
    switch (retval)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
        case NO_ERROR: /* Don't set the PhysicsFS error message for these... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
        case ERROR_INTERRUPT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
        case ERROR_TIMEOUT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
        case ERROR_NOT_ENOUGH_MEMORY:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
            err = ERR_OUT_OF_MEMORY;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
        case ERROR_FILE_NOT_FOUND:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
            err = "File not found";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
        case ERROR_PATH_NOT_FOUND:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
            err = "Path not found";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        case ERROR_ACCESS_DENIED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
            err = "Access denied";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
        case ERROR_NOT_DOS_DISK:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
            err = "Not a DOS disk";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
        case ERROR_SHARING_VIOLATION:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
            err = "Sharing violation";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
        case ERROR_CANNOT_MAKE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
            err = "Cannot make";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
        case ERROR_DEVICE_IN_USE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
            err = "Device already in use";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
        case ERROR_OPEN_FAILED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
            err = "Open failed";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
        case ERROR_DISK_FULL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
            err = "Disk is full";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
    95
        case ERROR_PIPE_BUSY:
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
            err = "Pipe busy";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
        case ERROR_SHARING_BUFFER_EXCEEDED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
            err = "Sharing buffer exceeded";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
        case ERROR_FILENAME_EXCED_RANGE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
        case ERROR_META_EXPANSION_TOO_LONG:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
            err = "Filename too big";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
        case ERROR_TOO_MANY_HANDLES:
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   109
        case ERROR_TOO_MANY_OPEN_FILES:
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
        case ERROR_NO_MORE_SEARCH_HANDLES:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
            err = "Too many open handles";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
        case ERROR_SEEK_ON_DEVICE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
            err = "Seek error";  /* Is that what this error means? */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
        case ERROR_NEGATIVE_SEEK:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
            err = "Seek past start of file";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
        case ERROR_CURRENT_DIRECTORY:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
            err = "Trying to delete current working directory";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
        case ERROR_WRITE_PROTECT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
            err = "Write protect error";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
        case ERROR_WRITE_FAULT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
            err = "Write fault";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
        case ERROR_LOCK_VIOLATION:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
            err = "Lock violation";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
        case ERROR_GEN_FAILURE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
            err = "General failure";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
        case ERROR_UNCERTAIN_MEDIA:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
            err = "Uncertain media";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
        case ERROR_PROTECTION_VIOLATION:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
            err = "Protection violation";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
        case ERROR_INVALID_PARAMETER:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
        case ERROR_INVALID_NAME:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
        case ERROR_INVALID_DRIVE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
        case ERROR_INVALID_HANDLE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
        case ERROR_INVALID_FUNCTION:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
        case ERROR_INVALID_LEVEL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
        case ERROR_INVALID_CATEGORY:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
        case ERROR_DUPLICATE_NAME:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
        case ERROR_BUFFER_OVERFLOW:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
        case ERROR_BAD_LENGTH:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
        case ERROR_BAD_DRIVER_LEVEL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
        case ERROR_DIRECT_ACCESS_HANDLE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
            err = "OS/2 reported an invalid parameter to an API function";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
        case ERROR_NO_VOLUME_LABEL:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
            err = "OS/2 reported no volume label";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
        case ERROR_NO_MORE_FILES:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
            err = "OS/2 reported no more files";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
        case ERROR_MONITORS_NOT_SUPPORTED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
            err = "OS/2 reported monitors not supported";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
        case ERROR_BROKEN_PIPE:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
            err = "OS/2 reported a broken pipe";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
        case ERROR_MORE_DATA:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
            err = "OS/2 reported \"more data\" (?)";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
        case ERROR_EAS_DIDNT_FIT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
            err = "OS/2 reported Extended Attributes didn't fit";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
        case ERROR_INVALID_EA_NAME:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
            err = "OS/2 reported an invalid Extended Attribute name";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
        case ERROR_EA_LIST_INCONSISTENT:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
            err = "OS/2 reported an inconsistent Extended Attribute list";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
        case ERROR_SEM_OWNER_DIED:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
            err = "OS/2 reported that semaphore owner died";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
        case ERROR_TOO_MANY_SEM_REQUESTS:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
            err = "OS/2 reported too many semaphore requests";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
        case ERROR_SEM_BUSY:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
            err = "OS/2 reported a blocked semaphore";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
        case ERROR_NOT_OWNER:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
            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
   211
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
        default:
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
            err = "OS/2 reported back with unrecognized error code";
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
            break;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
    } /* switch */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
    if (err != NULL)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
        __PHYSFS_setError(err);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
} /* os2err */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
420
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   225
/* (be gentle, this function isn't very robust.) */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   226
static void cvt_path_to_correct_case(char *buf)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   227
{
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   228
    char *fname = buf + 3;            /* point to first element. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   229
    char *ptr = strchr(fname, '\\');  /* find end of first element. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   230
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   231
    buf[0] = toupper(buf[0]);  /* capitalize drive letter. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   232
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   233
    /*
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   234
     * Go through each path element, and enumerate its parent dir until
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   235
     *  a case-insensitive match is found. If one is (and it SHOULD be)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   236
     *  then overwrite the original element with the correct case.
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   237
     * If there's an error, or the path has vanished for some reason, it
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   238
     *  won't hurt to have the original case, so we just keep going.
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   239
     */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   240
    while (fname != NULL)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   241
    {
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   242
        char spec[CCHMAXPATH];
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   243
        FILEFINDBUF3 fb;
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   244
        HDIR hdir = HDIR_CREATE;
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   245
        ULONG count = 1;
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   246
        APIRET rc;
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   247
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   248
        *(fname - 1) = '\0';  /* isolate parent dir string. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   249
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   250
        strcpy(spec, buf);      /* copy isolated parent dir... */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   251
        strcat(spec, "\\*.*");  /*  ...and add wildcard search spec. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   252
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   253
        if (ptr != NULL)  /* isolate element to find (fname is the start). */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   254
            *ptr = '\0';
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   255
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   256
        rc = DosFindFirst(spec, &hdir, FILE_DIRECTORY,
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   257
                          &fb, sizeof (fb), &count, FIL_STANDARD);
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   258
        if (rc == NO_ERROR)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   259
        {
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   260
            while (count == 1)  /* while still entries to enumerate... */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   261
            {
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   262
                if (__PHYSFS_platformStricmp(fb.achName, fname) == 0)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   263
                {
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   264
                    strcpy(fname, fb.achName);
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   265
                    break;  /* there it is. Overwrite and stop searching. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   266
                } /* if */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   267
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   268
                DosFindNext(hdir, &fb, sizeof (fb), &count);
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   269
            } /* while */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   270
            DosFindClose(hdir);
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   271
        } /* if */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   272
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   273
        *(fname - 1) = '\\';   /* unisolate parent dir. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   274
        fname = ptr;           /* point to next element. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   275
        if (ptr != NULL)
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   276
        {
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   277
            *ptr = '\\';       /* unisolate element. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   278
            ptr = strchr(++fname, '\\');  /* find next element. */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   279
        } /* if */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   280
    } /* while */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   281
} /* cvt_file_to_correct_case */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   282
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   283
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
static char *baseDir = NULL;
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
int __PHYSFS_platformInit(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
    char buf[CCHMAXPATH];
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
    APIRET rc;
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   290
    PTIB ptib;
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   291
    PPIB ppib;
411
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   292
    PHYSFS_sint32 len;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
    assert(baseDir == NULL);
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   295
    BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, NULL, 0);
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   296
    rc = DosQueryModuleName(ppib->pib_hmte, sizeof (buf), (PCHAR) buf);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
411
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   299
    /* chop off filename, leave path. */
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   300
    for (len = strlen(buf) - 1; len >= 0; len--)
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   301
    {
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   302
        if (buf[len] == '\\')
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   303
        {
412
f743cf88c61f Minor patch.
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   304
            buf[len] = '\0';
411
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   305
            break;
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   306
        } /* if */
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   307
    } /* for */
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   308
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   309
    assert(len > 0);  /* should have been a "x:\\" on the front on string. */
411
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   310
420
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   311
    /* The string is capitalized! Figure out the REAL case... */
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   312
    cvt_path_to_correct_case(buf);
8869f1432112 Determines correct case for basedir.
Ryan C. Gordon <icculus@icculus.org>
parents: 416
diff changeset
   313
411
4907a4f94872 Fixed basedir/userdir calculation.
Ryan C. Gordon <icculus@icculus.org>
parents: 407
diff changeset
   314
    baseDir = (char *) malloc(len + 1);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
    BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   316
    strcpy(baseDir, buf);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
    return(1);  /* success. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
} /* __PHYSFS_platformInit */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
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
int __PHYSFS_platformDeinit(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
    assert(baseDir != NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
    free(baseDir);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
    baseDir = NULL;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
    return(1);  /* success. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
} /* __PHYSFS_platformDeinit */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
static int disc_is_inserted(ULONG drive)
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
    int rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
    char buf[20];
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
    DosError(FERR_DISABLEHARDERR | FERR_DISABLEEXCEPTION);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
    rc = DosQueryFSInfo(drive + 1, FSIL_VOLSER, buf, sizeof (buf));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
    DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
    return(rc == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
} /* is_cdrom_inserted */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   341
/* looks like "CD01" in ASCII (littleendian)...used for an ioctl. */
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   342
#define CD01 0x31304443
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   343
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
static int is_cdrom_drive(ULONG drive)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
{
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   346
    PHYSFS_uint32 param, data;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
    ULONG ul1, ul2;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
    APIRET rc;
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   349
    HFILE hfile = NULLHANDLE;
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   350
    char drivename[3] = { 'A' + drive, ':', '\0' };
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   352
    rc = DosOpen(drivename, &hfile, &ul1, 0, 0,
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   353
                 OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   354
                 OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR |
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   355
                 OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE, NULL);
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   356
    BAIL_IF_MACRO(rc != NO_ERROR, NULL, 0);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   358
    data = 0;
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   359
    param = PHYSFS_swapULE32(CD01);
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   360
    ul1 = ul2 = sizeof (PHYSFS_uint32);
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   361
    rc = DosDevIOCtl(hfile, IOCTL_CDROMDISK, CDROMDISK_GETDRIVER,
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   362
                     &param, sizeof (param), &ul1, &data, sizeof (data), &ul2);
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   363
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   364
    DosClose(hfile);
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   365
    return((rc == NO_ERROR) && (PHYSFS_swapULE32(data) == CD01));
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
} /* is_cdrom_drive */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
char **__PHYSFS_platformDetectAvailableCDs(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
    ULONG dummy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
    ULONG drivemap;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
    ULONG i, bit;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
    APIRET rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
    char **retval;
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   376
    PHYSFS_uint32 cd_count = 1;   /* we count the NULL entry. */
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
    retval = (char **) malloc(sizeof (char *));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
    *retval = NULL;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
    rc = DosQueryCurrentDisk(&dummy, &drivemap);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, retval);
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
    /* !!! FIXME: the a, b, and c drives are almost certainly NOT cdroms... */
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   386
    for (i = 0, bit = 1; i < 26; i++, bit <<= 1)
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
        if (drivemap & bit)  /* this logical drive exists. */
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
            if ((is_cdrom_drive(i)) && (disc_is_inserted(i)))
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
            {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
                char **tmp = realloc(retval, sizeof (char *) * (cd_count + 1));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
                if (tmp)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
                {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
                    char *str = (char *) malloc(4);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
                    retval = tmp;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
                    retval[cd_count - 1] = str;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
                    if (str)
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
                        str[0] = ('A' + i);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
                        str[1] = ':';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
                        str[2] = '\\';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
                        str[3] = '\0';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
                        cd_count++;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
                    } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
                } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
            } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
    } /* for */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   411
    retval[cd_count - 1] = NULL;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
} /* __PHYSFS_platformDetectAvailableCDs */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
    char *retval = (char *) malloc(strlen(baseDir) + 1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
    strcpy(retval, baseDir); /* calculated at init time. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
} /* __PHYSFS_platformCalcBaseDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
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
char *__PHYSFS_platformGetUserName(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
    return(NULL);  /* (*shrug*) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
} /* __PHYSFS_platformGetUserName */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
char *__PHYSFS_platformGetUserDir(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
    return(__PHYSFS_platformCalcBaseDir(NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
} /* __PHYSFS_platformGetUserDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
int __PHYSFS_platformStricmp(const char *x, const char *y)
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
    int ux, uy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
    do
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
        ux = toupper((int) *x);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
        uy = toupper((int) *y);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
        if (ux > uy)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
            return(1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
        else if (ux < uy)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
            return(-1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
        x++;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
        y++;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
    } while ((ux) && (uy));
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
    return(0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
} /* __PHYSFS_platformStricmp */
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
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
int __PHYSFS_platformExists(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
    APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
    return(os2err(rc) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
} /* __PHYSFS_platformExists */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
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
int __PHYSFS_platformIsSymLink(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
    return(0);  /* no symlinks in OS/2. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
} /* __PHYSFS_platformIsSymlink */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
int __PHYSFS_platformIsDirectory(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
    APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
    return((fs.attrFile & FILE_DIRECTORY) != 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
} /* __PHYSFS_platformIsDirectory */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
char *__PHYSFS_platformCvtToDependent(const char *prepend,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
                                      const char *dirName,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
                                      const char *append)
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
    int len = ((prepend) ? strlen(prepend) : 0) +
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
              ((append) ? strlen(append) : 0) +
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486
              strlen(dirName) + 1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
    char *retval = malloc(len);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
    char *p;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
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
    if (prepend)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
        strcpy(retval, prepend);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
    else
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
        retval[0] = '\0';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
    strcat(retval, dirName);
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
    if (append)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
        strcat(retval, append);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
    for (p = strchr(retval, '/'); p != NULL; p = strchr(p + 1, '/'))
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
        *p = '\\';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
} /* __PHYSFS_platformCvtToDependent */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
                                                  int omitSymLinks)
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
    char spec[CCHMAXPATH];
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   513
    LinkedStringList *ret = NULL, *p = NULL;
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   514
    FILEFINDBUF3 fb;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
    HDIR hdir = HDIR_CREATE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
    ULONG count = 1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
    APIRET rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   519
    BAIL_IF_MACRO(strlen(dirname) > sizeof (spec) - 5, ERR_OS_ERROR, NULL);
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   520
    strcpy(spec, dirname);
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   521
    strcat(spec, (spec[strlen(spec) - 1] != '\\') ? "\\*.*" : "*.*");
404
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
    rc = DosFindFirst(spec, &hdir,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
                      FILE_DIRECTORY | FILE_ARCHIVED |
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
                      FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM,
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   526
                      &fb, sizeof (fb), &count, FIL_STANDARD);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
    while (count == 1)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
    {
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   530
        if ((strcmp(fb.achName, ".") != 0) && (strcmp(fb.achName, "..") != 0))
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   531
            ret = __PHYSFS_addToLinkedStringList(ret, &p, fb.achName, -1);
404
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
        DosFindNext(hdir, &fb, sizeof (fb), &count);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
    } /* while */
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
    DosFindClose(hdir);
416
eadb08626c80 Lots of fixes...seems to be fully functional, now.
Ryan C. Gordon <icculus@icculus.org>
parents: 412
diff changeset
   537
    return(ret);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   538
} /* __PHYSFS_platformEnumerateFiles */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
char *__PHYSFS_platformCurrentDir(void)
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
    char *retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
    ULONG currentDisk;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
    ULONG dummy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
    ULONG pathSize = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
    APIRET rc;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
    BYTE byte;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
    rc = DosQueryCurrentDisk(&currentDisk, &dummy);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
    /* 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
   554
    rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
    pathSize++; /* Add space for null terminator. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
    retval = (char *) malloc(pathSize + 3);  /* plus "x:\\" */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
    /* Actually get the string this time. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
    rc = DosQueryCurrentDir(currentDisk, (PBYTE) (retval + 3), &pathSize);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
    if (os2err(rc) != NO_ERROR)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
        free(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
        return(NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
    } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
    retval[0] = ('A' + (currentDisk - 1));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
    retval[1] = ':';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
    retval[2] = '\\';
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
} /* __PHYSFS_platformCurrentDir */
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
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
char *__PHYSFS_platformRealPath(const char *path)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
    char buf[CCHMAXPATH];
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
    char *retval;
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   578
    APIRET rc = DosQueryPathInfo(path, FIL_QUERYFULLNAME, buf, sizeof (buf));
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
    retval = (char *) malloc(strlen(buf) + 1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
    strcpy(retval, buf);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   583
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
} /* __PHYSFS_platformRealPath */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
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
int __PHYSFS_platformMkDir(const char *path)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   589
    return(os2err(DosCreateDir(path, NULL)) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   590
} /* __PHYSFS_platformMkDir */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   591
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
void *__PHYSFS_platformOpenRead(const char *filename)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
    ULONG actionTaken = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
    HFILE hfile = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   597
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   598
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   599
     * File must be opened SHARE_DENYWRITE and ACCESS_READONLY, otherwise
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   600
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   602
    os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
                   OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
                   OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   605
                   OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   606
                   OPEN_ACCESS_READONLY, NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
    return((void *) hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
} /* __PHYSFS_platformOpenRead */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
void *__PHYSFS_platformOpenWrite(const char *filename)
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
    ULONG actionTaken = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
    HFILE hfile = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   617
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
     * File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   619
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
    os2err(DosOpen(filename, &hfile, &actionTaken, 0, FILE_NORMAL,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
                   OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   623
                   OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   624
                   OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
                   OPEN_ACCESS_READWRITE, NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
    return((void *) hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
} /* __PHYSFS_platformOpenWrite */
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
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
void *__PHYSFS_platformOpenAppend(const char *filename)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
    ULONG dummy = 0;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
    HFILE hfile = NULLHANDLE;
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   635
    APIRET rc;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
     * File must be opened SHARE_DENYWRITE and ACCESS_READWRITE, otherwise
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
     *  DosQueryFileInfo() will fail if we try to get a file length, etc.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
     */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
    rc = os2err(DosOpen(filename, &hfile, &dummy, 0, FILE_NORMAL,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
                   OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
                   OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_LOCALITY |
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   644
                   OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYWRITE |
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
                   OPEN_ACCESS_READWRITE, NULL));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
    if (rc == NO_ERROR)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
    {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
        if (os2err(DosSetFilePtr(hfile, 0, FILE_END, &dummy)) != NO_ERROR)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
        {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
            DosClose(hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
            hfile = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
    } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
    return((void *) hfile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
} /* __PHYSFS_platformOpenAppend */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
                                    PHYSFS_uint32 size, PHYSFS_uint32 count)
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
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   664
    PHYSFS_sint64 retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   665
    ULONG br;
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
    for (retval = 0; retval < count; retval++)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
    {
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   669
        os2err(DosRead(hfile, buffer, size, &br));
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   670
        if (br < size)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   671
        {
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   672
            DosSetFilePtr(hfile, -br, FILE_CURRENT, &br); /* try to cleanup. */
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   673
            return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   674
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   676
        buffer = (void *) ( ((char *) buffer) + size );
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   677
    } /* for */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   678
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   679
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   680
} /* __PHYSFS_platformRead */
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
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   683
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   684
                                     PHYSFS_uint32 size, PHYSFS_uint32 count)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   685
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   686
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   687
    PHYSFS_sint64 retval;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   688
    ULONG bw;
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
    for (retval = 0; retval < count; retval++)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   691
    {
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   692
        os2err(DosWrite(hfile, buffer, size, &bw));
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   693
        if (bw < size)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   694
        {
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   695
            DosSetFilePtr(hfile, -bw, FILE_CURRENT, &bw); /* try to cleanup. */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   696
            return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   697
        } /* if */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   698
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   699
        buffer = (void *) ( ((char *) buffer) + size );
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   700
    } /* for */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   701
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   702
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   703
} /* __PHYSFS_platformWrite */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   704
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   705
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   706
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   707
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   708
    ULONG dummy;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   709
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   710
    LONG dist = (LONG) pos;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   711
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   712
    /* hooray for 32-bit filesystem limits!  :) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   713
    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
   714
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   715
    return(os2err(DosSetFilePtr(hfile, dist, FILE_BEGIN, &dummy)) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   716
} /* __PHYSFS_platformSeek */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   717
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   718
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   719
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
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
    ULONG pos;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   722
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   723
    APIRET rc = os2err(DosSetFilePtr(hfile, 0, FILE_CURRENT, &pos));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   724
    BAIL_IF_MACRO(rc != NO_ERROR, NULL, -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   725
    return((PHYSFS_sint64) pos);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   726
} /* __PHYSFS_platformTell */
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_sint64 __PHYSFS_platformFileLength(void *opaque)
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
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   732
    HFILE hfile = (HFILE) opaque;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   733
    APIRET rc = DosQueryFileInfo(hfile, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   734
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   735
    return((PHYSFS_sint64) fs.cbFile);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   736
} /* __PHYSFS_platformFileLength */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   737
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   738
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   739
int __PHYSFS_platformEOF(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   740
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   741
    PHYSFS_sint64 len, pos;
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
    len = __PHYSFS_platformFileLength(opaque);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   744
    BAIL_IF_MACRO(len == -1, NULL, 1);  /* (*shrug*) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   745
    pos = __PHYSFS_platformTell(opaque);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   746
    BAIL_IF_MACRO(pos == -1, NULL, 1);  /* (*shrug*) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   747
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   748
    return(pos >= len);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   749
} /* __PHYSFS_platformEOF */
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
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   752
int __PHYSFS_platformFlush(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   753
{
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   754
    return(os2err(DosResetBuffer((HFILE) opaque) == NO_ERROR));
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   755
} /* __PHYSFS_platformFlush */
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
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   758
int __PHYSFS_platformClose(void *opaque)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   759
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   760
    return(os2err(DosClose((HFILE) opaque) == NO_ERROR));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   761
} /* __PHYSFS_platformClose */
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
int __PHYSFS_platformDelete(const char *path)
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
    if (__PHYSFS_platformIsDirectory(path))
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   767
        return(os2err(DosDeleteDir(path)) == NO_ERROR);
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
    return(os2err(DosDelete(path) == NO_ERROR));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   770
} /* __PHYSFS_platformDelete */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   771
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   772
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   773
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   774
{
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   775
    PHYSFS_sint64 retval;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   776
    struct tm tm;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   777
    FILESTATUS3 fs;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   778
    APIRET rc = DosQueryPathInfo(fname, FIL_STANDARD, &fs, sizeof (fs));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   779
    BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   780
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   781
    /* Convert to a format that mktime() can grok... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   782
    tm.tm_sec = ((PHYSFS_uint32) fs.ftimeLastWrite.twosecs) * 2;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   783
    tm.tm_min = fs.ftimeLastWrite.minutes;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   784
    tm.tm_hour = fs.ftimeLastWrite.hours;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   785
    tm.tm_mday = fs.fdateLastWrite.day;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   786
    tm.tm_mon = fs.fdateLastWrite.month;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   787
    tm.tm_year = ((PHYSFS_uint32) fs.fdateLastWrite.year) + 80;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   788
    tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   789
    tm.tm_yday = -1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   790
    tm.tm_isdst = -1;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   791
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   792
    /* Convert to a format PhysicsFS can grok... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   793
    retval = (PHYSFS_sint64) mktime(&tm);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   794
    BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   795
    return(retval);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   796
} /* __PHYSFS_platformGetLastModTime */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   797
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   798
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   799
/* 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
   800
void __PHYSFS_platformTimeslice(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   801
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   802
    DosSleep(10);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   803
} /* __PHYSFS_platformTimeslice(void) */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   804
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   805
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   806
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   807
{
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   808
    PTIB ptib;
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   809
    PPIB ppib;
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   810
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   811
    /*
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   812
     * Allegedly, this API never fails, but we'll punt and return a
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   813
     *  default value (zero might as well do) if it does.
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   814
     */
407
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   815
    BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, 0, 0);
81646aa3f6f8 Patched to compile...works a little.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   816
    return((PHYSFS_uint64) ptib->tib_ordinal);
404
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   817
} /* __PHYSFS_platformGetThreadID */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   818
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   819
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   820
void *__PHYSFS_platformCreateMutex(void)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   821
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   822
    HMTX hmtx = NULLHANDLE;
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   823
    os2err(DosCreateMutexSem(NULL, &hmtx, 0, 0));
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   824
    return((void *) hmtx);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   825
} /* __PHYSFS_platformCreateMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   826
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   827
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   828
void __PHYSFS_platformDestroyMutex(void *mutex)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   829
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   830
    DosCloseMutexSem((HMTX) mutex);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   831
} /* __PHYSFS_platformDestroyMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   832
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   833
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   834
int __PHYSFS_platformGrabMutex(void *mutex)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   835
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   836
    /* Do _NOT_ call os2err() (which sets the physfs error msg) in here! */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   837
    return(DosRequestMutexSem((HMTX) mutex, SEM_INDEFINITE_WAIT) == NO_ERROR);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   838
} /* __PHYSFS_platformGrabMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   839
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   840
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   841
void __PHYSFS_platformReleaseMutex(void *mutex)
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   842
{
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   843
    DosReleaseMutexSem((HMTX) mutex);
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   844
} /* __PHYSFS_platformReleaseMutex */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   845
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   846
#endif  /* defined OS2 */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   847
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   848
/* end of os2.c ... */
d08723d994c1 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   849