src/filesystem/haiku/SDL_sysfilesystem.cc
author Ryan C. Gordon <icculus@icculus.org>
Thu, 14 Nov 2013 11:51:24 -0500
changeset 7981 6d538bc1b395
parent 7883 src/filesystem/beos/SDL_sysfilesystem.cc@62f562a475e1
child 8093 b43765095a6f
permissions -rw-r--r--
Renamed things named after BeOS to be named after Haiku instead.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "SDL_config.h"
    22 
    23 #ifdef SDL_FILESYSTEM_HAIKU
    24 
    25 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    26 /* System dependent filesystem routines                                */
    27 
    28 #include <os/kernel/image.h>
    29 #include <os/storage/Directory.h>
    30 #include <os/storage/Entry.h>
    31 #include <os/storage/Path.h>
    32 
    33 #include "SDL_error.h"
    34 #include "SDL_stdinc.h"
    35 #include "SDL_assert.h"
    36 #include "SDL_filesystem.h"
    37 
    38 char *
    39 SDL_GetBasePath(void)
    40 {
    41     image_info info;
    42     int32 cookie = 0;
    43 
    44     while (get_next_image_info(0, &cookie, &info) == B_OK) {
    45         if (info.type == B_APP_IMAGE) {
    46             break;
    47         }
    48     }
    49 
    50     BEntry entry(info.name, true);
    51     BPath path;
    52     status_t rc = entry.GetPath(&path);  /* (path) now has binary's path. */
    53     SDL_assert(rc == B_OK);
    54     rc = path.GetParent(&path); /* chop filename, keep directory. */
    55     SDL_assert(rc == B_OK);
    56     const char *str = path.Path();
    57     SDL_assert(str != NULL);
    58 
    59     const size_t len = SDL_strlen(str);
    60     char *retval = (char *) SDL_malloc(len + 2);
    61     if (!retval) {
    62         SDL_OutOfMemory();
    63         return NULL;
    64     }
    65 
    66     SDL_memcpy(retval, str, len);
    67     retval[len] = '/';
    68     retval[len+1] = '\0';
    69     return retval;
    70 }
    71 
    72 
    73 char *
    74 SDL_GetPrefPath(const char *org, const char *app)
    75 {
    76     // !!! FIXME: is there a better way to do this?
    77     const char *home = SDL_getenv("HOME");
    78     const char *append = "config/settings/";
    79     const size_t len = SDL_strlen(home) + SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
    80     char *retval = (char *) SDL_malloc(len);
    81     if (!retval) {
    82         SDL_OutOfMemory();
    83     } else {
    84         SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
    85         create_directory(retval, 0700);  // Haiku api: creates missing dirs
    86     }
    87 
    88     return retval;
    89 }
    90 
    91 #endif /* SDL_FILESYSTEM_HAIKU */
    92 
    93 /* vi: set ts=4 sw=4 expandtab: */