src/platform_beos.cpp
author Ryan C. Gordon <icculus@icculus.org>
Mon, 19 Mar 2012 02:58:41 -0400
changeset 1231 8206d0e4cf49
parent 1223 0b8f11836561
child 1240 22d4d1bd4e21
permissions -rw-r--r--
Minor code style cleanup in platform_beos.cpp ...
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
947
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    14
#ifdef PHYSFS_PLATFORM_HAIKU
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    15
#include <os/kernel/OS.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    16
#include <os/app/Roster.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    17
#include <os/storage/Volume.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    18
#include <os/storage/VolumeRoster.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    19
#include <os/storage/Directory.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    20
#include <os/storage/Entry.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    21
#include <os/storage/Path.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    22
#include <os/kernel/fs_info.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    23
#include <os/device/scsi.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    24
#include <os/support/Locker.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    25
#else
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#include <be/kernel/OS.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#include <be/app/Roster.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#include <be/storage/Volume.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
#include <be/storage/VolumeRoster.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
#include <be/storage/Directory.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
#include <be/storage/Entry.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
#include <be/storage/Path.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
#include <be/kernel/fs_info.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
#include <be/device/scsi.h>
854
6c3ebc2e627a Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents: 847
diff changeset
    35
#include <be/support/Locker.h>
947
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    36
#endif
235
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
#include <errno.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
#include <unistd.h>
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
#include "physfs_internal.h"
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
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
int __PHYSFS_platformInit(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
{
1231
8206d0e4cf49 Minor code style cleanup in platform_beos.cpp ...
Ryan C. Gordon <icculus@icculus.org>
parents: 1223
diff changeset
    46
    return 1;  /* always succeed. */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
} /* __PHYSFS_platformInit */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
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
int __PHYSFS_platformDeinit(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
{
1231
8206d0e4cf49 Minor code style cleanup in platform_beos.cpp ...
Ryan C. Gordon <icculus@icculus.org>
parents: 1223
diff changeset
    52
    return 1;  /* always succeed. */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
} /* __PHYSFS_platformDeinit */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    56
static char *getMountPoint(const char *devname, char *buf, size_t bufsize)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    BVolumeRoster mounts;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    BVolume vol;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    mounts.Rewind();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    while (mounts.GetNextVolume(&vol) == B_NO_ERROR)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
        fs_info fsinfo;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
        fs_stat_dev(vol.Device(), &fsinfo);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
        if (strcmp(devname, fsinfo.device_name) == 0)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
            BDirectory directory;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
            BEntry entry;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
            BPath path;
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    71
            const char *str;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    72
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    73
            if ( (vol.GetRootDirectory(&directory) < B_OK) ||
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    74
                 (directory.GetEntry(&entry) < B_OK) ||
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    75
                 (entry.GetPath(&path) < B_OK) ||
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    76
                 ( (str = path.Path()) == NULL) )
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    77
                return NULL;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    78
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    79
            strncpy(buf, str, bufsize-1);
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    80
            buf[bufsize-1] = '\0';
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    81
            return buf;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
        } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
    } /* while */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    85
    return NULL;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
} /* getMountPoint */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
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
     * This function is lifted from Simple Directmedia Layer (SDL):
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    91
     *  http://www.libsdl.org/  ... this is zlib-licensed code, too.
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
     */
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
    93
static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data)
235
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
    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
    96
    dir.SetTo(d);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    if (dir.InitCheck() != B_NO_ERROR)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
        return;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
    dir.Rewind();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
    BEntry entry;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
    while (dir.GetNextEntry(&entry) >= 0)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
    {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
        BPath path;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
        const char *name;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
        entry_ref e;
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.GetPath(&path) != 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
        name = path.Path();
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 (entry.GetRef(&e) != B_NO_ERROR)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
            continue;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
        if (entry.IsDirectory())
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
        {
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
            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
   119
                tryDir(name, callback, data);
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   120
            continue;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
        } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   123
        if (strcmp(e.name, "raw") != 0)  /* ignore partitions. */
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   124
            continue;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   125
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   126
        const int devfd = open(name, O_RDONLY);
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   127
        if (devfd < 0)
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   128
            continue;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   130
        device_geometry g;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   131
        const int rc = ioctl(devfd, B_GET_GEOMETRY, &g, sizeof (g));
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   132
        close(devfd);
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   133
        if (rc < 0)
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   134
            continue;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   135
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   136
        if (g.device_type != B_CD)
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   137
            continue;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   138
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   139
        char mntpnt[B_FILE_NAME_LENGTH];
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   140
        if (getMountPoint(name, mntpnt, sizeof (mntpnt)))
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   141
            callback(data, mntpnt);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    } /* while */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
} /* tryDir */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   146
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
{
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   148
    tryDir("/dev/disk", cb, data);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
} /* __PHYSFS_platformDetectAvailableCDs */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
static team_id getTeamID(void)
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
    thread_info info;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
    thread_id tid = find_thread(NULL);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
    get_thread_info(tid, &info);
