xref: /openbsd-src/lib/libc/locale/nl_langinfo_l.c (revision 3a628b46e7aaa520a6215eccabf31d313c2e7de0)
1*3a628b46Sschwarze /*	$OpenBSD: nl_langinfo_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */
2*3a628b46Sschwarze /*
3*3a628b46Sschwarze  * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
4*3a628b46Sschwarze  *
5*3a628b46Sschwarze  * Permission to use, copy, modify, and distribute this software for any
6*3a628b46Sschwarze  * purpose with or without fee is hereby granted, provided that the above
7*3a628b46Sschwarze  * copyright notice and this permission notice appear in all copies.
8*3a628b46Sschwarze  *
9*3a628b46Sschwarze  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*3a628b46Sschwarze  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*3a628b46Sschwarze  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*3a628b46Sschwarze  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*3a628b46Sschwarze  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*3a628b46Sschwarze  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*3a628b46Sschwarze  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*3a628b46Sschwarze  */
17*3a628b46Sschwarze 
18*3a628b46Sschwarze #include <langinfo.h>
19*3a628b46Sschwarze #include <locale.h>
20*3a628b46Sschwarze 
21*3a628b46Sschwarze #include "rune.h"
22*3a628b46Sschwarze 
23*3a628b46Sschwarze char *
nl_langinfo_l(nl_item item,locale_t locale)24*3a628b46Sschwarze nl_langinfo_l(nl_item item, locale_t locale)
25*3a628b46Sschwarze {
26*3a628b46Sschwarze 	_RuneLocale	*rl;
27*3a628b46Sschwarze 	const char	*s;
28*3a628b46Sschwarze 
29*3a628b46Sschwarze 	if (item != CODESET)
30*3a628b46Sschwarze 		return nl_langinfo(item);
31*3a628b46Sschwarze 
32*3a628b46Sschwarze 	rl = NULL;
33*3a628b46Sschwarze 	if (locale == _LOCALE_UTF8)
34*3a628b46Sschwarze 		rl = _Utf8RuneLocale;
35*3a628b46Sschwarze 	if (rl == NULL)
36*3a628b46Sschwarze 		rl = &_DefaultRuneLocale;
37*3a628b46Sschwarze 
38*3a628b46Sschwarze 	s = rl->rl_codeset;
39*3a628b46Sschwarze 	if (s == NULL)
40*3a628b46Sschwarze 		s = "";
41*3a628b46Sschwarze 
42*3a628b46Sschwarze 	return (char *)s;
43*3a628b46Sschwarze }
44