|
| 1 | +/* |
| 2 | + Simple DirectMedia Layer |
| 3 | + Copyright (C) 1997-2019 Sam Lantinga <[email protected]> |
| 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_internal.h" |
| 22 | + |
| 23 | +#ifdef SDL_FILESYSTEM_RISCOS |
| 24 | + |
| 25 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 26 | +/* System dependent filesystem routines */ |
| 27 | + |
| 28 | +#include <errno.h> |
| 29 | +#include <sys/stat.h> |
| 30 | + |
| 31 | +#include "SDL_error.h" |
| 32 | +#include "SDL_stdinc.h" |
| 33 | +#include "SDL_filesystem.h" |
| 34 | +#include "SDL_rwops.h" |
| 35 | + |
| 36 | +char * |
| 37 | +SDL_GetBasePath(void) |
| 38 | +{ |
| 39 | + SDL_Unsupported(); |
| 40 | + return NULL; |
| 41 | +} |
| 42 | + |
| 43 | +char * |
| 44 | +SDL_GetPrefPath(const char *org, const char *app) |
| 45 | +{ |
| 46 | + const char *prefix = "/<Choices$Write>/"; |
| 47 | + char *retval = NULL; |
| 48 | + char *ptr = NULL; |
| 49 | + size_t len = 0; |
| 50 | + |
| 51 | + if (!app) { |
| 52 | + SDL_InvalidParamError("app"); |
| 53 | + return NULL; |
| 54 | + } |
| 55 | + if (!org) { |
| 56 | + org = ""; |
| 57 | + } |
| 58 | + |
| 59 | + len = SDL_strlen(prefix) + SDL_strlen(org) + SDL_strlen(app) + 3; |
| 60 | + retval = (char *) SDL_malloc(len); |
| 61 | + if (!retval) { |
| 62 | + SDL_OutOfMemory(); |
| 63 | + return NULL; |
| 64 | + } |
| 65 | + |
| 66 | + if (*org) { |
| 67 | + SDL_snprintf(retval, len, "%s%s/%s/", prefix, org, app); |
| 68 | + } else { |
| 69 | + SDL_snprintf(retval, len, "%s%s/", prefix, app); |
| 70 | + } |
| 71 | + |
| 72 | + for (ptr = retval+1; *ptr; ptr++) { |
| 73 | + if (*ptr == '/') { |
| 74 | + *ptr = '\0'; |
| 75 | + if (mkdir(retval, 0700) != 0 && errno != EEXIST) |
| 76 | + goto error; |
| 77 | + *ptr = '/'; |
| 78 | + } |
| 79 | + } |
| 80 | + if (mkdir(retval, 0700) != 0 && errno != EEXIST) { |
| 81 | +error: |
| 82 | + SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno)); |
| 83 | + SDL_free(retval); |
| 84 | + return NULL; |
| 85 | + } |
| 86 | + |
| 87 | + return retval; |
| 88 | +} |
| 89 | + |
| 90 | +#endif /* SDL_FILESYSTEM_RISCOS */ |
| 91 | + |
| 92 | +/* vi: set ts=4 sw=4 expandtab: */ |
0 commit comments