1231
8206d0e4cf49 Minor code style cleanup in platform_beos.cpp ...
Ryan C. Gordon <icculus@icculus.org>
parents: 1223
diff changeset
   157
    return info.team;
847
5e5e6c067413 Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents: 845
diff changeset
   158
} /* getTeamID */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
{
1133
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   163
    image_info info;
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   164
    int32 cookie = 0;
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   165
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   166
    while (get_next_image_info(0, &cookie, &info) == B_OK)
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   167
    {
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   168
        if (info.type == B_APP_IMAGE)
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   169
            break;
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   170
    } /* while */
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   171
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   172
    BEntry entry(info.name, true);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
    BPath path;
1133
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   174
    status_t rc = entry.GetPath(&path);  /* (path) now has binary's path. */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
    assert(rc == B_OK);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
    rc = path.GetParent(&path); /* chop filename, keep directory. */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
    assert(rc == B_OK);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
    const char *str = path.Path();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    assert(str != NULL);
745
df04959950eb Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents: 657
diff changeset
   180
    char *retval = (char *) allocator.Malloc(strlen(str) + 1);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
    BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
    strcpy(retval, str);
1231
8206d0e4cf49 Minor code style cleanup in platform_beos.cpp ...
Ryan C. Gordon <icculus@icculus.org>
parents: 1223
diff changeset
   183
    return retval;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
} /* __PHYSFS_platformCalcBaseDir */
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
1012
f254870dd7dd Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents: 972
diff changeset
   187
void *__PHYSFS_platformGetThreadID(void)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
{
1231
8206d0e4cf49 Minor code style cleanup in platform_beos.cpp ...
Ryan C. Gordon <icculus@icculus.org>
parents: 1223
diff changeset
   189
    return (void *) find_thread(NULL);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
} /* __PHYSFS_platformGetThreadID */
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
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
void *__PHYSFS_platformCreateMutex(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
{
1231
8206d0e4cf49 Minor code style cleanup in platform_beos.cpp ...
Ryan C. Gordon <icculus@icculus.org>
parents: 1223
diff changeset
   195
    return new BLocker("PhysicsFS lock", true);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
} /* __PHYSFS_platformCreateMutex */
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
void __PHYSFS_platformDestroyMutex(void *mutex)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
{
854
6c3ebc2e627a Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents: 847
diff changeset
   201
    delete ((BLocker *) mutex);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
} /* __PHYSFS_platformDestroyMutex */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
int __PHYSFS_platformGrabMutex(void *mutex)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
{
854
6c3ebc2e627a Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents: 847
diff changeset
   207
    return ((BLocker *) mutex)->Lock() ? 1 : 0;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
} /* __PHYSFS_platformGrabMutex */
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_platformReleaseMutex(void *mutex)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
{
854
6c3ebc2e627a Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents: 847
diff changeset
   213
    ((BLocker *) mutex)->Unlock();
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
} /* __PHYSFS_platformReleaseMutex */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
845
3f150ffcf50c Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   216
3f150ffcf50c Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   217
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
3f150ffcf50c Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   218
{
1231
8206d0e4cf49 Minor code style cleanup in platform_beos.cpp ...
Ryan C. Gordon <icculus@icculus.org>
parents: 1223
diff changeset
   219
    return 0;  /* just use malloc() and friends. */
845
3f150ffcf50c Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   220
} /* __PHYSFS_platformSetDefaultAllocator */
3f150ffcf50c Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents: 844
diff changeset
   221
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
   222
#endif  /* PHYSFS_PLATFORM_BEOS */
235
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
/* end of beos.cpp ... */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225