user.odin 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package os2
  2. import "base:runtime"
  3. @(require_results)
  4. user_cache_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
  5. #partial switch ODIN_OS {
  6. case .Windows:
  7. dir = get_env("LocalAppData", allocator)
  8. if dir != "" {
  9. dir = clone_string(dir, allocator) or_return
  10. }
  11. case .Darwin:
  12. dir = get_env("HOME", allocator)
  13. if dir != "" {
  14. dir = concatenate({dir, "/Library/Caches"}, allocator) or_return
  15. }
  16. case: // All other UNIX systems
  17. dir = get_env("XDG_CACHE_HOME", allocator)
  18. if dir == "" {
  19. dir = get_env("HOME", allocator)
  20. if dir == "" {
  21. return
  22. }
  23. dir = concatenate({dir, "/.cache"}, allocator) or_return
  24. }
  25. }
  26. if dir == "" {
  27. err = .Invalid_Path
  28. }
  29. return
  30. }
  31. @(require_results)
  32. user_config_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
  33. #partial switch ODIN_OS {
  34. case .Windows:
  35. dir = get_env("AppData", allocator)
  36. if dir != "" {
  37. dir = clone_string(dir, allocator) or_return
  38. }
  39. case .Darwin:
  40. dir = get_env("HOME", allocator)
  41. if dir != "" {
  42. dir = concatenate({dir, "/Library/Application Support"}, allocator) or_return
  43. }
  44. case: // All other UNIX systems
  45. dir = get_env("XDG_CACHE_HOME", allocator)
  46. if dir == "" {
  47. dir = get_env("HOME", allocator)
  48. if dir == "" {
  49. return
  50. }
  51. dir = concatenate({dir, "/.config"}, allocator) or_return
  52. }
  53. }
  54. if dir == "" {
  55. err = .Invalid_Path
  56. }
  57. return
  58. }
  59. @(require_results)
  60. user_home_dir :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
  61. env := "HOME"
  62. #partial switch ODIN_OS {
  63. case .Windows:
  64. env = "USERPROFILE"
  65. }
  66. if v := get_env(env, allocator); v != "" {
  67. return v, nil
  68. }
  69. return "", .Invalid_Path
  70. }