aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Third2021-11-14 15:09:43 +0000
committerAlan Third2021-11-16 20:52:10 +0000
commit058c012f73d4abe014ace44b46c23babd48aebbc (patch)
treea2bde1cd5b18e13ccc6e730af3f2eb31867240fd /src
parent97c23204b981d5ad88ea3c8ddff0f726798aff1b (diff)
downloademacs-058c012f73d4abe014ace44b46c23babd48aebbc.tar.gz
emacs-058c012f73d4abe014ace44b46c23babd48aebbc.zip
Only set LANG if the ID is valid
* src/nsterm.m (ns_init_locale): Check the provided locale identifier is available before trying to use it.
Diffstat (limited to 'src')
-rw-r--r--src/nsterm.m17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/nsterm.m b/src/nsterm.m
index 1f17a30272c..e29dda684a0 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -535,8 +535,11 @@ ns_init_locale (void)
535 535
536 NSTRACE ("ns_init_locale"); 536 NSTRACE ("ns_init_locale");
537 537
538 @try 538 /* If we were run from a terminal then assume an unset LANG variable
539 is intentional and don't try to "fix" it. */
540 if (!isatty (STDIN_FILENO))
539 { 541 {
542 char *oldLocale = setlocale (LC_ALL, NULL);
540 /* It seems macOS should probably use UTF-8 everywhere. 543 /* It seems macOS should probably use UTF-8 everywhere.
541 'localeIdentifier' does not specify the encoding, and I can't 544 'localeIdentifier' does not specify the encoding, and I can't
542 find any way to get the OS to tell us which encoding to use, 545 find any way to get the OS to tell us which encoding to use,
@@ -544,12 +547,12 @@ ns_init_locale (void)
544 NSString *localeID = [NSString stringWithFormat:@"%@.UTF-8", 547 NSString *localeID = [NSString stringWithFormat:@"%@.UTF-8",
545 [locale localeIdentifier]]; 548 [locale localeIdentifier]];
546 549
547 /* Set LANG to locale, but not if LANG is already set. */ 550 /* Check the locale ID is valid and if so set LANG, but not if
548 setenv("LANG", [localeID UTF8String], 0); 551 it is already set. */
549 } 552 if (setlocale (LC_ALL, [localeID UTF8String]))
550 @catch (NSException *e) 553 setenv("LANG", [localeID UTF8String], 0);
551 { 554
552 NSLog (@"Locale detection failed: %@: %@", [e name], [e reason]); 555 setlocale (LC_ALL, oldLocale);
553 } 556 }
554} 557}
555 558