Keil™, An ARM® Company

RealView Libraries and Floating Point Support Guide

On-Line Manuals

RealView Libraries and Floating Point Support Guide

Preface
Introduction
The C and C++ Libraries
About the C and C++ libraries
Features of the C and C++ libraries
Namespaces
Writing reentrant and thread‑safe code
Introduction to reentrancy and thread‑safety
Use of static data in the C libraries
The __user_libspace static data area
Managing locks in multithreaded applications
Using the ARM C libraries with a multithreaded app
Thread‑safety in the ARM C libraries
Thread‑safety in the ARM C++ libraries
Building an application with the C library
Using the libraries with an application
Building an application for a semihosted environme
Building an application for a non semihosting envi
Building an application without the C library
Integer and FP helper functions
Bare machine integer C
Bare machine C with floating‑point
Exploiting the C library
The standalone C library functions
Tailoring the C library to a new execution environ
How C and C++ programs use the library functions
__rt_entry
Exiting from the program
__rt_exit()
__rt_lib_init()
__rt_lib_shutdown()
Tailoring static data access
Tailoring locale and CTYPE using assembler macros
Selecting locale at link time
Selecting locale at runtime
Defining a locale block
LC_CTYPE data block
LC_COLLATE data block
LC_MONETARY data block
LC_NUMERIC data block
LC_TIME data block
_get_lconv()
localeconv()
setlocale()
_findlocale()
The lconv structure
Tailoring locale and CTYPE using C macros
Selecting locale at link time
Selecting locale at runtime
Macros and utility functions
_get_lc_ctype()
_get_lc_collate()
_get_lc_monetary()
_get_lc_numeric()
_get_lc_time()
_get_lconv()
localeconv()
setlocale()
_findlocale()
__LC_CTYPE_DEF
__LC_COLLATE_DEF
__LC_TIME_DEF
__LC_NUMERIC_DEF
__LC_MONETARY_DEF
__LC_INDEX_END
The lconv structure
Tailoring error signaling, error handling, and pro
_sys_exit()
errno
__rt_errno_addr()
__raise()
__rt_raise()
__default_signal_handler()
_ttywrch()
__rt_fp_status_addr()
Tailoring storage management
Avoiding the ARM‑supplied heap and heap‑using
Support for malloc
Tailoring the runtime memory model
The memory models
Controlling the runtime memory model
Writing your own memory model
__user_initial_stackheap()
__user_setup_stackheap()
__user_heap_extend()
__user_heap_extent()
__user_stack_cleanup_space()
__rt_heap_extend()
__rt_stack_postlongjmp()
Tailoring the input/output functions
Dependencies on low‑level functions
Target‑dependent input/output support functions
_sys_open()
_sys_close()
_sys_read()
_sys_write()
_sys_ensure()
_sys_flen()
_sys_seek()
_sys_istty()
_sys_tmpnam()
_sys_command_string()
#pragma import(_main_redirection)
Tailoring other C library functions
clock()
_clock_init()
time()
remove()
rename()
system()
getenv()
_getenv_init()
Selecting real‑time division
ISO implementation definition
ISO C library implementation definition
Standard C++ library implementation definition
C library extensions
atoll()
strtoll()
strtoull()
printf()
snprintf()
vsnprintf()
lldiv()
llabs()
wcstombs()
alloca()
strlcpy()
strlcat()
_fisatty()
__heapstats()
__heapvalid()
Library naming conventions
Placing ARM libraries
Helper libraries
Identifying library variants
The C Micro-library
Floating‑point Support

_get_lc_ctype()

2.8.4. _get_lc_ctype()

The CTYPE implementation is selected at link time to be one of the following:

  • The C locale only. This is the default.

  • The ISO8859‑1 (Latin‑1) locale.

  • Shift‑JIS.

  • UTF‑8.

