zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_sysfilesystem.cc
Go to the documentation of this file.
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_BEOS
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) {
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(app) + 2;
80  char *retval = (char *) SDL_malloc(len);
81  if (!retval) {
83  } else {
84  SDL_snprintf(retval, len, "%s%s%s/", home, append, app);
85  create_directory(retval, 0700); // BeOS api: creates missing dirs
86  }
87 
88  return retval;
89 }
90 
91 #endif /* SDL_FILESYSTEM_BEOS */
92 
93 /* vi: set ts=4 sw=4 expandtab: */
#define NULL
Definition: ftobjs.h:61
DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt,...)
Definition: SDL_string.c:1277
DECLSPEC char *SDLCALL SDL_GetPrefPath(const char *org, const char *app)
Get the user-and-app-specific path where files can be written.
GLenum GLsizei len
Definition: glew.h:7035
GLsizei const GLchar *const * path
Definition: glew.h:5828
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
#define SDL_assert(condition)
Definition: SDL_assert.h:159
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
Definition: SDL_string.c:389
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
Definition: SDL_string.c:293
Include file for filesystem SDL API functions.
DECLSPEC char *SDLCALL SDL_getenv(const char *name)
Definition: SDL_getenv.c:179
#define str(s)
DECLSPEC char *SDLCALL SDL_GetBasePath(void)
Get the path where the application resides.