[Linux] Check for null pointer in locale specific functions

This commit is contained in:
Kevin 2015-12-05 22:25:25 +01:00
parent c0f7b0b1f3
commit a18089145b
1 changed files with 25 additions and 21 deletions

View File

@ -695,6 +695,8 @@ time_t platform_file_get_modified_time(const utf8* path){
uint8 platform_get_locale_currency(){
char *langstring = setlocale(LC_MONETARY, "");
if(langstring != NULL){
struct lconv *lc = localeconv();
//Only works if g_currency_specs contains the actual (local) symbol
@ -711,7 +713,7 @@ uint8 platform_get_locale_currency(){
else if(!strncmp(lc->int_curr_symbol, "RUB", 3)){
return CURRENCY_ROUBLE;
}
}
//All other currencies are historic
return CURRENCY_POUNDS;
}
@ -720,21 +722,23 @@ uint8 platform_get_locale_measurement_format(){
//FIXME: LC_MEASUREMENT is GNU specific.
const char *langstring = setlocale(LC_MEASUREMENT, "");
if(langstring != NULL){
//using https://en.wikipedia.org/wiki/Metrication#Chronology_and_status_of_conversion_by_country as reference
if(!fnmatch("*_US*", langstring, 0) || !fnmatch("*_MM*", langstring, 0) || !fnmatch("*_LR*", langstring, 0)){
return MEASUREMENT_FORMAT_IMPERIAL;
}
}
return MEASUREMENT_FORMAT_METRIC;
}
uint8 platform_get_locale_temperature_format(){
const char *langstring = setlocale(LC_MEASUREMENT, "");
if(langstring != NULL){
if(!fnmatch("*_US*", langstring, 0) || !fnmatch("*_BS*", langstring, 0) || !fnmatch("*_BZ*", langstring, 0) || !fnmatch("*_PW*", langstring, 0)){
return TEMPERATURE_FORMAT_F;
}
}
return TEMPERATURE_FORMAT_C;
}