src/physfs_platform_haiku.cpp
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1553 55b6495c3f17
permissions -rw-r--r--
7z: Make error handling a little more robust.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
1443
0e74405d587f Removed BeOS support (Haiku still supported, though!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1442
diff changeset
     2
 * Haiku platform-dependent support routines for PhysicsFS.
235
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
1443
0e74405d587f Removed BeOS support (Haiku still supported, though!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1442
diff changeset
    12
#ifdef PHYSFS_PLATFORM_HAIKU
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
#include <os/kernel/OS.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    15
#include <os/app/Roster.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    16
#include <os/storage/Volume.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    17
#include <os/storage/VolumeRoster.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    18
#include <os/storage/Directory.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    19
#include <os/storage/Entry.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    20
#include <os/storage/Path.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    21
#include <os/kernel/fs_info.h>
b0c91495af9b Haiku support.
Ryan C. Gordon <icculus@icculus.org>
parents: 854
diff changeset
    22
#include <os/device/scsi.h>
235
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 <errno.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
#include <unistd.h>
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#include "physfs_internal.h"
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
int __PHYSFS_platformInit(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
{
1231
8206d0e4cf49 Minor code style cleanup in platform_beos.cpp ...
Ryan C. Gordon <icculus@icculus.org>
parents: 1223
diff changeset
    31
    return 1;  /* always succeed. */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
} /* __PHYSFS_platformInit */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
1536
c791c9aaa2a2 __PHYSFS_platformDeinit() should return void.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
    35
void __PHYSFS_platformDeinit(void)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
{
1536
c791c9aaa2a2 __PHYSFS_platformDeinit() should return void.
Ryan C. Gordon <icculus@icculus.org>
parents: 1507
diff changeset
    37
    /* no-op */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
} /* __PHYSFS_platformDeinit */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    41
static char *getMountPoint(const char *devname, char *buf, size_t bufsize)
235
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
    BVolumeRoster mounts;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    BVolume vol;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
    mounts.Rewind();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    while (mounts.GetNextVolume(&vol) == B_NO_ERROR)
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
        fs_info fsinfo;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
        fs_stat_dev(vol.Device(), &fsinfo);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
        if (strcmp(devname, fsinfo.device_name) == 0)
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
            BDirectory directory;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
            BEntry entry;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
            BPath path;
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    56
            const char *str;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    57
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    58
            if ( (vol.GetRootDirectory(&directory) < B_OK) ||
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    59
                 (directory.GetEntry(&entry) < B_OK) ||
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    60
                 (entry.GetPath(&path) < B_OK) ||
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    61
                 ( (str = path.Path()) == NULL) )
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    62
                return NULL;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    63
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    64
            strncpy(buf, str, bufsize-1);
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    65
            buf[bufsize-1] = '\0';
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    66
            return buf;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
    } /* while */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
    70
    return NULL;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
} /* getMountPoint */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
    /*
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
     * This function is lifted from Simple Directmedia Layer (SDL):
1373
527ef3c6a2d6 HTTPS all the things.
Ryan C. Gordon <icculus@icculus.org>
parents: 1266
diff changeset
    76
     *  https://www.libsdl.org/  ... this is zlib-licensed code, too.
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
     */
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
    78
static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data)
235
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
    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
    81
    dir.SetTo(d);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    if (dir.InitCheck() != B_NO_ERROR)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
        return;
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
    dir.Rewind();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
    BEntry entry;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
    while (dir.GetNextEntry(&entry) >= 0)
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
        BPath path;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
        const char *name;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
        entry_ref e;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
        if (entry.GetPath(&path) != B_NO_ERROR)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
            continue;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
        name = path.Path();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
        if (entry.GetRef(&e) != B_NO_ERROR)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
            continue;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
        if (entry.IsDirectory())
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 (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
   104
                tryDir(name, callback, data);
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   105
            continue;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
        } /* if */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   108
        const int devfd = open(name, O_RDONLY);
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   109
        if (devfd < 0)
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   110
            continue;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
