I am running as root, but have the user's uid (e.g. 504). How can I work out the user's locale (in my case en_GB)? The following does not work:
setuid(user_uid);
fprintf(stderr,
CFStringGetCStringPtr(CFLocaleGetIdentifier(CFLocaleCopyCurrent()),
kCFStringEncodingMacRoman);
setuid(0);
This outputs en_US for me.
This information is contained in GlobalPreferences.plist, so running:
$ defaults read /Library/Preferences/.GlobalPreferences AppleLocale
gives the desired result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With