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
14using BPrivate::Libroot::gPosixLanginfo;
15using BPrivate::Libroot::GetCurrentLocaleBackend;
16using BPrivate::Libroot::LocaleBackend;
17using BPrivate::Libroot::LocaleBackendData;
18
19
20extern "C" char*
21nl_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
33extern "C" char*
34nl_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