user.odin 1.7 KB

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