[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/ns/testing 5e4ba5c 1/7: Only set LANG if the ID is valid
From: |
Alan Third |
Subject: |
scratch/ns/testing 5e4ba5c 1/7: Only set LANG if the ID is valid |
Date: |
Sun, 14 Nov 2021 13:50:26 -0500 (EST) |
branch: scratch/ns/testing
commit 5e4ba5c1b546a6e15ea32afb1bdfef91dbf8c10d
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>
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.
---
src/nsterm.m | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/nsterm.m b/src/nsterm.m
index 1f17a30..e29dda6 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -535,8 +535,11 @@ ns_init_locale (void)
NSTRACE ("ns_init_locale");
- @try
+ /* If we were run from a terminal then assume an unset LANG variable
+ is intentional and don't try to "fix" it. */
+ if (!isatty (STDIN_FILENO))
{
+ char *oldLocale = setlocale (LC_ALL, NULL);
/* It seems macOS should probably use UTF-8 everywhere.
'localeIdentifier' does not specify the encoding, and I can't
find any way to get the OS to tell us which encoding to use,
@@ -544,12 +547,12 @@ ns_init_locale (void)
NSString *localeID = [NSString stringWithFormat:@"%@.UTF-8",
[locale localeIdentifier]];
- /* Set LANG to locale, but not if LANG is already set. */
- setenv("LANG", [localeID UTF8String], 0);
- }
- @catch (NSException *e)
- {
- NSLog (@"Locale detection failed: %@: %@", [e name], [e reason]);
+ /* Check the locale ID is valid and if so set LANG, but not if
+ it is already set. */
+ if (setlocale (LC_ALL, [localeID UTF8String]))
+ setenv("LANG", [localeID UTF8String], 0);
+
+ setlocale (LC_ALL, oldLocale);
}
}
- branch scratch/ns/testing created (now 6ab3dc1), Alan Third, 2021/11/14
- scratch/ns/testing 2dd414a 2/7: Simplify NS color handling, Alan Third, 2021/11/14
- scratch/ns/testing 5e4ba5c 1/7: Only set LANG if the ID is valid,
Alan Third <=
- scratch/ns/testing 9eadfb7 5/7: Make NS toolbar use NSString instead of C strings, Alan Third, 2021/11/14
- scratch/ns/testing 7d2c360 6/7: Make NS toolbar item ID more unique (bug#50160), Alan Third, 2021/11/14
- scratch/ns/testing bc3b8f3 3/7: Further cleanup of NS color code, Alan Third, 2021/11/14
- scratch/ns/testing ee8e8af 4/7: Fix macfont backend color handling, Alan Third, 2021/11/14
- scratch/ns/testing 6ab3dc1 7/7: Allow resizing undecorated frames on macOS (bug#28512, bug#31795), Alan Third, 2021/11/14