testfilesystem.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely.
  9. */
  10. /* Simple test of filesystem functions. */
  11. #include <stdio.h>
  12. #include "SDL.h"
  13. int
  14. main(int argc, char *argv[])
  15. {
  16. char *base_path;
  17. char *pref_path;
  18. /* Enable standard application logging */
  19. SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  20. if (SDL_Init(0) == -1) {
  21. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
  22. return 1;
  23. }
  24. base_path = SDL_GetBasePath();
  25. if(base_path == NULL){
  26. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
  27. SDL_GetError());
  28. } else {
  29. SDL_Log("base path: '%s'\n", base_path);
  30. SDL_free(base_path);
  31. }
  32. pref_path = SDL_GetPrefPath("libsdl", "testfilesystem");
  33. if(pref_path == NULL){
  34. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n",
  35. SDL_GetError());
  36. } else {
  37. SDL_Log("pref path: '%s'\n", pref_path);
  38. SDL_free(pref_path);
  39. }
  40. pref_path = SDL_GetPrefPath(NULL, "testfilesystem");
  41. if(pref_path == NULL){
  42. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n",
  43. SDL_GetError());
  44. } else {
  45. SDL_Log("pref path: '%s'\n", pref_path);
  46. SDL_free(pref_path);
  47. }
  48. SDL_Quit();
  49. return 0;
  50. }