| ... | ... | @@ -1748,7 +1748,7 @@ static void utf16le_ptr_to_utf8(Buf *out, WCHAR *utf16le) { |
| 1748 | 1748 | #endif |
| 1749 | 1749 | |
| 1750 | 1750 | // Ported from std.os.getAppDataDir |
| 1751 | | Error os_get_app_data_dir(Buf *out_path, const char *appname) { |
| 1751 | Error os_get_cache_dir(Buf *out_path, const char *appname) { |
| 1752 | 1752 | #if defined(ZIG_OS_WINDOWS) |
| 1753 | 1753 | WCHAR *dir_path_ptr; |
| 1754 | 1754 | switch (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &dir_path_ptr)) { |
| ... | ... | @@ -1774,24 +1774,35 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { |
| 1774 | 1774 | buf_appendf(out_path, "%s/Library/Application Support/%s", home_dir, appname); |
| 1775 | 1775 | return ErrorNone; |
| 1776 | 1776 | #elif defined(ZIG_OS_POSIX) |
| 1777 | | const char *home_dir = getenv("HOME"); |
| 1778 | | if (home_dir == nullptr) { |
| 1779 | | // TODO use /etc/passwd |
| 1780 | | return ErrorFileNotFound; |
| 1781 | | } |
| 1782 | | if (home_dir[0] == 0) { |
| 1783 | | return ErrorFileNotFound; |
| 1784 | | } |
| 1785 | | buf_init_from_str(out_path, home_dir); |
| 1786 | | if (buf_ptr(out_path)[buf_len(out_path) - 1] != '/') { |
| 1787 | | buf_append_char(out_path, '/'); |
| 1777 | const char *cache_dir = getenv("XDG_CACHE_HOME"); |
| 1778 | if (cache_dir == nullptr) { |
| 1779 | cache_dir = getenv("HOME"); |
| 1780 | if (cache_dir == nullptr) { |
| 1781 | // TODO use /etc/passwd |
| 1782 | return ErrorFileNotFound; |
| 1783 | } |
| 1784 | if (cache_dir[0] == 0) { |
| 1785 | return ErrorFileNotFound; |
| 1786 | } |
| 1787 | buf_init_from_str(out_path, cache_dir); |
| 1788 | if (buf_ptr(out_path)[buf_len(out_path) - 1] != '/') { |
| 1789 | buf_append_char(out_path, '/'); |
| 1790 | } |
| 1791 | buf_appendf(out_path, ".cache/%s", appname); |
| 1792 | } else { |
| 1793 | if (cache_dir[0] == 0) { |
| 1794 | return ErrorFileNotFound; |
| 1795 | } |
| 1796 | buf_init_from_str(out_path, cache_dir); |
| 1797 | if (buf_ptr(out_path)[buf_len(out_path) - 1] != '/') { |
| 1798 | buf_append_char(out_path, '/'); |
| 1799 | } |
| 1800 | buf_appendf(out_path, "%s", appname); |
| 1788 | 1801 | } |
| 1789 | | buf_appendf(out_path, ".local/share/%s", appname); |
| 1790 | 1802 | return ErrorNone; |
| 1791 | 1803 | #endif |
| 1792 | 1804 | } |
| 1793 | 1805 | |
| 1794 | | |
| 1795 | 1806 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY) |
| 1796 | 1807 | static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) { |
| 1797 | 1808 | ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data); |