diff --git a/src/kernel/libroot/posix/glibc/wcsmbs/Jamfile b/src/kernel/libroot/posix/glibc/wcsmbs/Jamfile index 1918a436a4..cd3be87d83 100644 --- a/src/kernel/libroot/posix/glibc/wcsmbs/Jamfile +++ b/src/kernel/libroot/posix/glibc/wcsmbs/Jamfile @@ -1,11 +1,11 @@ SubDir OBOS_TOP src kernel libroot posix glibc wcsmbs ; SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc include arch $(OBOS_ARCH) ; -SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc wcsmbs ; SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc include ; +SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc libio ; +SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc wcsmbs ; SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc iconv ; SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc locale ; -SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc libio ; SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc ; # ToDo: for now, all wide character functions are disabled @@ -14,5 +14,14 @@ KernelMergeObject posix_gnu_wcsmbs.o : mbrlen.c mbrtowc.c mbsinit.c + mbsnrtowcs.c + wcrtomb.c + wcslen.c + wcsmbsload.c + wcsnlen.c + wcsrtombs.c + wmemcpy.c + wmempcpy.c + wmemmove.c : -fPIC -DPIC ; diff --git a/src/kernel/libroot/posix/glibc/wcsmbs/mbsnrtowcs.c b/src/kernel/libroot/posix/glibc/wcsmbs/mbsnrtowcs.c index 9ac06fe6c2..7014aa52a2 100644 --- a/src/kernel/libroot/posix/glibc/wcsmbs/mbsnrtowcs.c +++ b/src/kernel/libroot/posix/glibc/wcsmbs/mbsnrtowcs.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996,1997,1998,1999,2000,2002 Free Software Foundation, Inc. +/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1996. @@ -51,7 +51,6 @@ __mbsnrtowcs (dst, src, nmc, len, ps) int status; struct __gconv_step *towc; size_t dummy; - const struct gconv_fcts *fcts; /* Tell where we want the result. */ data.__invocation_counter = 0; @@ -64,11 +63,11 @@ __mbsnrtowcs (dst, src, nmc, len, ps) return 0; srcend = *src + __strnlen (*src, nmc - 1) + 1; - /* Get the conversion functions. */ - fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE)); + /* Make sure we use the correct function. */ + update_conversion_ptrs (); /* Get the structure with the function pointers. */ - towc = fcts->towc; + towc = __wcsmbs_gconv_fcts.towc; /* We have to handle DST == NULL special. */ if (dst == NULL) diff --git a/src/kernel/libroot/posix/glibc/wcsmbs/wchar.h b/src/kernel/libroot/posix/glibc/wcsmbs/wchar.h index ff37f1ee6d..0b4386b277 100644 --- a/src/kernel/libroot/posix/glibc/wcsmbs/wchar.h +++ b/src/kernel/libroot/posix/glibc/wcsmbs/wchar.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-99,2000,01,02 Free Software Foundation, Inc. +/* Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -23,8 +23,6 @@ #ifndef _WCHAR_H -#include - #ifndef __need_mbstate_t # define _WCHAR_H 1 # include @@ -60,10 +58,6 @@ member of the extended character set. */ # define _WINT_T typedef unsigned int wint_t; -#else -# ifdef __USE_GNU -__USING_NAMESPACE_STD(wint_t) -# endif #endif @@ -87,13 +81,8 @@ typedef struct defined. */ #ifdef _WCHAR_H -__BEGIN_NAMESPACE_C99 /* Public type. */ typedef __mbstate_t mbstate_t; -__END_NAMESPACE_C99 -#ifdef __USE_GNU -__USING_NAMESPACE_C99(mbstate_t) -#endif #ifndef WCHAR_MIN /* These constants might also be defined in . */ @@ -111,21 +100,13 @@ __USING_NAMESPACE_C99(mbstate_t) # include #endif - -__BEGIN_DECLS - -__BEGIN_NAMESPACE_STD /* This incomplete type is defined in but needed here because of `wcsftime'. */ struct tm; -/* XXX We have to clean this up at some point. Since tm is in the std - namespace but wcsftime is in __c99 the type wouldn't be found - without inserting it in the global namespace. */ -__USING_NAMESPACE_STD(tm) -__END_NAMESPACE_STD -__BEGIN_NAMESPACE_C99 +__BEGIN_DECLS + /* Copy SRC to DEST. */ extern wchar_t *wcscpy (wchar_t *__restrict __dest, __const wchar_t *__restrict __src) __THROW; @@ -148,7 +129,6 @@ extern int wcscmp (__const wchar_t *__s1, __const wchar_t *__s2) /* Compare N wide-characters of S1 and S2. */ extern int wcsncmp (__const wchar_t *__s1, __const wchar_t *__s2, size_t __n) __THROW __attribute_pure__; -__END_NAMESPACE_C99 #ifdef __USE_GNU /* Compare S1 and S2, ignoring case. */ @@ -162,14 +142,13 @@ extern int wcsncasecmp (__const wchar_t *__s1, __const wchar_t *__s2, the provided locale and not the global locale. */ # include -extern int wcscasecmp_l (__const wchar_t *__s1, __const wchar_t *__s2, - __locale_t __loc) __THROW; +extern int __wcscasecmp_l (__const wchar_t *__s1, __const wchar_t *__s2, + __locale_t __loc) __THROW; -extern int wcsncasecmp_l (__const wchar_t *__s1, __const wchar_t *__s2, - size_t __n, __locale_t __loc) __THROW; +extern int __wcsncasecmp_l (__const wchar_t *__s1, __const wchar_t *__s2, + size_t __n, __locale_t __loc) __THROW; #endif -__BEGIN_NAMESPACE_C99 /* Compare S1 and S2, both interpreted as appropriate to the LC_COLLATE category of the current locale. */ extern int wcscoll (__const wchar_t *__s1, __const wchar_t *__s2) __THROW; @@ -178,7 +157,6 @@ extern int wcscoll (__const wchar_t *__s1, __const wchar_t *__s2) __THROW; `wcscoll' to the original strings. */ extern size_t wcsxfrm (wchar_t *__restrict __s1, __const wchar_t *__restrict __s2, size_t __n) __THROW; -__END_NAMESPACE_C99 #ifdef __USE_GNU /* Similar to the two functions above but take the information from @@ -186,27 +164,24 @@ __END_NAMESPACE_C99 /* Compare S1 and S2, both interpreted as appropriate to the LC_COLLATE category of the given locale. */ -extern int wcscoll_l (__const wchar_t *__s1, __const wchar_t *__s2, - __locale_t __loc) __THROW; - +extern int __wcscoll_l (__const wchar_t *__s1, __const wchar_t *__s2, + __locale_t __loc) __THROW; /* Transform S2 into array pointed to by S1 such that if wcscmp is applied to two transformed strings the result is the as applying `wcscoll' to the original strings. */ -extern size_t wcsxfrm_l (wchar_t *__s1, __const wchar_t *__s2, - size_t __n, __locale_t __loc) __THROW; +extern size_t __wcsxfrm_l (wchar_t *__s1, __const wchar_t *__s2, + size_t __n, __locale_t __loc) __THROW; /* Duplicate S, returning an identical malloc'd string. */ extern wchar_t *wcsdup (__const wchar_t *__s) __THROW __attribute_malloc__; #endif -__BEGIN_NAMESPACE_C99 /* Find the first occurrence of WC in WCS. */ extern wchar_t *wcschr (__const wchar_t *__wcs, wchar_t __wc) __THROW __attribute_pure__; /* Find the last occurrence of WC in WCS. */ extern wchar_t *wcsrchr (__const wchar_t *__wcs, wchar_t __wc) __THROW __attribute_pure__; -__END_NAMESPACE_C99 #ifdef __USE_GNU /* This function is similar to `wcschr'. But it returns a pointer to @@ -215,7 +190,6 @@ extern wchar_t *wcschrnul (__const wchar_t *__s, wchar_t __wc) __THROW __attribute_pure__; #endif -__BEGIN_NAMESPACE_C99 /* Return the length of the initial segmet of WCS which consists entirely of wide characters not in REJECT. */ extern size_t wcscspn (__const wchar_t *__wcs, __const wchar_t *__reject) @@ -231,6 +205,12 @@ extern wchar_t *wcspbrk (__const wchar_t *__wcs, __const wchar_t *__accept) extern wchar_t *wcsstr (__const wchar_t *__haystack, __const wchar_t *__needle) __THROW __attribute_pure__; +#ifdef __USE_XOPEN +/* Another name for `wcsstr' from XPG4. */ +extern wchar_t *wcswcs (__const wchar_t *__haystack, __const wchar_t *__needle) + __THROW __attribute_pure__; +#endif + /* Divide WCS into tokens separated by characters in DELIM. */ extern wchar_t *wcstok (wchar_t *__restrict __s, __const wchar_t *__restrict __delim, @@ -238,13 +218,6 @@ extern wchar_t *wcstok (wchar_t *__restrict __s, /* Return the number of wide characters in S. */ extern size_t wcslen (__const wchar_t *__s) __THROW __attribute_pure__; -__END_NAMESPACE_C99 - -#ifdef __USE_XOPEN -/* Another name for `wcsstr' from XPG4. */ -extern wchar_t *wcswcs (__const wchar_t *__haystack, __const wchar_t *__needle) - __THROW __attribute_pure__; -#endif #ifdef __USE_GNU /* Return the number of wide characters in S, but at most MAXLEN. */ @@ -253,7 +226,6 @@ extern size_t wcsnlen (__const wchar_t *__s, size_t __maxlen) #endif -__BEGIN_NAMESPACE_C99 /* Search N wide characters of S for C. */ extern wchar_t *wmemchr (__const wchar_t *__s, wchar_t __c, size_t __n) __THROW __attribute_pure__; @@ -274,7 +246,6 @@ extern wchar_t *wmemmove (wchar_t *__s1, __const wchar_t *__s2, size_t __n) /* Set N wide characters of S to C. */ extern wchar_t *wmemset (wchar_t *__s, wchar_t __c, size_t __n) __THROW; -__END_NAMESPACE_C99 #ifdef __USE_GNU /* Copy N wide characters of SRC to DEST and return pointer to following @@ -285,7 +256,6 @@ extern wchar_t *wmempcpy (wchar_t *__restrict __s1, #endif -__BEGIN_NAMESPACE_C99 /* Determine whether C constitutes a valid (one-byte) multibyte character. */ extern wint_t btowc (int __c) __THROW; @@ -313,7 +283,6 @@ extern size_t __mbrlen (__const char *__restrict __s, size_t __n, mbstate_t *__restrict __ps) __THROW; extern size_t mbrlen (__const char *__restrict __s, size_t __n, mbstate_t *__restrict __ps) __THROW; -__END_NAMESPACE_C99 #ifdef __USE_EXTERN_INLINES /* Define inline function as optimization. */ @@ -323,7 +292,6 @@ extern __inline size_t mbrlen (__const char *__restrict __s, size_t __n, ? mbrtowc (NULL, __s, __n, __ps) : __mbrlen (__s, __n, NULL)); } #endif -__BEGIN_NAMESPACE_C99 /* Write wide character representation of multibyte character string SRC to DST. */ extern size_t mbsrtowcs (wchar_t *__restrict __dst, @@ -335,7 +303,6 @@ extern size_t mbsrtowcs (wchar_t *__restrict __dst, extern size_t wcsrtombs (char *__restrict __dst, __const wchar_t **__restrict __src, size_t __len, mbstate_t *__restrict __ps) __THROW; -__END_NAMESPACE_C99 #ifdef __USE_GNU @@ -365,7 +332,6 @@ extern int wcswidth (__const wchar_t *__s, size_t __n) __THROW; #endif /* Use X/Open. */ -__BEGIN_NAMESPACE_C99 /* Convert initial portion of the wide string NPTR to `double' representation. */ extern double wcstod (__const wchar_t *__restrict __nptr, @@ -391,23 +357,6 @@ extern unsigned long int wcstoul (__const wchar_t *__restrict __nptr, wchar_t **__restrict __endptr, int __base) __THROW; -#if defined __USE_ISOC99 || (defined __GNUC__ && defined __USE_GNU) -/* Convert initial portion of wide string NPTR to `long int' - representation. */ -__extension__ -extern long long int wcstoll (__const wchar_t *__restrict __nptr, - wchar_t **__restrict __endptr, int __base) - __THROW; - -/* Convert initial portion of wide string NPTR to `unsigned long long int' - representation. */ -__extension__ -extern unsigned long long int wcstoull (__const wchar_t *__restrict __nptr, - wchar_t **__restrict __endptr, - int __base) __THROW; -#endif /* ISO C99 or GCC and GNU. */ -__END_NAMESPACE_C99 - #if defined __GNUC__ && defined __USE_GNU /* Convert initial portion of wide string NPTR to `long int' representation. */ @@ -424,6 +373,22 @@ extern unsigned long long int wcstouq (__const wchar_t *__restrict __nptr, int __base) __THROW; #endif /* GCC and use GNU. */ +#if defined __USE_ISOC99 || (defined __GNUC__ && defined __USE_GNU) +/* Convert initial portion of wide string NPTR to `long int' + representation. */ +__extension__ +extern long long int wcstoll (__const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr, int __base) + __THROW; + +/* Convert initial portion of wide string NPTR to `unsigned long long int' + representation. */ +__extension__ +extern unsigned long long int wcstoull (__const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr, + int __base) __THROW; +#endif /* ISO C99 or GCC and GNU. */ + #ifdef __USE_GNU /* The concept of one static locale per category is not very well thought out. Many applications will need to process its data using @@ -442,36 +407,36 @@ extern unsigned long long int wcstouq (__const wchar_t *__restrict __nptr, /* Special versions of the functions above which take the locale to use as an additional parameter. */ -extern long int wcstol_l (__const wchar_t *__restrict __nptr, - wchar_t **__restrict __endptr, int __base, - __locale_t __loc) __THROW; +extern long int __wcstol_l (__const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr, int __base, + __locale_t __loc) __THROW; -extern unsigned long int wcstoul_l (__const wchar_t *__restrict __nptr, - wchar_t **__restrict __endptr, - int __base, __locale_t __loc) __THROW; +extern unsigned long int __wcstoul_l (__const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr, + int __base, __locale_t __loc) __THROW; __extension__ -extern long long int wcstoll_l (__const wchar_t *__restrict __nptr, +extern long long int __wcstoll_l (__const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr, + int __base, __locale_t __loc) __THROW; + +__extension__ +extern unsigned long long int __wcstoull_l (__const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr, + int __base, __locale_t __loc) + __THROW; + +extern double __wcstod_l (__const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr, __locale_t __loc) + __THROW; + +extern float __wcstof_l (__const wchar_t *__restrict __nptr, + wchar_t **__restrict __endptr, __locale_t __loc) + __THROW; + +extern long double __wcstold_l (__const wchar_t *__restrict __nptr, wchar_t **__restrict __endptr, - int __base, __locale_t __loc) __THROW; - -__extension__ -extern unsigned long long int wcstoull_l (__const wchar_t *__restrict __nptr, - wchar_t **__restrict __endptr, - int __base, __locale_t __loc) - __THROW; - -extern double wcstod_l (__const wchar_t *__restrict __nptr, - wchar_t **__restrict __endptr, __locale_t __loc) - __THROW; - -extern float wcstof_l (__const wchar_t *__restrict __nptr, - wchar_t **__restrict __endptr, __locale_t __loc) - __THROW; - -extern long double wcstold_l (__const wchar_t *__restrict __nptr, - wchar_t **__restrict __endptr, - __locale_t __loc) __THROW; + __locale_t __loc) __THROW; #endif /* GNU */ @@ -520,7 +485,6 @@ extern unsigned long long int __wcstoull_internal (__const wchar_t * #if defined __OPTIMIZE__ && __GNUC__ >= 2 /* Define inline functions which call the internal entry points. */ -__BEGIN_NAMESPACE_C99 extern __inline double wcstod (__const wchar_t *__restrict __nptr, wchar_t **__restrict __endptr) __THROW @@ -533,7 +497,6 @@ extern __inline unsigned long int wcstoul (__const wchar_t *__restrict __nptr, wchar_t **__restrict __endptr, int __base) __THROW { return __wcstoul_internal (__nptr, __endptr, __base, 0); } -__END_NAMESPACE_C99 # ifdef __USE_GNU extern __inline float wcstof (__const wchar_t *__restrict __nptr, @@ -573,7 +536,6 @@ extern wchar_t *wcpncpy (wchar_t *__dest, __const wchar_t *__src, size_t __n) /* Wide character I/O functions. */ #if defined __USE_ISOC99 || defined __USE_UNIX98 -__BEGIN_NAMESPACE_C99 /* Select orientation for stream. */ extern int fwide (__FILE *__fp, int __mode) __THROW; @@ -619,13 +581,9 @@ extern int wscanf (__const wchar_t *__restrict __format, ...) extern int swscanf (__const wchar_t *__restrict __s, __const wchar_t *__restrict __format, ...) __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */; - -__END_NAMESPACE_C99 #endif /* Use ISO C99 and Unix98. */ #ifdef __USE_ISOC99 -__BEGIN_NAMESPACE_C99 - /* Read formatted input from S into argument list ARG. */ extern int vfwscanf (__FILE *__restrict __s, __const wchar_t *__restrict __format, @@ -640,12 +598,9 @@ extern int vswscanf (__const wchar_t *__restrict __s, __const wchar_t *__restrict __format, __gnuc_va_list __arg) __THROW /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */; - -__END_NAMESPACE_C99 #endif /* Use ISO C99. */ -__BEGIN_NAMESPACE_C99 /* Read a character from STREAM. */ extern wint_t fgetwc (__FILE *__stream) __THROW; extern wint_t getwc (__FILE *__stream) __THROW; @@ -674,7 +629,6 @@ extern int fputws (__const wchar_t *__restrict __ws, /* Push a character back onto the input buffer of STREAM. */ extern wint_t ungetwc (wint_t __wc, __FILE *__stream) __THROW; -__END_NAMESPACE_C99 #ifdef __USE_GNU @@ -705,25 +659,12 @@ extern int fputws_unlocked (__const wchar_t *__restrict __ws, #endif -__BEGIN_NAMESPACE_C99 /* Format TP into S according to FORMAT. Write no more than MAXSIZE wide characters and return the number of wide characters written, or 0 if it would exceed MAXSIZE. */ extern size_t wcsftime (wchar_t *__restrict __s, size_t __maxsize, __const wchar_t *__restrict __format, __const struct tm *__restrict __tp) __THROW; -__END_NAMESPACE_C99 - -# ifdef __USE_GNU -# include - -/* Similar to `wcsftime' but takes the information from - the provided locale and not the global locale. */ -extern size_t wcsftime_l (wchar_t *__restrict __s, size_t __maxsize, - __const wchar_t *__restrict __format, - __const struct tm *__restrict __tp, - __locale_t __loc) __THROW; -# endif /* The X/Open standard demands that most of the functions defined in the header must also appear here. This is probably diff --git a/src/kernel/libroot/posix/glibc/wcsmbs/wcrtomb.c b/src/kernel/libroot/posix/glibc/wcsmbs/wcrtomb.c index 38144796f8..53e119b004 100644 --- a/src/kernel/libroot/posix/glibc/wcsmbs/wcrtomb.c +++ b/src/kernel/libroot/posix/glibc/wcsmbs/wcrtomb.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996,1997,1998,2000,2002 Free Software Foundation, Inc. +/* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1996. @@ -42,7 +42,6 @@ __wcrtomb (char *s, wchar_t wc, mbstate_t *ps) int status; size_t result; size_t dummy; - const struct gconv_fcts *fcts; /* Set information for this step. */ data.__invocation_counter = 0; @@ -63,16 +62,16 @@ __wcrtomb (char *s, wchar_t wc, mbstate_t *ps) data.__outbuf = s; data.__outbufend = s + MB_CUR_MAX; - /* Get the conversion functions. */ - fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE)); + /* Make sure we use the correct function. */ + update_conversion_ptrs (); /* If WC is the NUL character we write into the output buffer the byte sequence necessary for PS to get into the initial state, followed by a NUL byte. */ if (wc == L'\0') { - status = DL_CALL_FCT (fcts->tomb->__fct, - (fcts->tomb, &data, NULL, NULL, + status = DL_CALL_FCT (__wcsmbs_gconv_fcts.tomb->__fct, + (__wcsmbs_gconv_fcts.tomb, &data, NULL, NULL, NULL, &dummy, 1, 1)); if (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT) @@ -83,8 +82,8 @@ __wcrtomb (char *s, wchar_t wc, mbstate_t *ps) /* Do a normal conversion. */ const unsigned char *inbuf = (const unsigned char *) &wc; - status = DL_CALL_FCT (fcts->tomb->__fct, - (fcts->tomb, &data, &inbuf, + status = DL_CALL_FCT (__wcsmbs_gconv_fcts.tomb->__fct, + (__wcsmbs_gconv_fcts.tomb, &data, &inbuf, inbuf + sizeof (wchar_t), NULL, &dummy, 0, 1)); } @@ -109,4 +108,3 @@ __wcrtomb (char *s, wchar_t wc, mbstate_t *ps) return result; } weak_alias (__wcrtomb, wcrtomb) -libc_hidden_weak (wcrtomb) diff --git a/src/kernel/libroot/posix/glibc/wcsmbs/wcsmbsload.c b/src/kernel/libroot/posix/glibc/wcsmbs/wcsmbsload.c index 2fea6c38b3..74f62d36f9 100644 --- a/src/kernel/libroot/posix/glibc/wcsmbs/wcsmbsload.c +++ b/src/kernel/libroot/posix/glibc/wcsmbs/wcsmbsload.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1998. @@ -26,6 +26,23 @@ #include #include #include +#include + +void +internal_function +__wcsmbs_load_conv (const struct locale_data *new_category) +{ +} + +static void __attribute__ ((unused)) +free_mem (void) +{ +} + +/* Last loaded locale for LC_CTYPE. We initialize for the C locale + which is enabled at startup. */ +extern const struct locale_data _nl_C_LC_CTYPE; +const struct locale_data *__wcsmbs_last_locale = &_nl_C_LC_CTYPE; /* These are the descriptions for the default conversion functions. */ @@ -36,8 +53,7 @@ static struct __gconv_step to_wc = .__counter = INT_MAX, .__from_name = (char *) "ANSI_X3.4-1968//TRANSLIT", .__to_name = (char *) "INTERNAL", - .__fct = __gconv_transform_ascii_internal, - .__btowc_fct = __gconv_btwoc_ascii, + .__fct = NULL, // __gconv_transform_ascii_internal, .__init_fct = NULL, .__end_fct = NULL, .__min_needed_from = 1, @@ -55,8 +71,7 @@ static struct __gconv_step to_mb = .__counter = INT_MAX, .__from_name = (char *) "INTERNAL", .__to_name = (char *) "ANSI_X3.4-1968//TRANSLIT", - .__fct = __gconv_transform_internal_ascii, - .__btowc_fct = NULL, + .__fct = NULL, // __gconv_transform_internal_ascii, .__init_fct = NULL, .__end_fct = NULL, .__min_needed_from = 4, @@ -69,7 +84,7 @@ static struct __gconv_step to_mb = /* For the default locale we only have to handle ANSI_X3.4-1968. */ -const struct gconv_fcts __wcsmbs_gconv_fcts_c = +struct gconv_fcts __wcsmbs_gconv_fcts = { .towc = &to_wc, .towc_nsteps = 1, @@ -77,10 +92,10 @@ const struct gconv_fcts __wcsmbs_gconv_fcts_c = .tomb_nsteps = 1 }; +#if 0 -struct __gconv_step * -attribute_hidden -__wcsmbs_getfct (const char *to, const char *from, size_t *nstepsp) +static inline struct __gconv_step * +getfct (const char *to, const char *from, size_t *nstepsp) { size_t nsteps; struct __gconv_step *result; @@ -144,74 +159,88 @@ __wcsmbs_getfct (const char *to, const char *from, size_t *nstepsp) }) -/* Some of the functions here must not be used while setlocale is called. */ -__libc_lock_define (extern, __libc_setlocale_lock attribute_hidden) +/* We must modify global data. */ +__libc_lock_define_initialized (static, lock) + /* Load conversion functions for the currently selected locale. */ void internal_function -__wcsmbs_load_conv (struct locale_data *new_category) +__wcsmbs_load_conv (const struct locale_data *new_category) { /* Acquire the lock. */ - __libc_lock_lock (__libc_setlocale_lock); + __libc_lock_lock (lock); /* We should repeat the test since while we waited some other thread might have run this function. */ - if (__builtin_expect (new_category->private.ctype == NULL, 1)) + if (__builtin_expect (__wcsmbs_last_locale != new_category, 1)) { - /* We must find the real functions. */ - const char *charset_name; - const char *complete_name; - struct gconv_fcts *new_fcts; - int use_translit; - - /* Allocate the gconv_fcts structure. */ - new_fcts = malloc (sizeof *new_fcts); - if (new_fcts == NULL) - goto failed; - - /* Get name of charset of the locale. */ - charset_name = new_category->values[_NL_ITEM_INDEX(CODESET)].string; - - /* Does the user want transliteration? */ - use_translit = new_category->use_translit; - - /* Normalize the name and add the slashes necessary for a - complete lookup. */ - complete_name = norm_add_slashes (charset_name, - use_translit ? "TRANSLIT" : NULL); - - /* It is not necessary to use transliteration in this direction - since the internal character set is supposed to be able to - represent all others. */ - new_fcts->towc = __wcsmbs_getfct ("INTERNAL", complete_name, - &new_fcts->towc_nsteps); - new_fcts->tomb = (new_fcts->towc != NULL - ? __wcsmbs_getfct (complete_name, "INTERNAL", - &new_fcts->tomb_nsteps) - : NULL); - - /* If any of the conversion functions is not available we don't - use any since this would mean we cannot convert back and - forth.*/ - if (new_fcts->tomb == NULL) + if (new_category->name == _nl_C_name) /* Yes, pointer comparison. */ { - if (new_fcts->towc != NULL) - __gconv_close_transform (new_fcts->towc, new_fcts->towc_nsteps); - - free (new_fcts); - failed: - new_category->private.ctype = &__wcsmbs_gconv_fcts_c; + __wcsmbs_gconv_fcts.towc = &to_wc; + __wcsmbs_gconv_fcts.tomb = &to_mb; } else { - new_category->private.ctype = new_fcts; - new_category->private.cleanup = &_nl_cleanup_ctype; + /* We must find the real functions. */ + const char *charset_name; + const char *complete_name; + struct __gconv_step *new_towc; + size_t new_towc_nsteps; + struct __gconv_step *new_tomb; + size_t new_tomb_nsteps; + int use_translit; + + /* Free the old conversions. */ + if (__wcsmbs_gconv_fcts.tomb != &to_mb) + __gconv_close_transform (__wcsmbs_gconv_fcts.tomb, + __wcsmbs_gconv_fcts.tomb_nsteps); + if (__wcsmbs_gconv_fcts.towc != &to_wc) + __gconv_close_transform (__wcsmbs_gconv_fcts.towc, + __wcsmbs_gconv_fcts.towc_nsteps); + + /* Get name of charset of the locale. */ + charset_name = new_category->values[_NL_ITEM_INDEX(CODESET)].string; + + /* Does the user want transliteration? */ + use_translit = new_category->use_translit; + + /* Normalize the name and add the slashes necessary for a + complete lookup. */ + complete_name = norm_add_slashes (charset_name, + use_translit ? "TRANSLIT" : NULL); + + /* It is not necessary to use transliteration in this direction + since the internal character set is supposed to be able to + represent all others. */ + new_towc = getfct ("INTERNAL", complete_name, &new_towc_nsteps); + new_tomb = (new_towc != NULL + ? getfct (complete_name, "INTERNAL", &new_tomb_nsteps) + : NULL); + + /* If any of the conversion functions is not available we don't + use any since this would mean we cannot convert back and + forth.*/ + if (new_towc == NULL || new_tomb == NULL) + { + if (new_towc != NULL) + __gconv_close_transform (new_towc, 1); + + goto failed; + } + + __wcsmbs_gconv_fcts.tomb = new_tomb; + __wcsmbs_gconv_fcts.tomb_nsteps = new_tomb_nsteps; + __wcsmbs_gconv_fcts.towc = new_towc; + __wcsmbs_gconv_fcts.towc_nsteps = new_towc_nsteps; } + + /* Set last-used variable for current locale. */ + __wcsmbs_last_locale = new_category; } - __libc_lock_unlock (__libc_setlocale_lock); + __libc_lock_unlock (lock); } @@ -220,19 +249,22 @@ void internal_function __wcsmbs_clone_conv (struct gconv_fcts *copy) { - const struct gconv_fcts *orig; + /* First make sure the function table is up-to-date. */ + update_conversion_ptrs (); - orig = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE)); + /* Make sure the data structures remain the same until we are finished. */ + __libc_lock_lock (lock); /* Copy the data. */ - *copy = *orig; + *copy = __wcsmbs_gconv_fcts; - /* Now increment the usage counters. - Note: This assumes copy->towc_nsteps == 1 and copy->tomb_nsteps == 1. */ + /* Now increment the usage counters. */ if (copy->towc->__shlib_handle != NULL) ++copy->towc->__counter; if (copy->tomb->__shlib_handle != NULL) ++copy->tomb->__counter; + + __libc_lock_unlock (lock); } @@ -241,10 +273,10 @@ int internal_function __wcsmbs_named_conv (struct gconv_fcts *copy, const char *name) { - copy->towc = __wcsmbs_getfct ("INTERNAL", name, ©->towc_nsteps); + copy->towc = getfct ("INTERNAL", name, ©->towc_nsteps); if (copy->towc != NULL) { - copy->tomb = __wcsmbs_getfct (name, "INTERNAL", ©->tomb_nsteps); + copy->tomb = getfct (name, "INTERNAL", ©->tomb_nsteps); if (copy->tomb == NULL) __gconv_close_transform (copy->towc, copy->towc_nsteps); } @@ -252,18 +284,30 @@ __wcsmbs_named_conv (struct gconv_fcts *copy, const char *name) return copy->towc == NULL || copy->tomb == NULL ? 1 : 0; } -void internal_function -_nl_cleanup_ctype (struct locale_data *locale) -{ - const struct gconv_fcts *const data = locale->private.ctype; - if (data != NULL) - { - locale->private.ctype = NULL; - locale->private.cleanup = NULL; - /* Free the old conversions. */ - __gconv_close_transform (data->tomb, data->tomb_nsteps); - __gconv_close_transform (data->towc, data->towc_nsteps); - free ((char *) data); +/* Free all resources if necessary. */ +static void __attribute__ ((unused)) +free_mem (void) +{ + if (__wcsmbs_gconv_fcts.tomb != &to_mb) + { + struct __gconv_step *old = __wcsmbs_gconv_fcts.tomb; + size_t nold = __wcsmbs_gconv_fcts.tomb_nsteps; + __wcsmbs_gconv_fcts.tomb = &to_mb; + __wcsmbs_gconv_fcts.tomb_nsteps = 1; + __gconv_release_cache (old, nold); + } + + if (__wcsmbs_gconv_fcts.towc != &to_wc) + { + struct __gconv_step *old = __wcsmbs_gconv_fcts.towc; + size_t nold = __wcsmbs_gconv_fcts.towc_nsteps; + __wcsmbs_gconv_fcts.towc = &to_wc; + __wcsmbs_gconv_fcts.towc_nsteps = 1; + __gconv_release_cache (old, nold); } } + +#endif + +text_set_element (__libc_subfreeres, free_mem); diff --git a/src/kernel/libroot/posix/glibc/wcsmbs/wcsmbsload.h b/src/kernel/libroot/posix/glibc/wcsmbs/wcsmbsload.h index 12cd75cdb4..6aa6139f77 100644 --- a/src/kernel/libroot/posix/glibc/wcsmbs/wcsmbsload.h +++ b/src/kernel/libroot/posix/glibc/wcsmbs/wcsmbsload.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1998. @@ -17,9 +17,6 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef _WCSMBSLOAD_H -#define _WCSMBSLOAD_H 1 - #include #include #include @@ -35,10 +32,15 @@ struct gconv_fcts }; /* Set of currently active conversion functions. */ -extern const struct gconv_fcts __wcsmbs_gconv_fcts_c attribute_hidden; +extern struct gconv_fcts __wcsmbs_gconv_fcts; + + +/* Last loaded locale for LC_CTYPE. */ +extern const struct locale_data *__wcsmbs_last_locale; + /* Load conversion functions for the currently selected locale. */ -extern void __wcsmbs_load_conv (struct locale_data *new_category) +extern void __wcsmbs_load_conv (const struct locale_data *new_category) internal_function; /* Clone the current `__wcsmbs_load_conv' value. */ @@ -49,33 +51,12 @@ extern void __wcsmbs_clone_conv (struct gconv_fcts *copy) extern int __wcsmbs_named_conv (struct gconv_fcts *copy, const char *name) internal_function; -/* Function used for the `private.cleanup' hook. */ -extern void _nl_cleanup_ctype (struct locale_data *) - internal_function attribute_hidden; - - -#include - - -/* Load the function implementation if necessary. */ -extern struct __gconv_step *__wcsmbs_getfct (const char *to, const char *from, - size_t *nstepsp) - attribute_hidden; - -extern const struct locale_data _nl_C_LC_CTYPE attribute_hidden; /* Check whether the LC_CTYPE locale changed since the last call. Update the pointers appropriately. */ -static inline const struct gconv_fcts * -get_gconv_fcts (struct locale_data *data) +static inline void +update_conversion_ptrs (void) { - if (__builtin_expect (data->private.u.ctype == NULL, 0)) - { - if (__builtin_expect (data == &_nl_C_LC_CTYPE, 0)) - return &__wcsmbs_gconv_fcts_c; - __wcsmbs_load_conv (data); - } - return data->private.u.ctype; + if (__wcsmbs_last_locale != _nl_current_LC_CTYPE) + __wcsmbs_load_conv (_nl_current_LC_CTYPE); } - -#endif /* wcsmbsload.h */ diff --git a/src/kernel/libroot/posix/glibc/wcsmbs/wcsrtombs.c b/src/kernel/libroot/posix/glibc/wcsmbs/wcsrtombs.c index dda115dfd3..e0382b4bb9 100644 --- a/src/kernel/libroot/posix/glibc/wcsmbs/wcsrtombs.c +++ b/src/kernel/libroot/posix/glibc/wcsmbs/wcsrtombs.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996,1997,1998,1999,2000,2002 Free Software Foundation, Inc. +/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 1996. @@ -45,7 +45,6 @@ __wcsrtombs (dst, src, len, ps) int status; size_t result; struct __gconv_step *tomb; - const struct gconv_fcts *fcts; /* Tell where we want the result. */ data.__invocation_counter = 0; @@ -54,11 +53,11 @@ __wcsrtombs (dst, src, len, ps) data.__statep = ps ?: &state; data.__trans = NULL; - /* Get the conversion functions. */ - fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE)); + /* Make sure we use the correct function. */ + update_conversion_ptrs (); /* Get the structure with the function pointers. */ - tomb = fcts->tomb; + tomb = __wcsmbs_gconv_fcts.tomb; /* We have to handle DST == NULL special. */ if (dst == NULL)