Queries or sets locale properties.
#include <locale.h> char* setlocale(int cat, const char* locale);
cat
The property to query or set.
locale
A pointer to the locale.
The cat argument specifies the locale property to query or set. The following table lists the values recognized by setlocale().
If locale is a null pointer then setlocale() makes a query. It returns a pointer to a character string that indicates which locale that the cat property is set to. Your program must not modify this character string. Subsequent calls to the function might alter this character string.
If locale is not a null pointer then setlocale() modifies the locale property specified by cat. The character string that locale points to must be a result returned by a previous query to setlocale(). The function returns a pointer to a character string that describes the newly-set locale.
CodeWarrior C compilers and EWL use the "C" locale by default and a native locale named "" (the empty string).
| Value | Locale Property |
|---|---|
| LC_ALL | All properties. |
| LC_COLLATE | Behaviors for strcoll()and strxfrm. |
| LC_CTYPE | Character manipulation behaviors of facilities in ctype.h, wctype.h, and stdlib.h. |
| LC_MONETARY | Monetary formatting properties returned by localeconv(). |
| LC_NUMERIC | Non-monetary numeric formatting properties returned by localeconv(). |
| LC_TIME | Behavior for strftime(). |
#include <locale.h> #include <stdlib.h> #include <string.h> char* copylocale(int cat); char* copylocale(int cat) { char* loc; char* copy; /* Make query. */ if ((loc = setlocale(cat, NULL)) == NULL) return NULL; /* Query failure. */ /* Allocate memory, including null character. */ copy = (char*)malloc(strlen(loc) + 1); if (copy == NULL) /* Memory failure. */ return NULL; return strcpy(copy, loc); } int main(void) { char* save; if ((save = copylocale(LC_ALL)) == NULL) return 1; setlocale(LC_ALL, ""); /* Set native locale. */ /* ... */ setlocale(LC_ALL, save); /* Restore locale. */ /* ... */ _free(save); return 0; }