You can define your own CTYPE attribute table with the following characteristics:

  • It must be read‑only.

  • It is a byte array with indexes ranging from –1 to 255 inclusive (257 bytes in total)

  • Each byte is interpreted as eight attribute bits. The values are defined in ctype.h as follows:

    __S

    whitespace characters

    __P

    punctuation characters

    __B

    printable space characters

    __L

    lowercase letters

    __U

    uppercase letters

    __N

    decimal digits

    __C

    control characters

    __X

    hexadecimal‑digit letters A‑F and a‑f

    __A

    alphabetic but neither uppercase nor lowercase, such as Japanese katakana.

    Note

    A printable space character is defined as any character where the result of both isprint() and isspace() is true.

The first element in the array, the element located at –1, must be zero. A skeletal implementation of the functions that return CTYPE data is shown in Example 2.10. There are also macros that define multibyte LC_CTYPE locales, for example, LC_MBCTYPE_DEF. See the file rt_locale.h for more information.

Example 2.10. LC_CTYPE_DEF Table

__LC_CTYPE_DEF(lcctype_c, "C")
{
    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x00‑0x08 */
    __C+__S,__C+__S,__C+__S,__C+__S,__C+__S,    /* 0x09‑0x0D (BS,LF,VT,FF,CR) */
    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x0E‑0x16 */
    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x17‑0x1F */
    __B+__S,                                                /* space */
    __P, __P, __P, __P, __P, __P, __P, __P,                 /* !"#$%&'( */
    __P, __P, __P, __P, __P, __P, __P,                      /* )*+,‑./ */
    __N, __N, __N, __N, __N, __N, __N, __N, __N, __N,       /* 0‑9 */
    __P, __P, __P, __P, __P, __P, __P,                      /* :;<=>?@ */
    __U+__X, __U+__X, __U+__X, __U+__X, __U+__X, __U+__X,   /* A‑F */
    __U, __U, __U, __U, __U, __U, __U, __U, __U, __U,       /* G‑P */
    __U, __U, __U, __U, __U, __U, __U, __U, __U, __U,       /* Q‑Z */
    __P, __P, __P, __P, __P, __P,                           /* [\]^_` */
    __L+__X, __L+__X, __L+__X, __L+__X, __L+__X, __L+__X,   /* a‑f */
    __L, __L, __L, __L, __L, __L, __L, __L, __L, __L,       /* g‑p */
    __L, __L, __L, __L, __L, __L, __L, __L, __L, __L,       /* q‑z */
    __P, __P, __P, __P,                                     /* {|}~ */
    __C,                                                    /* 0x7F */
    /* the whole of the top half is illegal characters */
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
__LC_CTYPE_DEF(lcctype_iso8859_1, "ISO8859‑1")
{
    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x00‑0x08 */
    __C+__S,__C+__S,__C+__S,__C+__S,__C+__S,  /* 0x09‑0x0D (BS,LF,VT,FF,CR) */
    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x0E‑0x16 */
    __C, __C, __C, __C, __C, __C, __C, __C, __C,            /* 0x17‑0x1F */
    __B+__S,                                                /* space */
    __P, __P, __P, __P, __P, __P, __P, __P,                 /* !"#$%&'( */
    __P, __P, __P, __P, __P, __P, __P,                      /* )*+,‑./ */
    __N, __N, __N, __N, __N, __N, __N, __N, __N, __N,       /* 0‑9 */
    __P, __P, __P, __P, __P, __P, __P,                      /* :;<=>?@ */
    __U+__X, __U+__X, __U+__X, __U+__X, __U+__X, __U+__X,   /* A‑F */
    __U, __U, __U, __U, __U, __U, __U, __U, __U, __U,       /* G‑P */
    __U, __U, __U, __U, __U, __U, __U, __U, __U, __U,       /* Q‑Z */
    __P, __P, __P, __P, __P, __P,                           /* [\]^_` */
    __L+__X, __L+__X, __L+__X, __L+__X, __L+__X, __L+__X,   /* a‑f */
    __L, __L, __L, __L, __L, __L, __L, __L, __L, __L,       /* g‑p */
    __L, __L, __L, __L, __L, __L, __L, __L, __L, __L,       /* q‑z */
    __P, __P, __P, __P,                                     /* {|}~ */
    __C,                                                    /* 0x7F */
    /* ISO8859‑1 top half:
     * ‑ 0x80‑0x9f are control chars
     * ‑ 0xa0 is nonbreaking space (whitespace)
     * ‑ 0xa1‑0xbf are punctuation chars
     * ‑ 0xc0‑0xdf are uppercase chars except times sign at 0xd7
     * ‑ 0xe0‑0xff are lowercase chars except divide sign at 0xf7 */
    __C,__C,__C,__C,__C,__C,__C,__C,       /* 0x80 ‑ 0x87 */
    __C,__C,__C,__C,__C,__C,__C,__C,       /* 0x88 ‑ 0x8f */
    __C,__C,__C,__C,__C,__C,__C,__C,       /* 0x90 ‑ 0x97 */
    __C,__C,__C,__C,__C,__C,__C,__C,       /* 0x98 ‑ 0x9f */
    __B+__S,__P,__P,__P,__P,__P,__P,__P,   /* 0xa0 ‑ 0xa7 */
    __P,__P,__P,__P,__P,__P,__P,__P,       /* 0xa8 ‑ 0xaf */
    __P,__P,__P,__P,__P,__P,__P,__P,       /* 0xb0 ‑ 0xb7 */
    __P,__P,__P,__P,__P,__P,__P,__P,       /* 0xb8 ‑ 0xbf */
    __U,__U,__U,__U,__U,__U,__U,__U,       /* 0xc0 ‑ 0xc7 */
    __U,__U,__U,__U,__U,__U,__U,__U,       /* 0xc8 ‑ 0xcf */
    __U,__U,__U,__U,__U,__U,__U,__P,       /* 0xd0 ‑ 0xd7 */
    __U,__U,__U,__U,__U,__U,__U,__U,       /* 0xd8 ‑ 0xdf */
    __L,__L,__L,__L,__L,__L,__L,__L,       /* 0xe0 ‑ 0xe7 */
    __L,__L,__L,__L,__L,__L,__L,__L,       /* 0xe8 ‑ 0xef */
    __L,__L,__L,__L,__L,__L,__L,__P,       /* 0xf0 ‑ 0xf7 */
    __L,__L,__L,__L,__L,__L,__L,__L,       /* 0xf8 ‑ 0xff */
};
_LC_INDEX_END(lcctype_dummy)

void const *_get_lc_ctype(void const *null, char const *name) {
    return _findlocale(&lcctype_c_index, name);
}

void test_lc_ctype(void) {
    EQS(setlocale(LC_CTYPE, NULL), "C");  /* verify starting point */
    EQI(!!isalpha('@'), 0);               /* test off‑by‑one */
    EQI(!!isalpha('A'), 1);
    EQI(!!isalpha('\xc1'), 0);            /* C locale: isalpha(Aacute)==0 */
    EQI(!setlocale(LC_CTYPE, "ISO8859‑1"), 0);
    EQS(setlocale(LC_CTYPE, NULL), "ISO8859‑1");
    EQI(!!isalpha('@'), 0);               /* test off‑by‑one */
    EQI(!!isalpha('A'), 1);
    EQI(!!isalpha('\xc1'), 1);            /* ISO8859 locale: isalpha(Aacute)!=0 */
    EQI(!setlocale(LC_CTYPE, "C"), 0);
    EQS(setlocale(LC_CTYPE, NULL), "C");
    EQI(!!isalpha('@'), 0);               /* test off‑by‑one */
    EQI(!!isalpha('A'), 1);
    EQI(!!isalpha('\xc1'), 0);            /* C locale: isalpha(Aacute)==0 */
}
Copyright © 2007 ARM Limited. All rights reserved.ARM DUI 0378A