- # It is acceptable for the second parameter to be just a simple scalar
- # denoting a single category (either name or number). No conversion into
- # a number is done in this case.
-
- use Config;
+ # It is a fatal error to call this with something that isn't a known
+ # category to this file. If this happens, look first for a typo, and
+ # second if you are using a category unknown to Perl. In the latter case
+ # a bug report should be submitted.
+
+ # khw cargo-culted the '?' in the pattern on the next line.
+ return 0 if $Config{ccflags} =~ /\bD?NO_LOCALE\b/;
+
+ # If we can't load the POSIX XS module, we can't have locales even if they
+ # normally would be available
+ return 0 if ! defined &DynaLoader::boot_DynaLoader;
+
+ # Don't test locales where they aren't safe. On systems with unsafe
+ # threads, for the purposes of testing, we consider the main thread safe,
+ # and all other threads unsafe.
+ if (! ${^SAFE_LOCALES}) {
+ require threads;
+ return 0 if threads->tid() != 0;
+ }