Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the user's locale when running as root?

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.

like image 684
fredley Avatar asked Dec 01 '25 13:12

fredley


1 Answers

This information is contained in GlobalPreferences.plist, so running:

$ defaults read /Library/Preferences/.GlobalPreferences AppleLocale

gives the desired result.

like image 56
fredley Avatar answered Dec 03 '25 02:12

fredley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!