Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *  * Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  *  * Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in
     12  *    the documentation and/or other materials provided with the
     13  *    distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
     22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 #include <ctype.h>
     29 #include <errno.h>
     30 #include <limits.h>
     31 #include <locale.h>
     32 #include <stdio.h>
     33 #include <stdlib.h>
     34 #include <time.h>
     35 #include <wctype.h>
     36 
     37 // Contains an implementation of all locale-specific functions (those
     38 // ending in _l, like strcoll_l()), as simple wrapper to the non-locale
     39 // specific ones for now.
     40 //
     41 // That's because Android's C library doesn't support locales. Or more
     42 // specifically, only supports the "C" one.
     43 //
     44 // TODO(digit): Write a more complete implementation that uses JNI to
     45 //              invoke the platform APIs to implement proper handling.
     46 //
     47 
     48 ///////////////////////////////////////////////////////////////////////
     49 // stdio.h declarations
     50 
     51 int vasprintf_l(char** strp, locale_t l, const char* fmt, va_list args) {
     52     // Ignore locale.
     53     return vasprintf(strp, fmt, args);
     54 }
     55 
     56 int asprintf_l(char** strp, locale_t locale, const char* fmt, ...) {
     57     va_list args;
     58     va_start(args, fmt);
     59     int result = vasprintf_l(strp, locale, fmt, args);
     60     va_end(args);
     61     return result;
     62 }
     63 
     64 int vsprintf_l(char* str, locale_t l, const char* fmt, va_list args) {
     65     // Ignore locale.
     66     return vsprintf(str, fmt, args);
     67 }
     68 
     69 int sprintf_l(char* str, locale_t l, const char* fmt, ...) {
     70     va_list args;
     71     va_start(args, fmt);
     72     int result = vsprintf_l(str, l, fmt, args);
     73     va_end(args);
     74     return result;
     75 }
     76 
     77 int vsnprintf_l(char* str, size_t size, locale_t l, const char* fmt, va_list args) {
     78     return vsnprintf(str, size, fmt, args);
     79 }
     80 
     81 int snprintf_l(char* str, size_t size, locale_t l, const char* fmt, ...) {
     82   va_list args;
     83   va_start(args, fmt);
     84   int result = vsnprintf_l(str, size, l, fmt, args);
     85   va_end(args);
     86   return result;
     87 }
     88 
     89 int vsscanf_l(const char* str, locale_t l, const char* fmt, va_list args) {
     90     return vsscanf(str, fmt, args);
     91 }
     92 
     93 int sscanf_l(const char* str, locale_t l, const char* fmt, ...) {
     94     va_list args;
     95     va_start(args, fmt);
     96     int result = vsscanf_l(str, l, fmt, args);
     97     va_end(args);
     98     return result;
     99 }
    100 
    101 ///////////////////////////////////////////////////////////////////////
    102 // stdlib.h declarations
    103 
    104 long strtol_l(const char *nptr, char **endptr, int base, locale_t loc) {
    105     return strtol(nptr, endptr, base);
    106 }
    107 
    108 unsigned long strtoul_l(const char *nptr, char **endptr, int base, locale_t loc) {
    109     return strtoul(nptr, endptr, base);
    110 }
    111 
    112 long long strtoll_l(const char *nptr, char **endptr, int base, locale_t loc) {
    113     return strtoll(nptr, endptr, base);
    114 }
    115 
    116 unsigned long long strtoull_l(const char *nptr, char **endptr, int base, locale_t loc) {
    117     return strtoull(nptr, endptr, base);
    118 }
    119 
    120 long double strtold_l (const char *nptr, char **endptr, locale_t loc) {
    121     return strtold(nptr, endptr);
    122 }
    123