man-pages/man3/nl_langinfo.3.html
2021-03-31 01:06:50 +01:00

333 lines
8.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of NL_LANGINFO</TITLE>
</HEAD><BODY>
<H1>NL_LANGINFO</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
nl_langinfo, nl_langinfo_l - query language and locale information
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/langinfo.h">langinfo.h</A>&gt;</B>
<B>char *nl_langinfo(nl_item </B><I>item</I><B>);</B>
<B>char *nl_langinfo_l(nl_item </B><I>item</I><B>, locale_t </B><I>locale</I><B>);</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>nl_langinfo_l</B>():
<DL COMPACT><DT id="1"><DD>
Since glibc 2.24:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200809L
<BR>
Glibc 2.23 and earlier:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;_POSIX_C_SOURCE&nbsp;&gt;=&nbsp;200112L
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>nl_langinfo</B>()
and
<B>nl_langinfo_l</B>()
functions provide access to locale information
in a more flexible way than
<B><A HREF="/cgi-bin/man/man2html?3+localeconv">localeconv</A></B>(3).
<B>nl_langinfo</B>()
returns a string which is the value corresponding to
<I>item</I> in the program's current global
locale.
<B>nl_langinfo_l</B>()
returns a string which is the value corresponding to <I>item</I>
for the locale identified by the locale object <I>locale</I>,
which was previously created by
<B><A HREF="/cgi-bin/man/man2html?1+newlocale">newlocale</A></B>(1).
Individual and additional elements of the locale categories can
be queried.
<B><A HREF="/cgi-bin/man/man2html?3+setlocale">setlocale</A></B>(3)
needs to be executed with proper arguments before.
<P>
Examples for the locale elements that can be specified in <I>item</I>
using the constants defined in <I>&lt;<A HREF="file:///usr/include/langinfo.h">langinfo.h</A>&gt;</I> are:
<DL COMPACT>
<DT id="2"><B>CODESET</B>&nbsp;(LC_CTYPE)
<DD>
Return a string with the name of the character encoding used in the
selected locale, such as &quot;UTF-8&quot;, &quot;ISO-8859-1&quot;, or &quot;ANSI_X3.4-1968&quot;
(better known as US-ASCII).
This is the same string that you get with
&quot;locale charmap&quot;.
For a list of character encoding names,
try &quot;locale -m&quot; (see
<B><A HREF="/cgi-bin/man/man2html?1+locale">locale</A></B>(1)).
<DT id="3"><B>D_T_FMT</B>&nbsp;(LC_TIME)
<DD>
Return a string that can be used as a format string for
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3)
to represent time and date in a locale-specific way.
<DT id="4"><B>D_FMT</B>&nbsp;(LC_TIME)
<DD>
Return a string that can be used as a format string for
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3)
to represent a date in a locale-specific way.
<DT id="5"><B>T_FMT</B>&nbsp;(LC_TIME)
<DD>
Return a string that can be used as a format string for
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3)
to represent a time in a locale-specific way.
<DT id="6"><B>DAY_</B>{1-7} (LC_TIME)
<DD>
Return name of the <I>n</I>-th day of the week. [Warning: this follows
the US convention DAY_1 = Sunday, not the international convention
(ISO 8601) that Monday is the first day of the week.]
<DT id="7"><B>ABDAY_</B>{1-7} (LC_TIME)
<DD>
Return abbreviated name of the <I>n</I>-th day of the week.
<DT id="8"><B>MON_</B>{1-12} (LC_TIME)
<DD>
Return name of the <I>n</I>-th month.
<DT id="9"><B>ABMON_</B>{1-12} (LC_TIME)
<DD>
Return abbreviated name of the <I>n</I>-th month.
<DT id="10"><B>RADIXCHAR</B>&nbsp;(LC_NUMERIC)
<DD>
Return radix character (decimal dot, decimal comma, etc.).
<DT id="11"><B>THOUSEP</B>&nbsp;(LC_NUMERIC)
<DD>
Return separator character for thousands (groups of three digits).
<DT id="12"><B>YESEXPR</B>&nbsp;(LC_MESSAGES)
<DD>
Return a regular expression that can be used with the
<B><A HREF="/cgi-bin/man/man2html?3+regex">regex</A></B>(3)
function to recognize a positive response to a yes/no question.
<DT id="13"><B>NOEXPR</B>&nbsp;(LC_MESSAGES)
<DD>
Return a regular expression that can be used with the
<B><A HREF="/cgi-bin/man/man2html?3+regex">regex</A></B>(3)
function to recognize a negative response to a yes/no question.
<DT id="14"><B>CRNCYSTR</B>&nbsp;(LC_MONETARY)
<DD>
Return the currency symbol, preceded by &quot;-&quot; if the symbol should
appear before the value, &quot;+&quot; if the symbol should appear after the
value, or &quot;.&quot; if the symbol should replace the radix character.
</DL>
<P>
The above list covers just some examples of items that can be requested.
For a more detailed list, consult
<I>The GNU C Library Reference Manual</I>.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success, these functions return a pointer to a string which
is the value corresponding to
<I>item</I>
in the specified locale.
<P>
If no locale has been selected by
<B><A HREF="/cgi-bin/man/man2html?3+setlocale">setlocale</A></B>(3)
for the appropriate category,
<B>nl_langinfo</B>()
return a pointer to the corresponding string in the &quot;C&quot; locale.
The same is true of
<B>nl_langinfo_l</B>()
if
<I>locale</I>
specifies a locale where
<I>langinfo</I>
data is not defined.
<P>
If <I>item</I> is not valid, a pointer to an empty string is returned.
<P>
The pointer returned by these functions may point to static data that
may be overwritten, or the pointer itself may be invalidated,
by a subsequent call to
<B>nl_langinfo</B>(),
<B>nl_langinfo_l</B>(),
or
<B><A HREF="/cgi-bin/man/man2html?3+setlocale">setlocale</A></B>(3).
The same statements apply to
<B>nl_langinfo_l</B>()
if the locale object referred to by
<I>locale</I>
is freed or modified by
<B><A HREF="/cgi-bin/man/man2html?3+freelocale">freelocale</A></B>(3)
or
<B><A HREF="/cgi-bin/man/man2html?3+newlocale">newlocale</A></B>(3).
<P>
POSIX specifies that the application may not modify
the string returned by these functions.
<A NAME="lbAF">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>nl_langinfo</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
</TABLE>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, SUSv2.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
The behavior of
<B>nl_langinfo_l</B>()
is undefined if
<I>locale</I>
is the special locale object
<B>LC_GLOBAL_LOCALE</B>
or is not a valid locale object handle.
<A NAME="lbAI">&nbsp;</A>
<H2>EXAMPLE</H2>
The following program sets the character type and the numeric locale
according to the environment and queries the terminal character set and
the radix character.
<P>
#include &lt;<A HREF="file:///usr/include/langinfo.h">langinfo.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/locale.h">locale.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
<P>
int
main(int argc, char *argv[])
{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;setlocale(LC_CTYPE,&nbsp;&quot;&quot;);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;setlocale(LC_NUMERIC,&nbsp;&quot;&quot;);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;%s\n&quot;,&nbsp;nl_langinfo(CODESET));
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;%s\n&quot;,&nbsp;nl_langinfo(RADIXCHAR));
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_SUCCESS);
}
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+locale">locale</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?3+localeconv">localeconv</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+setlocale">setlocale</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+charsets">charsets</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+locale">locale</A></B>(7)
<P>
The GNU C Library Reference Manual
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="15"><A HREF="#lbAB">NAME</A><DD>
<DT id="16"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="17"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="18"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="19"><A HREF="#lbAF">ATTRIBUTES</A><DD>
<DT id="20"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="21"><A HREF="#lbAH">NOTES</A><DD>
<DT id="22"><A HREF="#lbAI">EXAMPLE</A><DD>
<DT id="23"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="24"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:49 GMT, March 31, 2021
</BODY>
</HTML>