Print this page
2964 need POSIX 2008 locale object support
*** 33,42 ****
--- 33,44 ----
static struct lc_time_T _time_locale;
static int _time_using_locale;
static char *time_locale_buf;
+ struct xlocale_time __xlocale_global_time;
+
#define LCTIME_SIZE (sizeof (struct lc_time_T) / sizeof (char *))
static const struct lc_time_T _C_time_locale = {
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
*** 82,100 ****
* ampm_fmt - To determine 12-hour clock format time (empty, if N/A)
*/
"%I:%M:%S %p"
};
struct lc_time_T *
! __get_current_time_locale(void)
{
! return (_time_using_locale ? &_time_locale :
! (struct lc_time_T *)&_C_time_locale);
}
int
__time_load_locale(const char *name)
{
! return (__part_load_locale(name, &_time_using_locale,
! &time_locale_buf, "LC_TIME", LCTIME_SIZE, LCTIME_SIZE,
! (const char **)&_time_locale));
}
--- 84,143 ----
* ampm_fmt - To determine 12-hour clock format time (empty, if N/A)
*/
"%I:%M:%S %p"
};
+ static void
+ destruct_time(void *v)
+ {
+ struct xlocale_time *l = v;
+
+ if (l->buffer != NULL)
+ free(l->buffer);
+
+ free(l);
+ }
+
struct lc_time_T *
! __get_current_time_locale(locale_t loc)
{
! return (loc->using_time_locale
! ? &((struct xlocale_time *)loc->components[XLC_TIME])->locale
! : (struct lc_time_T *)&_C_time_locale);
! }
!
! static int
! time_load_locale(struct xlocale_time *l, int *using_locale, const char *name)
! {
! struct lc_time_T *time_locale = &l->locale;
!
! return (__part_load_locale(name, using_locale,
! &l->buffer, "LC_TIME",
! LCTIME_SIZE, LCTIME_SIZE,
! (const char **)time_locale));
}
int
__time_load_locale(const char *name)
{
! return (time_load_locale(&__xlocale_global_time,
! &__xlocale_global_locale.using_time_locale, name));
! }
!
! void *
! __time_load(const char* name, locale_t loc)
! {
! struct xlocale_time *new;
!
! new = calloc(sizeof(struct xlocale_time), 1);
! if (new == NULL)
! return (NULL);
!
! new->header.header.destructor = destruct_time;
! if (time_load_locale(new, &loc->using_time_locale, name) ==
! _LDP_ERROR) {
! xlocale_release(new);
! return (NULL);
! }
!
! return (new);
}