platform/beos.cpp
author Ryan C. Gordon <icculus@icculus.org>
Sun, 11 Mar 2007 22:50:53 +0000
changeset 818 e36f23f49042
parent 809 116b8fe30371
child 838 257f0f83e012
permissions -rw-r--r--
Now compiles everything whether we need it or not, removing whole files with #ifdefs...this will make it easier to "embed" this library in other projects or use a different build system: just push everything through the compiler with preprocessor defines for the parts you want/need...platform modules are determined automatically without the build system needing to intervene, so you just have to #define the archivers, etc that you want.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
 * BeOS platform-dependent support routines for PhysicsFS.
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
809
116b8fe30371 Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 *  This file written by Ryan C. Gordon.
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
818
e36f23f49042 Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
     9
#define __PHYSICSFS_INTERNAL__
e36f23f49042 Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
    10
#include "physfs_platforms.h"
e36f23f49042 Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
    11
e36f23f49042 Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
    12
#ifdef PHYSFS_PLATFORM_BEOS
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <be/kernel/OS.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include <be/app/Roster.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#include <be/storage/Volume.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include <be/storage/VolumeRoster.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
#include <be/storage/Directory.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#include <be/storage/Entry.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
#include <be/storage/Path.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#include <be/kernel/fs_info.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#include <be/device/scsi.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
#include <stdio.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
#include <stdlib.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#include <string.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#include <errno.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#include <unistd.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
#include "physfs_internal.h"
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
const char *__PHYSFS_platformDirSeparator = "/";
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
int __PHYSFS_platformInit(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
    return(1);  /* always succeed. */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
} /* __PHYSFS_platformInit */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
int __PHYSFS_platformDeinit(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    return(1);  /* always succeed. */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
} /* __PHYSFS_platformDeinit */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
static char *getMountPoint(const char *devname)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    BVolumeRoster mounts;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
    BVolume vol;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
    mounts.Rewind();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    while (mounts.GetNextVolume(&vol) == B_NO_ERROR)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
        fs_info fsinfo;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
        fs_stat_dev(vol.Device(), &fsinfo);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
        if (strcmp(devname, fsinfo.device_name) == 0)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
        {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
            //char buf[B_FILE_NAME_LENGTH];
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
            BDirectory directory;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
            BEntry entry;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
            BPath path;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
            status_t rc;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
            rc = vol.GetRootDirectory(&directory);
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
    66
            BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
            rc = directory.GetEntry(&entry);
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
    68
            BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
            rc = entry.GetPath(&path);
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
    70
            BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
            const char *str = path.Path();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
            BAIL_IF_MACRO(str == NULL, ERR_OS_ERROR, NULL);  /* ?! */
745
df04959950eb Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
    73
            char *retval = (char *) allocator.Malloc(strlen(str) + 1);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
            BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
            strcpy(retval, str);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
            return(retval);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
        } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    } /* while */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
    return(NULL);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
} /* getMountPoint */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
    /*
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
     * This function is lifted from Simple Directmedia Layer (SDL):
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
     *  http://www.libsdl.org/
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
     */
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
    88