1223
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   112
        device_geometry g;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   113
        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
   114
        close(devfd);
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   115
        if (rc < 0)
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   116
            continue;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   117
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   118
        if (g.device_type != B_CD)
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   119
            continue;
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   120
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   121
        char mntpnt[B_FILE_NAME_LENGTH];
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   122
        if (getMountPoint(name, mntpnt, sizeof (mntpnt)))
0b8f11836561 Reworked BeOS CD detection code.
Ryan C. Gordon <icculus@icculus.org>
parents: 1213
diff changeset
   123
            callback(data, mntpnt);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
    } /* while */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
} /* tryDir */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   128
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
{
657
dad3b5c307a9 Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents: 504
diff changeset
   130
    tryDir("/dev/disk", cb, data);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
} /* __PHYSFS_platformDetectAvailableCDs */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
static team_id getTeamID(void)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
{
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
    thread_info info;
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    thread_id tid = find_thread(NULL);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    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
   139
    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
   140
} /* getTeamID */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
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
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
{
1133
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   145
    image_info info;
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   146
    int32 cookie = 0;
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   147
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   148
    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
   149
    {
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   150
        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
   151
            break;
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   152
    } /* while */
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   153
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   154
    BEntry entry(info.name, true);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
    BPath path;
1133
958df28c5449 Haiku fixes, merged from stable-2.0 branch.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   156
    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
   157
    assert(rc == B_OK);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
    rc = path.GetParent(&path); /* chop filename, keep directory. */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    assert(rc == B_OK);
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
    const char *str = path.Path();
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    assert(str != NULL);
1266
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
   162
    const size_t len = strlen(str);
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
   163
    char *retval = (char *) allocator.Malloc(len + 2);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
   164
    BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
    strcpy(retval, str);
1266
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
   166
    retval[len] = '/';
135cb99a06a0 More FIXME cleanup.
Ryan C. Gordon <icculus@icculus.org>
parents: 1264
diff changeset
   167
    retval[len+1] = '\0';
1231
8206d0e4cf49 Minor code style cleanup in platform_beos.cpp ...
Ryan C. Gordon <icculus@icculus.org>
parents: 1223
diff changeset
   168
    return retval;
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
} /* __PHYSFS_platformCalcBaseDir */
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
1242
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
   172
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
   173
{
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
   174
    const char *userdir = __PHYSFS_getUserDir();
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
   175
    const char *append = "config/settings/";
1246
4fa9fe3e0b52 Make sure the prefdir has a final dirsep on it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
   176
    const size_t len = strlen(userdir) + strlen(append) + strlen(app) + 2;
1433
257e297ed9d3 Patched to compile on BeOS/Haiku.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
   177
    char *retval = (char *) allocator.Malloc(len);
1402
c5a5dadb901d Cleanup BAIL_* and GOTO_* macros to be less cluttered.
Ryan C. Gordon <icculus@icculus.org>
parents: 1373
diff changeset
   178
    BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
1246
4fa9fe3e0b52 Make sure the prefdir has a final dirsep on it.
Ryan C. Gordon <icculus@icculus.org>
parents: 1242
diff changeset
   179
    snprintf(retval, len, "%s%s%s/", userdir, append, app);
1242
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
   180
    return retval;
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
   181
} /* __PHYSFS_platformCalcPrefDir */
1e6db80d2393 Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents: 1240
diff changeset
   182
1443
0e74405d587f Removed BeOS support (Haiku still supported, though!).
Ryan C. Gordon <icculus@icculus.org>
parents: 1442
diff changeset
   183
#endif  /* PHYSFS_PLATFORM_HAIKU */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
1507
8953b8a171e7 Update filename comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 1506
diff changeset
   185
/* end of physfs_platform_haiku.cpp ... */
235
4ad12914f652 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186