Fully implement LANG fallbacks

This commit is contained in:
saloniamatteo
2021-03-20 11:20:37 +01:00
parent 3d27ecaba8
commit 05fe281141
+21 -3
View File
@@ -7,15 +7,33 @@ void ffPrintLocale(FFinstance* instance)
char localeCode[256];
FILE *fp;
/* Try to open /etc/locale.conf in read-only mode */
FILE *fp;
fp = fopen("/etc/locale.conf", "r");
/* File does not exist */
if (fp == NULL) {
strcpy(localeCode, getenv("LANG"));
/* Check if LANG exists */
if (getenv("LANG") != NULL)
strcpy(localeCode, getenv("LANG"));
/* Check if LC_ALL exists */
else if (getenv("LC_ALL") != NULL)
strcpy(localeCode, getenv("LC_ALL"));
/* Check if LC_CTYPE exists */
else if (getenv("LC_CTYPE") != NULL)
strcpy(localeCode, getenv("LC_CTYPE"));
/* Check if LC_CTYPE exists */
else if (getenv("LC_CTYPE") != NULL)
strcpy(localeCode, getenv("LC_CTYPE"));
/* Check if LC_MESSAGES exists */
else if (getenv("LC_MESSAGES") != NULL)
strcpy(localeCode, getenv("LC_MESSAGES"));
/* User has broken system */
else
ffPrintError(instance, "Locale", "Locale not found!");
/* /etc/locale.conf exists */
} else {
ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", localeCode);
ffParsePropFile("/etc/locale.conf", "LANG=%[^\n]", localeCode);
}
/* Free pointer to file */