static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
    BDirectory dir;
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
    91
    dir.SetTo(d);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    if (dir.InitCheck() != B_NO_ERROR)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
        return;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
    dir.Rewind();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
    BEntry entry;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    while (dir.GetNextEntry(&entry) >= 0)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
        BPath path;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
        const char *name;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
        entry_ref e;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
        if (entry.GetPath(&path) != B_NO_ERROR)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
            continue;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
        name = path.Path();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
        if (entry.GetRef(&e) != B_NO_ERROR)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
            continue;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
        if (entry.IsDirectory())
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
        {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
            if (strcmp(e.name, "floppy") != 0)
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   114
                tryDir(name, callback, data);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
        } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
        else
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
        {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
            bool add_it = false;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
            int devfd;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
            device_geometry g;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
            if (strcmp(e.name, "raw") == 0)  /* ignore partitions. */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
            {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
                int devfd = open(name, O_RDONLY);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
                if (devfd >= 0)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
                {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
                    if (ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
                    {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
                        if (g.device_type == B_CD)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
                        {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
                            char *mntpnt = getMountPoint(name);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
                            if (mntpnt != NULL)
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   134
                            {
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   135
                                callback(data, mntpnt);
745
df04959950eb Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   136
                                allocator.Free(mntpnt);  /* !!! FIXME: lose this malloc! */
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   137
                            } /* if */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
                        } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
                    } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
                } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
            } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
            close(devfd);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
        } /* else */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
    } /* while */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
} /* tryDir */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   149
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
{
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   151
    tryDir("/dev/disk", cb, data);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
} /* __PHYSFS_platformDetectAvailableCDs */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
static team_id getTeamID(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
    thread_info info;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    thread_id tid = find_thread(NULL);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    get_thread_info(tid, &info);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
    return(info.team);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
} /* getMyTeamID */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
    /* in case there isn't a BApplication yet, we'll construct a roster. */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
    BRoster roster; 
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
    app_info info;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
    status_t rc = roster.GetRunningAppInfo(getTeamID(), &info);
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   170
    BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
    BEntry entry(&(info.ref), true);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
    BPath path;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    rc = entry.GetPath(&path);  /* (path) now has binary's path. */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
    assert(rc == B_OK);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    rc = path.GetParent(&path); /* chop filename, keep directory. */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    assert(rc == B_OK);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    const char *str = path.Path();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    assert(str != NULL);
745
df04959950eb Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   179
    char *retval = (char *) allocator.Malloc(strlen(str) + 1);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
    strcpy(retval, str);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
    return(retval);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
} /* __PHYSFS_platformCalcBaseDir */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
    return((PHYSFS_uint64) find_thread(NULL));
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
} /* __PHYSFS_platformGetThreadID */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
/* Much like my college days, try to sleep for 10 milliseconds at a time... */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
void __PHYSFS_platformTimeslice(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    snooze(10000);  /* put thread to sleep for 10 milliseconds. */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
} /* __PHYSFS_platformTimeslice */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
char *__PHYSFS_platformRealPath(const char *path)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
{
788
3df4f1b61339 Apparently BeOS's BPath constructor doesn't actually _need_ leaf to be
Ryan C. Gordon <icculus@icculus.org>
parents: 745
diff changeset
   201
    BPath normalized(path, NULL, true);  /* force normalization of path. */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
    const char *resolved_path = normalized.Path();
362
ac8c846a0a66 Changed enumeration code to use __PHYSFS_addToLinkedStringList().
Ryan C. Gordon <icculus@icculus.org>
parents: 327
diff changeset
   203
    BAIL_IF_MACRO(resolved_path == NULL, ERR_NO_SUCH_FILE, NULL);
745
df04959950eb Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   204
    char *retval = (char *) allocator.Malloc(strlen(resolved_path) + 1);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
    strcpy(retval, resolved_path);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
    return(retval);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
} /* __PHYSFS_platformRealPath */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
void *__PHYSFS_platformCreateMutex(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
{
745
df04959950eb Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   213
    sem_id *retval = (sem_id *) allocator.Malloc(sizeof (sem_id));
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
    sem_id rc;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
    rc = create_sem(1, "PhysicsFS semaphore");
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
    if (rc < B_OK)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
    {
745
df04959950eb Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   220
        allocator.Free(retval);
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   221
        BAIL_MACRO(strerror(rc), NULL);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
    } // if
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    *retval = rc;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    return(retval);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
} /* __PHYSFS_platformCreateMutex */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
void __PHYSFS_platformDestroyMutex(void *mutex)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
    delete_sem( *((sem_id *) mutex) );
745
df04959950eb Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   232
    allocator.Free(mutex);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
} /* __PHYSFS_platformDestroyMutex */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
int __PHYSFS_platformGrabMutex(void *mutex)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
    status_t rc = acquire_sem(*((sem_id *) mutex));
393
468f75bf4d7d Minor cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 362
diff changeset
   239
    BAIL_IF_MACRO(rc < B_OK, strerror(rc), 0);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
    return(1);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
} /* __PHYSFS_platformGrabMutex */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
void __PHYSFS_platformReleaseMutex(void *mutex)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
    release_sem(*((sem_id *) mutex));
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
} /* __PHYSFS_platformReleaseMutex */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
818
e36f23f49042 Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents: 809
diff changeset
   249
#endif  /* PHYSFS_PLATFORM_BEOS */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
/* end of beos.cpp ... */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252