From 9cd3cdf79cdff52a5e474d126bd8584ba744aeb3 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 8 Jan 2014 22:53:00 +0100 Subject: [PATCH] Update libc/locale/setlocale.cpp to current coding conventions. --- libc/locale/setlocale.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libc/locale/setlocale.cpp b/libc/locale/setlocale.cpp index 496d3e4e..fd63c633 100644 --- a/libc/locale/setlocale.cpp +++ b/libc/locale/setlocale.cpp @@ -23,28 +23,28 @@ *******************************************************************************/ #define __SORTIX_STDLIB_REDIRECTS 0 +#include +#include #include #include -#include -#include static char* current_locales[LC_NUM_CATEGORIES] = { NULL }; extern "C" const char* sortix_setlocale(int category, const char* locale) { - if ( category < 0 || LC_ALL < category ) { errno = EINVAL; return NULL; } + if ( category < 0 || LC_ALL < category ) + return errno = EINVAL, (const char*) NULL; char* new_strings[LC_NUM_CATEGORIES]; - int from = category; - int to = category; + int from = category != LC_ALL ? category : 0; + int to = category != LC_ALL ? category : LC_NUM_CATEGORIES - 1; if ( !locale ) return current_locales[to] ? current_locales[to] : "C"; - if ( category == LC_ALL ) { from = 0; to = LC_NUM_CATEGORIES-1; } for ( int i = from; i <= to; i++ ) { - new_strings[i] = strdup(locale); - if ( !new_strings[i] ) + if ( !(new_strings[i] = strdup(locale)) ) { - for ( int n = from; n < i; n++ ) { free(new_strings[n]); } + for ( int n = from; n < i; n++ ) + free(new_strings[n]); return NULL; } }