SDL_sysfilesystem.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #ifdef SDL_FILESYSTEM_N3DS
  20. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  21. // System dependent filesystem routines
  22. #include "../SDL_sysfilesystem.h"
  23. #include <3ds.h>
  24. #include <dirent.h>
  25. #include <errno.h>
  26. static char *MakePrefPath(const char *app);
  27. static bool CreatePrefPathDir(const char *pref);
  28. char *SDL_SYS_GetBasePath(void)
  29. {
  30. char *base_path = SDL_strdup("romfs:/");
  31. return base_path;
  32. }
  33. char *SDL_SYS_GetPrefPath(const char *org, const char *app)
  34. {
  35. char *pref_path = NULL;
  36. pref_path = MakePrefPath(app);
  37. if (!pref_path) {
  38. return NULL;
  39. }
  40. if (!CreatePrefPathDir(pref_path)) {
  41. SDL_free(pref_path);
  42. return NULL;
  43. }
  44. return pref_path;
  45. }
  46. // TODO
  47. char *SDL_SYS_GetUserFolder(SDL_Folder folder)
  48. {
  49. SDL_Unsupported();
  50. return NULL;
  51. }
  52. static char *MakePrefPath(const char *app)
  53. {
  54. char *pref_path;
  55. if (SDL_asprintf(&pref_path, "sdmc:/3ds/%s/", app) < 0) {
  56. return NULL;
  57. }
  58. return pref_path;
  59. }
  60. static bool CreatePrefPathDir(const char *pref)
  61. {
  62. int result = mkdir(pref, 0666);
  63. if (result == -1 && errno != EEXIST) {
  64. return SDL_SetError("Failed to create '%s' (%s)", pref, strerror(errno));
  65. }
  66. return true;
  67. }
  68. #endif // SDL_FILESYSTEM_N3DS