Index: src/OFSystemInfo.h ================================================================== --- src/OFSystemInfo.h +++ src/OFSystemInfo.h @@ -116,32 +116,52 @@ #ifdef OF_HAVE_FILES /** * @brief Returns the path where user data for the application can be stored. * - * On Unix systems, this adheres to the XDG Base Directory specification.@n - * On Mac OS X and iOS, it uses the `NSApplicationSupportDirectory` directory.@n + * On UNIX systems, this adheres to the XDG Base Directory specification.@n + * On macOS and iOS, it uses the `NSApplicationSupportDirectory` directory.@n * On Windows, it uses the `APPDATA` environment variable.@n - * On Haiku, it uses the `B_USER_SETTINGS_DIRECTORY` directory. + * On Haiku, it uses the `B_USER_SETTINGS_DIRECTORY` directory.@n + * On AmigaOS and MorphOS, it returns `PROGDIR:`. * * @return The path where user data for the application can be stored */ + (nullable OFString *)userDataPath; /** * @brief Returns the path where user configuration for the application can be * stored. * - * On Unix systems, this adheres to the XDG Base Directory specification.@n - * On Mac OS X and iOS, it uses the `Preferences` directory inside of + * On UNIX systems, this adheres to the XDG Base Directory specification.@n + * On macOS and iOS, it uses the `Preferences` directory inside of * `NSLibraryDirectory` directory.@n * On Windows, it uses the `APPDATA` environment variable.@n * On Haiku, it uses the `B_USER_SETTINGS_DIRECTORY` directory. + * On AmigaOS and MorphOS, it returns `PROGDIR:`. * * @return The path where user configuration for the application can be stored */ + (nullable OFString *)userConfigPath; + +/** + * @brief Returns a path where temporary files for can be stored. + * + * If possible, returns a temporary directory for the user, otherwise returns a + * global temporary directory. + * + * On UNIX systems, this adheres to the XDG Base Directory specification and + * returns `/tmp` if `XDG_RUNTIME_DIR` is not set.@n + * On macOS and iOS, this uses `_CS_DARWIN_USER_TEMP_DIR`, falling back to + * `/tmp` if this fails.@n + * On Windows, it uses `GetTempPath`.@n + * On Haiku, it uses the `B_SYSTEM_TEMP_DIRECTORY` directory. + * On AmigaOS and MorphOS, it returns `T:`. + * + * @return A path where temporary files can be stored + */ ++ (nullable OFString *)temporaryDirectoryPath; #endif /** * @brief Returns the vendor of the CPU. * Index: src/OFSystemInfo.m ================================================================== --- src/OFSystemInfo.m +++ src/OFSystemInfo.m @@ -522,10 +522,61 @@ object: self]; return [var stringByAppendingPathComponent: @".config"]; # endif } + ++ (OFString *)temporaryDirectoryPath +{ +# if defined(OF_MACOS) || defined(OF_IOS) + char buffer[PATH_MAX]; + size_t length; + + if ((length = confstr(_CS_DARWIN_USER_TEMP_DIR, buffer, PATH_MAX)) == 0) + return @"/tmp"; + + return [OFString stringWithCString: buffer + encoding: [OFLocale encoding] + length: length]; +# elif defined(OF_WINDOWS) + if ([self isWindowsNT]) { + wchar_t buffer[PATH_MAX]; + + if (!GetTempPathW(PATH_MAX, buffer)) + return nil; + + return [OFString stringWithUTF16String: buffer]; + } else { + char buffer[PATH_MAX]; + + if (!GetTempPathA(PATH_MAX, buffer)) + return nil; + + return [OFString stringWithCString: buffer + encoding: [OFLocale encoding]]; + } +# elif defined(OF_HAIKU) + char pathC[PATH_MAX]; + + if (find_directory(B_SYSTEM_TEMP_DIRECTORY, 0, false, + pathC, PATH_MAX) != B_OK) + @throw [OFNotImplementedException exceptionWithSelector: _cmd + object: self]; + + return [OFString stringWithUTF8String: pathC]; +# elif defined(OF_AMIGAOS) + return @"T:"; +# else + OFString *path = + [[OFApplication environment] objectForKey: @"XDG_RUNTIME_DIR"]; + + if (path != nil) + return path; + + return @"/tmp"; +# endif +} #endif + (OFString *)CPUVendor { #if (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__)