Update libc/locale/setlocale.cpp to current coding conventions.
This commit is contained in:
parent
292cca5f0e
commit
9cd3cdf79c
|
@ -23,28 +23,28 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#define __SORTIX_STDLIB_REDIRECTS 0
|
#define __SORTIX_STDLIB_REDIRECTS 0
|
||||||
|
#include <errno.h>
|
||||||
|
#include <locale.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <locale.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
static char* current_locales[LC_NUM_CATEGORIES] = { NULL };
|
static char* current_locales[LC_NUM_CATEGORIES] = { NULL };
|
||||||
|
|
||||||
extern "C" const char* sortix_setlocale(int category, const char* locale)
|
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];
|
char* new_strings[LC_NUM_CATEGORIES];
|
||||||
int from = category;
|
int from = category != LC_ALL ? category : 0;
|
||||||
int to = category;
|
int to = category != LC_ALL ? category : LC_NUM_CATEGORIES - 1;
|
||||||
if ( !locale )
|
if ( !locale )
|
||||||
return current_locales[to] ? current_locales[to] : "C";
|
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++ )
|
for ( int i = from; i <= to; i++ )
|
||||||
{
|
{
|
||||||
new_strings[i] = strdup(locale);
|
if ( !(new_strings[i] = strdup(locale)) )
|
||||||
if ( !new_strings[i] )
|
|
||||||
{
|
{
|
||||||
for ( int n = from; n < i; n++ ) { free(new_strings[n]); }
|
for ( int n = from; n < i; n++ )
|
||||||
|
free(new_strings[n]);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue