xref: /haiku/src/system/libroot/posix/locale/nl_langinfo.cpp (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
1 /*
2  * Copyright 2010, Oliver Tappe, zooey@hirschkaefer.de
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <langinfo.h>
8 
9 #include "LocaleBackend.h"
10 
11 #include <PosixLanginfo.h>
12 
13 
14 using BPrivate::Libroot::gPosixLanginfo;
15 using BPrivate::Libroot::GetCurrentLocaleBackend;
16 using BPrivate::Libroot::LocaleBackend;
17 using BPrivate::Libroot::LocaleBackendData;
18 
19 
20 extern "C" char*
21 nl_langinfo(nl_item item)
22 {
23 	if (item < 0 || item >= _NL_LANGINFO_LAST)
24 		return const_cast<char*>("");
25 
26 	if (GetCurrentLocaleBackend() != NULL)
27 		return const_cast<char*>(GetCurrentLocaleBackend()->GetLanginfo(item));
28 
29 	return const_cast<char*>(gPosixLanginfo[item]);
30 }
31 
32 
33 extern "C" char*
34 nl_langinfo_l(nl_item item, locale_t locale)
35 {
36 	if (item < 0 || item >= _NL_LANGINFO_LAST)
37 		return const_cast<char*>("");
38 
39 	LocaleBackend* backend = ((LocaleBackendData*)locale)->backend;
40 
41 	if (backend != NULL)
42 		return const_cast<char*>(backend->GetLanginfo(item));
43 
44 	return const_cast<char*>(gPosixLanginfo[item]);
45 }
46