xref: /titanic_44/usr/src/lib/libc/port/locale/localeimpl.h (revision 732efd5515b5788339f3da4db04de7cea0f79c86)
12d08521bSGarrett D'Amore /*
22d08521bSGarrett D'Amore  * This file and its contents are supplied under the terms of the
32d08521bSGarrett D'Amore  * Common Development and Distribution License ("CDDL"), version 1.0.
42d08521bSGarrett D'Amore  * You may only use this file in accordance with the terms of version
52d08521bSGarrett D'Amore  * 1.0 of the CDDL.
62d08521bSGarrett D'Amore  *
72d08521bSGarrett D'Amore  * A full copy of the text of the CDDL should have accompanied this
82d08521bSGarrett D'Amore  * source.  A copy of the CDDL is also available via the Internet at
92d08521bSGarrett D'Amore  * http://www.illumos.org/license/CDDL.
102d08521bSGarrett D'Amore  */
112d08521bSGarrett D'Amore 
122d08521bSGarrett D'Amore /*
132d08521bSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
142d08521bSGarrett D'Amore  */
152d08521bSGarrett D'Amore 
162d08521bSGarrett D'Amore /*
172d08521bSGarrett D'Amore  * This file implements the 2008 newlocale and friends handling. It is
182d08521bSGarrett D'Amore  * private to libc.
192d08521bSGarrett D'Amore  */
202d08521bSGarrett D'Amore #ifndef	_LOCALEIMPL_H_
212d08521bSGarrett D'Amore #define	_LOCALEIMPL_H_
222d08521bSGarrett D'Amore 
232d08521bSGarrett D'Amore #ifndef _LCONV_C99
242d08521bSGarrett D'Amore #define	_LCONV_C99	/* so we get all the extensions */
252d08521bSGarrett D'Amore #endif
262d08521bSGarrett D'Amore 
272d08521bSGarrett D'Amore #include <sys/types.h>
282d08521bSGarrett D'Amore #include <locale.h>
292d08521bSGarrett D'Amore #include <xlocale.h>
302d08521bSGarrett D'Amore #include "setlocale.h"
312d08521bSGarrett D'Amore #include "runetype.h"
322d08521bSGarrett D'Amore 
332d08521bSGarrett D'Amore /* private locale structures */
342d08521bSGarrett D'Amore 
352d08521bSGarrett D'Amore /*
362d08521bSGarrett D'Amore  * Because some locale data is rather ahem.. large, we would like to keep
372d08521bSGarrett D'Amore  * reference counts on it.  We create an abstract header (locdata) structure
382d08521bSGarrett D'Amore  * which keeps a point to the opaque per-category data, along with a reference
392d08521bSGarrett D'Amore  * count to it.  To be threadsafe, we will use atomics when holding it or
402d08521bSGarrett D'Amore  * freeing it.  (This only occurs when locale objects are created or destroyed,
412d08521bSGarrett D'Amore  * so there should be no performance impact on hot code paths.  If your code
422d08521bSGarrett D'Amore  * uses locale_t creation/destruction on a hot code path, its broken.  But
432d08521bSGarrett D'Amore  * even so, the atomic and reference counting will probably *greatly* improve
442d08521bSGarrett D'Amore  * your life as bootstrapping locale data from files is quite expensive.
452d08521bSGarrett D'Amore  */
462d08521bSGarrett D'Amore 
472d08521bSGarrett D'Amore #define	NLOCDATA	4
482d08521bSGarrett D'Amore struct locdata {
492d08521bSGarrett D'Amore 	char		l_lname[ENCODING_LEN+1];	/* locale name */
502d08521bSGarrett D'Amore 	void		*l_data[NLOCDATA];		/* storage area */
512d08521bSGarrett D'Amore 	void		*l_map;				/* mapped file */
522d08521bSGarrett D'Amore 	size_t		l_map_len;
532d08521bSGarrett D'Amore 	struct locdata	*l_next;			/* link cached list */
542d08521bSGarrett D'Amore 	int		l_cached;			/* nonzero if cached */
552d08521bSGarrett D'Amore };
562d08521bSGarrett D'Amore 
572d08521bSGarrett D'Amore 
58*732efd55SDan McDonald struct _locale {
592d08521bSGarrett D'Amore 	struct locdata	*locdata[LC_ALL];
60*732efd55SDan McDonald 	struct _locale	*next;
612d08521bSGarrett D'Amore 	int		on_list;	/* on linked list */
622d08521bSGarrett D'Amore 	char		locname[(ENCODING_LEN+1)*NLOCDATA + 1];
632d08521bSGarrett D'Amore 
642d08521bSGarrett D'Amore 	/*
652d08521bSGarrett D'Amore 	 * Convenience pointers.
662d08521bSGarrett D'Amore 	 */
672d08521bSGarrett D'Amore 	const struct lc_ctype		*ctype;
682d08521bSGarrett D'Amore 	const struct lc_collate		*collate;
692d08521bSGarrett D'Amore 	const struct lc_messages	*messages;
702d08521bSGarrett D'Amore 	const struct lc_monetary	*monetary;
712d08521bSGarrett D'Amore 	const struct lc_numeric		*numeric;
722d08521bSGarrett D'Amore 	const struct lc_time		*time;
732d08521bSGarrett D'Amore 	const _RuneLocale		*runelocale;
742d08521bSGarrett D'Amore 
752d08521bSGarrett D'Amore 	/*
762d08521bSGarrett D'Amore 	 * The loaded value is used for localeconv.  In paticular, when
772d08521bSGarrett D'Amore 	 * when we change the value of one of the above categories, we will
782d08521bSGarrett D'Amore 	 * also need to update the lconv structure.  The loaded bit indicates
792d08521bSGarrett D'Amore 	 * that the lconv structure is "current" for that category.  It's
802d08521bSGarrett D'Amore 	 * sort of an "inverse dirty" bit.
812d08521bSGarrett D'Amore 	 */
822d08521bSGarrett D'Amore 	int		loaded[LC_ALL];
832d08521bSGarrett D'Amore 	struct lconv	lconv;
842d08521bSGarrett D'Amore };
852d08521bSGarrett D'Amore 
862d08521bSGarrett D'Amore 
872d08521bSGarrett D'Amore struct locdata *__locdata_alloc(const char *, size_t);
882d08521bSGarrett D'Amore void __locdata_free(struct locdata *);
892d08521bSGarrett D'Amore struct locdata *__locdata_get_cache(int, const char *);
902d08521bSGarrett D'Amore void __locdata_set_cache(int, struct locdata *);
912d08521bSGarrett D'Amore 
922d08521bSGarrett D'Amore struct locdata *__lc_numeric_load(const char *name);
932d08521bSGarrett D'Amore struct locdata *__lc_monetary_load(const char *name);
942d08521bSGarrett D'Amore struct locdata *__lc_messages_load(const char *name);
952d08521bSGarrett D'Amore struct locdata *__lc_time_load(const char *name);
962d08521bSGarrett D'Amore struct locdata *__lc_ctype_load(const char *name);
972d08521bSGarrett D'Amore struct locdata *__lc_collate_load(const char *name);
982d08521bSGarrett D'Amore 
992d08521bSGarrett D'Amore extern struct locdata	__posix_numeric_locdata;
1002d08521bSGarrett D'Amore extern struct locdata	__posix_monetary_locdata;
1012d08521bSGarrett D'Amore extern struct locdata	__posix_messages_locdata;
1022d08521bSGarrett D'Amore extern struct locdata	__posix_time_locdata;
1032d08521bSGarrett D'Amore extern struct locdata	__posix_ctype_locdata;
1042d08521bSGarrett D'Amore extern struct locdata	__posix_collate_locdata;
1052d08521bSGarrett D'Amore extern locale_t ___global_locale;
1062d08521bSGarrett D'Amore 
1072d08521bSGarrett D'Amore #endif	/* _LOCALEIMPL_H_ */
108