123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- /*++
- Copyright (c) 2013 Minoca Corp.
- This file is licensed under the terms of the GNU General Public License
- version 3. Alternative licensing terms are available. Contact
- info@minocacorp.com for details. See the LICENSE file at the root of this
- project for complete licensing information.
- Module Name:
- locale.c
- Abstract:
- This module implements locale functionality for the C library.
- Author:
- Evan Green 22-Jul-2013
- Environment:
- User Mode C Library
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include "libcp.h"
- #include <assert.h>
- #include <limits.h>
- #include <locale.h>
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // Store the current locale information, which is initialized to the "C"
- // locale.
- //
- struct lconv ClLocaleInformation = {
- "",
- ".",
- CHAR_MAX,
- "",
- "",
- CHAR_MAX,
- CHAR_MAX,
- CHAR_MAX,
- CHAR_MAX,
- CHAR_MAX,
- CHAR_MAX,
- CHAR_MAX,
- "",
- "",
- "",
- "",
- CHAR_MAX,
- CHAR_MAX,
- CHAR_MAX,
- "",
- CHAR_MAX,
- CHAR_MAX,
- CHAR_MAX,
- ""
- };
- //
- // ------------------------------------------------------------------ Functions
- //
- LIBC_API
- struct lconv *
- localeconv (
- void
- )
- /*++
- Routine Description:
- This routine returns a pointer to a structure containing the numeric and
- monetary customs of the current locale. String members of the structure
- may point to "" to indicate that the value is not available in the current
- locale or is of zero length. Character members are non-negative numbers,
- any of which can be CHAR_MAX to indicate that the value is not available
- in the current locale.
- Arguments:
- None.
- Return Value:
- Returns a pointer to the filled in structure. The caller must not attempt
- to modify or free the returned structure. The structure returned or
- storage areas pointed to by the structure may be overwritten or invalidated
- by subsequent calls to setlocale or uselocale which affect the categories
- LC_ALL, LC_MONETARY, or LC_NUMERIC.
- --*/
- {
- return &ClLocaleInformation;
- }
- LIBC_API
- char *
- setlocale (
- int Category,
- const char *Locale
- )
- /*++
- Routine Description:
- This routine sets or returns the appropriate piece of the program's
- locale.
- Arguments:
- Category - Supplies the category of the locale to set. See LC_* definitions.
- Locale - Supplies an optional pointer to a string containing the locale to
- set. If NULL is supplied, then the current locale will be returned and
- left unchanged.
- Return Value:
- Returns a pointer to a string containing the name of the original locale
- for the specified category. This string must not be modified, and may be
- overwritten by subsequent calls to this routine.
- NULL on failure.
- --*/
- {
- //
- // At some point, consider implementing some support for locales.
- //
- if (Locale != NULL) {
- if ((strcmp(Locale, "C") != 0) &&
- (strcmp(Locale, "POSIX") != 0) &&
- (strcmp(Locale, "") != 0)) {
- return NULL;
- }
- }
- return "C";
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
|