Atlas - SDL_sysfilesystem.c
Home / ext / SDL / src / filesystem / dos Lines: 1 | Size: 2768 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 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_DOS 24 25#include <dir.h> 26#include <sys/stat.h> 27 28/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 29// System dependent filesystem routines 30 31#include "../SDL_sysfilesystem.h" 32 33char *SDL_SYS_GetBasePath(void) 34{ 35 extern const char *SDL_argv0; // from src/main/dos/SDL_sysmain_runapp.c 36 char *searched = searchpath(SDL_argv0); 37 if (!searched) { 38 SDL_SetError("argv[0] not found by searchpath"); 39 return NULL; 40 } 41 42 char *fullpath = SDL_strdup(searched); 43 if (!fullpath) { 44 return NULL; 45 } 46 47 // I don't know if this is a good idea. Drop DOS path separators, use Unix style instead. 48 char *ptr; 49 for (ptr = fullpath; *ptr; ptr++) { 50 if (*ptr == '\\') { 51 *ptr = '/'; 52 } 53 } 54 55 // drop the .exe name. 56 ptr = SDL_strrchr(fullpath, '/'); 57 if (ptr) { 58 ptr[1] = '\0'; 59 } 60 61 return fullpath; 62} 63 64char *SDL_SYS_GetPrefPath(const char *org, const char *app) 65{ 66 char *result = NULL; 67 size_t len; 68 if (!app) { 69 SDL_InvalidParamError("app"); 70 return NULL; 71 } 72 73 const char *base = SDL_GetBasePath(); 74 if (!base) { 75 return NULL; 76 } 77 78 if (!org) { 79 org = ""; 80 } 81 82 len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4; 83 result = (char *)SDL_malloc(len); 84 if (result) { 85 if (*org) { 86 SDL_snprintf(result, len, "%s%s", base, org); 87 mkdir(result, 0755); 88 SDL_snprintf(result, len, "%s%s/%s/", base, org, app); 89 } else { 90 SDL_snprintf(result, len, "%s%s/", base, app); 91 } 92 93 mkdir(result, 0755); 94 } 95 96 return result; 97} 98 99char *SDL_SYS_GetUserFolder(SDL_Folder folder) 100{ 101 SDL_Unsupported(); 102 return NULL; 103} 104 105#endif // SDL_FILESYSTEM_DOS 106[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.