src/filesystem/haiku/SDL_sysfilesystem.cc
author Ryan C. Gordon <icculus@icculus.org>
Thu, 21 Apr 2016 03:16:44 -0400
changeset 11729 d1ce8396c356
parent 11222 083133ba8f9b
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Initial shot at a renderer target for Apple's Metal API.

This isn't complete, but is enough to run testsprite2. It's currently
Mac-only; with a little work to figure out how to properly glue in a Metal
layer to a UIView, this will likely work on iOS, too.

This is only wired up to the configure script right now, and disabled by
default. CMake and Xcode still need their bits filled in as appropriate.
icculus@7667
     1
/*
icculus@7667
     2
  Simple DirectMedia Layer
slouken@10737
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
icculus@7667
     4
icculus@7667
     5
  This software is provided 'as-is', without any express or implied
icculus@7667
     6
  warranty.  In no event will the authors be held liable for any damages
icculus@7667
     7
  arising from the use of this software.
icculus@7667
     8
icculus@7667
     9
  Permission is granted to anyone to use this software for any purpose,
icculus@7667
    10
  including commercial applications, and to alter it and redistribute it
icculus@7667
    11
  freely, subject to the following restrictions:
icculus@7667
    12
icculus@7667
    13
  1. The origin of this software must not be misrepresented; you must not
icculus@7667
    14
     claim that you wrote the original software. If you use this software
icculus@7667
    15
     in a product, an acknowledgment in the product documentation would be
icculus@7667
    16
     appreciated but is not required.
icculus@7667
    17
  2. Altered source versions must be plainly marked as such, and must not be
icculus@7667
    18
     misrepresented as being the original software.
icculus@7667
    19
  3. This notice may not be removed or altered from any source distribution.
icculus@7667
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
icculus@7667
    22
icculus@7981
    23
#ifdef SDL_FILESYSTEM_HAIKU
icculus@7667
    24
icculus@7667
    25
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
icculus@7667
    26
/* System dependent filesystem routines                                */
icculus@7667
    27
philipp@11164
    28
#include <kernel/image.h>
philipp@11164
    29
#include <storage/Directory.h>
philipp@11164
    30
#include <storage/Entry.h>
philipp@11164
    31
#include <storage/Path.h>
icculus@7667
    32
icculus@7667
    33
#include "SDL_error.h"
icculus@7667
    34
#include "SDL_stdinc.h"
icculus@7667
    35
#include "SDL_assert.h"
icculus@7667
    36
#include "SDL_filesystem.h"
icculus@7667
    37
icculus@7667
    38
char *
icculus@7667
    39
SDL_GetBasePath(void)
icculus@7667
    40
{
icculus@7667
    41
    image_info info;
icculus@7667
    42
    int32 cookie = 0;
icculus@7667
    43
icculus@7667
    44
    while (get_next_image_info(0, &cookie, &info) == B_OK) {
icculus@7667
    45
        if (info.type == B_APP_IMAGE) {
icculus@7667
    46
            break;
icculus@7667
    47
        }
icculus@7667
    48
    }
icculus@7667
    49
icculus@7667
    50
    BEntry entry(info.name, true);
icculus@7667
    51
    BPath path;
icculus@7667
    52
    status_t rc = entry.GetPath(&path);  /* (path) now has binary's path. */
icculus@7667
    53
    SDL_assert(rc == B_OK);
icculus@7667
    54
    rc = path.GetParent(&path); /* chop filename, keep directory. */
icculus@7667
    55
    SDL_assert(rc == B_OK);
icculus@7667
    56
    const char *str = path.Path();
icculus@7667
    57
    SDL_assert(str != NULL);
icculus@7667
    58
icculus@7667
    59
    const size_t len = SDL_strlen(str);
icculus@7667
    60
    char *retval = (char *) SDL_malloc(len + 2);
icculus@7667
    61
    if (!retval) {
icculus@7667
    62
        SDL_OutOfMemory();
icculus@7667
    63
        return NULL;
icculus@7667
    64
    }
icculus@7667
    65
icculus@7676
    66
    SDL_memcpy(retval, str, len);
icculus@7667
    67
    retval[len] = '/';
icculus@7667
    68
    retval[len+1] = '\0';
icculus@7667
    69
    return retval;
icculus@7667
    70
}
icculus@7667
    71
icculus@7667
    72
icculus@7667
    73
char *
icculus@7667
    74
SDL_GetPrefPath(const char *org, const char *app)
icculus@7667
    75
{
icculus@7667
    76
    // !!! FIXME: is there a better way to do this?
icculus@7667
    77
    const char *home = SDL_getenv("HOME");
philipp@11106
    78
    const char *append = "/config/settings/";
philipp@11106
    79
    size_t len = SDL_strlen(home);
slouken@11222
    80
slouken@11222
    81
    if (!app) {
slouken@11222
    82
        SDL_InvalidParamError("app");
slouken@11222
    83
        return NULL;
slouken@11222
    84
    }
slouken@11222
    85
    if (!org) {
slouken@11222
    86
        org = "";
slouken@11222
    87
    }
slouken@11222
    88
philipp@11106
    89
    if (!len || (home[len - 1] == '/')) {
philipp@11106
    90
        ++append; // home empty or ends with separator, skip the one from append
philipp@11106
    91
    }
philipp@11106
    92
    len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
icculus@7667
    93
    char *retval = (char *) SDL_malloc(len);
icculus@7667
    94
    if (!retval) {
icculus@7667
    95
        SDL_OutOfMemory();
icculus@7667
    96
    } else {
slouken@11222
    97
        if (*org) {
slouken@11222
    98
            SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
slouken@11222
    99
        } else {
slouken@11222
   100
            SDL_snprintf(retval, len, "%s%s%s/", home, append, app);
slouken@11222
   101
        }
icculus@7981
   102
        create_directory(retval, 0700);  // Haiku api: creates missing dirs
icculus@7667
   103
    }
icculus@7667
   104
icculus@7667
   105
    return retval;
icculus@7667
   106
}
icculus@7667
   107
icculus@7981
   108
#endif /* SDL_FILESYSTEM_HAIKU */
icculus@7667
   109
icculus@7667
   110
/* vi: set ts=4 sw=4 expandtab: */