Switch to a regular enum from a typed CFStringRef enum.
diff --git a/CoreFoundation/Base.subproj/CFKnownLocations.c b/CoreFoundation/Base.subproj/CFKnownLocations.c
index fd80a90..2da610b 100644
--- a/CoreFoundation/Base.subproj/CFKnownLocations.c
+++ b/CoreFoundation/Base.subproj/CFKnownLocations.c
@@ -15,10 +15,7 @@
#include <assert.h>
-CONST_STRING_DECL(_kCFKnownLocationUserAny, " == _kCFKnownLocationUserAny");
-CONST_STRING_DECL(_kCFKnownLocationUserCurrent, " == _kCFKnownLocationUserCurrent");
-
-CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUser user) {
+CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUser user, CFStringRef _Nullable username) {
CFURLRef location = NULL;
#if (DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI)
@@ -31,18 +28,23 @@
- Current: $HOME/Library/Preferences
*/
- if (user == _kCFKnownLocationUserAny) {
- location = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, CFSTR("/Library/Preferences"), kCFURLPOSIXPathStyle, true);
- } else {
- if (user == _kCFKnownLocationUserCurrent) {
- user = NULL;
+ switch (user) {
+ case _kCFKnownLocationUserAny:
+ location = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, CFSTR("/Library/Preferences"), kCFURLPOSIXPathStyle, true);
+ break;
+
+ case _kCFKnownLocationUserCurrent:
+ username = NULL;
+ // passthrough to:
+ case _kCFKnownLocationUserByName: {
+ CFURLRef home = CFCopyHomeDirectoryURLForUser(username);
+ location = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, CFSTR("/Library/Preferences"), kCFURLPOSIXPathStyle, true, home);
+ CFRelease(home);
+
+ break;
}
-
- CFURLRef home = CFCopyHomeDirectoryURLForUser(user);
- location = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, CFSTR("/Library/Preferences"), kCFURLPOSIXPathStyle, true, home);
- CFRelease(home);
+
}
-
#elif !DEPLOYMENT_RUNTIME_OBJC && !DEPLOYMENT_TARGET_WINDOWS
/*
@@ -53,15 +55,20 @@
- Current: $XDG_CONFIG_PATH (usually: $HOME/.config/).
*/
- if (user == _kCFKnownLocationUserAny) {
- location = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, CFSTR("/usr/local/etc"), kCFURLPOSIXPathStyle, true);
- } else {
- assert(user == _kCFKnownLocationUserCurrent);
-
- if (user == _kCFKnownLocationUserCurrent) {
+ switch (user) {
+ case _kCFKnownLocationUserAny:
+ location = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, CFSTR("/usr/local/etc"), kCFURLPOSIXPathStyle, true);
+ break;
+
+ case _kCFKnownLocationUserByName:
+ assert(username == NULL);
+ // passthrough to:
+ case _kCFKnownLocationUserCurrent: {
CFStringRef path = _CFXDGCreateConfigHomePath();
location = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, path, kCFURLPOSIXPathStyle, true);
CFRelease(path);
+
+ break;
}
}
diff --git a/CoreFoundation/Base.subproj/CFKnownLocations.h b/CoreFoundation/Base.subproj/CFKnownLocations.h
index 078d769..629468c 100644
--- a/CoreFoundation/Base.subproj/CFKnownLocations.h
+++ b/CoreFoundation/Base.subproj/CFKnownLocations.h
@@ -15,11 +15,11 @@
CF_ASSUME_NONNULL_BEGIN
-typedef CFStringRef CFKnownLocationUser CF_TYPED_EXTENSIBLE_ENUM;
-
-extern const CFKnownLocationUser _kCFKnownLocationUserAny;
-
-extern const CFKnownLocationUser _kCFKnownLocationUserCurrent;
+typedef CF_ENUM(CFIndex, CFKnownLocationUser) {
+ _kCFKnownLocationUserAny,
+ _kCFKnownLocationUserCurrent,
+ _kCFKnownLocationUserByName,
+};
/* A note on support:
@@ -28,13 +28,14 @@
- For platforms that use the XDG spec to identify a configuration path in a user's home, we cannot determine that path for any user other than the one we're currently running as.
So:
- - We're keeping that behavior when building Core Foundation for Darwin/ObjC for compatibility, hence the _EXTENSIBLE above; but
+ - We're keeping that behavior when building Core Foundation for Darwin/ObjC for compatibility, hence the _EXTENSIBLE above; on those platforms, the …ByName enum will continue working to get locations for arbitrary usernames. But:
- For Swift and any new platform, we are enforcing the documented constraint. Using a user value other than …Any or …Current above will assert (or return NULL if asserts are off).
See CFKnownLocations.c for a summary of what paths are returned.
*/
-extern CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUser user);
+// The username parameter is ignored for any user constant other than …ByName. …ByName with a NULL username is the same as …Current.
+extern CFURLRef _Nullable _CFKnownLocationCreatePreferencesURLForUser(CFKnownLocationUser user, CFStringRef _Nullable username);
CF_ASSUME_NONNULL_END
diff --git a/CoreFoundation/Preferences.subproj/CFPreferences.c b/CoreFoundation/Preferences.subproj/CFPreferences.c
index b7fe19c..19cd77b 100644
--- a/CoreFoundation/Preferences.subproj/CFPreferences.c
+++ b/CoreFoundation/Preferences.subproj/CFPreferences.c
@@ -193,10 +193,10 @@
} else if (userName == kCFPreferencesCurrentUser) {
user = _kCFKnownLocationUserCurrent;
} else {
- user = userName;
+ user = _kCFKnownLocationUserByName;
}
- CFURLRef base = _CFKnownLocationCreatePreferencesURLForUser(user);
+ CFURLRef base = _CFKnownLocationCreatePreferencesURLForUser(user, userName);
if (hostName == kCFPreferencesCurrentHost) {
location = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorSystemDefault, CFSTR("ByHost"), kCFURLPOSIXPathStyle, true, base);