274 lines
7.2 KiB
HTML
274 lines
7.2 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of DUPLOCALE</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>DUPLOCALE</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"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
duplocale - duplicate a locale object
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/locale.h">locale.h</A>></B>
|
|
|
|
<B>locale_t duplocale(locale_t </B><I>locobj</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>duplocale</B>():
|
|
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
<DL COMPACT>
|
|
<DT id="2">Since glibc 2.10:<DD>
|
|
_XOPEN_SOURCE >= 700
|
|
<DT id="3">Before glibc 2.10:<DD>
|
|
_GNU_SOURCE
|
|
</DL>
|
|
</DL>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>duplocale</B>()
|
|
|
|
function creates a duplicate of the locale object referred to by
|
|
<I>locobj</I>.
|
|
|
|
<P>
|
|
|
|
If
|
|
<I>locobj</I>
|
|
|
|
is
|
|
<B>LC_GLOBAL_LOCALE</B>,
|
|
|
|
<B>duplocale</B>()
|
|
|
|
creates a locale object containing a copy of the global locale
|
|
determined by
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setlocale">setlocale</A></B>(3).
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success,
|
|
<B>duplocale</B>()
|
|
|
|
returns a handle for the new locale object.
|
|
On error, it returns
|
|
<I>(locale_t) 0,</I>
|
|
|
|
and sets
|
|
<I>errno</I>
|
|
|
|
to indicate the cause of the error.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="4"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
Insufficient memory to create the duplicate locale object.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
The
|
|
<B>duplocale</B>()
|
|
|
|
function first appeared in version 2.3 of the GNU C library.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2008.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Duplicating a locale can serve the following purposes:
|
|
<DL COMPACT>
|
|
<DT id="5">*<DD>
|
|
To create a copy of a locale object in which one of more categories
|
|
are to be modified (using
|
|
<B><A HREF="/cgi-bin/man/man2html?3+newlocale">newlocale</A></B>(3)).
|
|
|
|
<DT id="6">*<DD>
|
|
To obtain a handle for the current locale which can used in
|
|
other functions that employ a locale handle, such as
|
|
<B><A HREF="/cgi-bin/man/man2html?3+toupper_l">toupper_l</A></B>(3).
|
|
|
|
This is done by applying
|
|
<B>duplocale</B>()
|
|
|
|
to the value returned by the following call:
|
|
<DT id="7"><DD>
|
|
<BR> loc = uselocale((locale_t) 0);
|
|
<DT id="8"><DD>
|
|
This technique is necessary, because the above
|
|
<B><A HREF="/cgi-bin/man/man2html?3+uselocale">uselocale</A></B>(3)
|
|
|
|
call may return the value
|
|
<B>LC_GLOBAL_LOCALE</B>,
|
|
|
|
which results in undefined behavior if passed to functions such as
|
|
<B><A HREF="/cgi-bin/man/man2html?3+toupper_l">toupper_l</A></B>(3).
|
|
|
|
Calling
|
|
<B>duplocale</B>()
|
|
|
|
can be used to ensure that the
|
|
<B>LC_GLOBAL_LOCALE</B>
|
|
|
|
value is converted into a usable locale object.
|
|
See EXAMPLE, below.
|
|
</DL>
|
|
<P>
|
|
|
|
Each locale object created by
|
|
<B>duplocale</B>()
|
|
|
|
should be deallocated using
|
|
<B><A HREF="/cgi-bin/man/man2html?3+freelocale">freelocale</A></B>(3).
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
The program below uses
|
|
<B><A HREF="/cgi-bin/man/man2html?3+uselocale">uselocale</A></B>(3)
|
|
|
|
and
|
|
<B>duplocale</B>()
|
|
|
|
to obtain a handle for the current locale which is then passed to
|
|
<B><A HREF="/cgi-bin/man/man2html?3+toupper_l">toupper_l</A></B>(3).
|
|
|
|
The program takes one command-line argument,
|
|
a string of characters that is converted to uppercase and
|
|
displayed on standard output.
|
|
An example of its use is the following:
|
|
<P>
|
|
|
|
|
|
|
|
$ <B>./a.out abc</B>
|
|
ABC
|
|
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H3>Program source</H3>
|
|
|
|
|
|
|
|
#define _XOPEN_SOURCE 700
|
|
#include <<A HREF="file:///usr/include/ctype.h">ctype.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/locale.h">locale.h</A>>
|
|
<P>
|
|
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \
|
|
<BR> } while (0)
|
|
<P>
|
|
int
|
|
main(int argc, char *argv[])
|
|
{
|
|
<BR> locale_t loc, nloc;
|
|
<BR> char *p;
|
|
<P>
|
|
<BR> if (argc != 2) {
|
|
<BR> fprintf(stderr, "Usage: %s string\n", argv[0]);
|
|
<BR> exit(EXIT_FAILURE);
|
|
<BR> }
|
|
<P>
|
|
<BR> /* This sequence is necessary, because uselocale() might return
|
|
<BR> the value LC_GLOBAL_LOCALE, which can't be passed as an
|
|
<BR> argument to toupper_l() */
|
|
<P>
|
|
<BR> loc = uselocale((locale_t) 0);
|
|
<BR> if (loc == (locale_t) 0)
|
|
<BR> errExit("uselocale");
|
|
<P>
|
|
<BR> nloc = duplocale(loc);
|
|
<BR> if (nloc == (locale_t) 0)
|
|
<BR> errExit("duplocale");
|
|
<P>
|
|
<BR> for (p = argv[1]; *p; p++)
|
|
<BR> putchar(toupper_l(*p, nloc));
|
|
<P>
|
|
<BR> printf("\n");
|
|
<P>
|
|
<BR> freelocale(nloc);
|
|
<P>
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+freelocale">freelocale</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+newlocale">newlocale</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setlocale">setlocale</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+uselocale">uselocale</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+locale">locale</A></B>(5),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+locale">locale</A></B>(7)
|
|
|
|
<A NAME="lbAM"> </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"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="9"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="10"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="11"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="12"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="13"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="14"><A HREF="#lbAG">VERSIONS</A><DD>
|
|
<DT id="15"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="16"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="17"><A HREF="#lbAJ">EXAMPLE</A><DD>
|
|
<DL>
|
|
<DT id="18"><A HREF="#lbAK">Program source</A><DD>
|
|
</DL>
|
|
<DT id="19"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="20"><A HREF="#lbAM">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:39 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|