
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
        "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyFirstUnitAd -->
<ins class="adsbygoogle"
     style="display:inline-block;width:970px;height:250px"
     data-ad-client="ca-pub-5778386704669218"
     data-ad-slot="1503492166"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" type="text/css" href="../../../style.css" title="style" />
    <link rel="stylesheet" type="text/css" href="../style.css" title="style" />
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />

    <title>duplocale(3) - Linux manual page</title>
</head>

<body>

<div class="page-top"><a id="top_of_page"></a></div>
<!--%%%TOP_BAR%%%-->
    <div class="nav-bar">
        <table class="nav-table">
            <tr>
                <td class="nav-cell">
                    <p class="nav-text">
                        <a href="http://man7.org/index.html">man7.org</a> &gt; Linux &gt; <a href="../index.html">man-pages</a>
                    </p>
                </td>
                <td class="training-cell">
                    <p class="training-text"><a class="training-link" href="http://man7.org/training/">Linux/UNIX system programming training</a></p>
                </td>
            </tr>
        </table>
    </div>

<hr class="nav-end" />

<!--%%%PAGE_START%%%-->


<table class="sec-table">
<tr>
    <td>
        <p class="section-dir">
<a href="duplocale.3.html#NAME">NAME</a> | <a href="duplocale.3.html#SYNOPSIS">SYNOPSIS</a> | <a href="duplocale.3.html#DESCRIPTION">DESCRIPTION</a> | <a href="duplocale.3.html#RETURN_VALUE">RETURN&nbsp;VALUE</a> | <a href="duplocale.3.html#ERRORS">ERRORS</a> | <a href="duplocale.3.html#VERSIONS">VERSIONS</a> | <a href="duplocale.3.html#CONFORMING_TO">CONFORMING&nbsp;TO</a> | <a href="duplocale.3.html#NOTES">NOTES</a> | <a href="duplocale.3.html#EXAMPLE">EXAMPLE</a> | <a href="duplocale.3.html#SEE_ALSO">SEE&nbsp;ALSO</a> | <a href="duplocale.3.html#COLOPHON">COLOPHON</a>
        </p>
    </td>
    <td class="search-box">
        <div class="man-search-box">

            <form method="get" action="http://www.google.com/search">
                <fieldset class="man-search">
                    <input type="text" name="q" size="10" maxlength="255" value="" />
                    <input type="hidden" name="sitesearch" value="man7.org/linux/man-pages" />
                    <input type="submit" name="sa" value="Search online pages" />
                </fieldset>
            </form>

        </div>
    </td>
    <td> </td>
</tr>
</table>

<pre>
<span class="headline">DUPLOCALE(3)              Linux Programmer's Manual             DUPLOCALE(3)</span>
</pre>
<h2><a id="NAME" href="duplocale.3.html#NAME"></a>NAME  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       duplocale - duplicate a locale object
</pre>
<h2><a id="SYNOPSIS" href="duplocale.3.html#SYNOPSIS"></a>SYNOPSIS  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       <b>#include &lt;locale.h&gt;</b>

       <b>locale_t duplocale(locale_t </b><i>locobj</i><b>);</b>

   Feature Test Macro Requirements for glibc (see <a href="../man7/feature_test_macros.7.html">feature_test_macros(7)</a>):

       <b>duplocale</b>():
           Since glibc 2.10:
                  _XOPEN_SOURCE &gt;= 700
           Before glibc 2.10:
                  _GNU_SOURCE
</pre>
<h2><a id="DESCRIPTION" href="duplocale.3.html#DESCRIPTION"></a>DESCRIPTION  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       The <b>duplocale</b>() function creates a duplicate of the locale object
       referred to by <i>locobj</i>.

       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 <a href="setlocale.3.html">setlocale(3)</a>.
</pre>
<h2><a id="RETURN_VALUE" href="duplocale.3.html#RETURN_VALUE"></a>RETURN VALUE  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       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><a href="errno.3.html">errno</a></i> to indicate the
       cause of the error.
</pre>
<h2><a id="ERRORS" href="duplocale.3.html#ERRORS"></a>ERRORS  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       <b>ENOMEM </b>Insufficient memory to create the duplicate locale object.
</pre>
<h2><a id="VERSIONS" href="duplocale.3.html#VERSIONS"></a>VERSIONS  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       The <b>duplocale</b>() function first appeared in version 2.3 of the GNU C
       library.
</pre>
<h2><a id="CONFORMING_TO" href="duplocale.3.html#CONFORMING_TO"></a>CONFORMING TO  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       POSIX.1-2008.
</pre>
<h2><a id="NOTES" href="duplocale.3.html#NOTES"></a>NOTES  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       Duplicating a locale can serve the following purposes:

       *  To create a copy of a locale object in which one of more
          categories are to be modified (using <a href="newlocale.3.html">newlocale(3)</a>).

       *  To obtain a handle for the current locale which can used in other
          functions that employ a locale handle, such as <a href="toupper_l.3.html">toupper_l(3)</a>.  This
          is done by applying <b>duplocale</b>() to the value returned by the
          following call:

              loc = uselocale((locale_t) 0);

          This technique is necessary, because the above <a href="uselocale.3.html">uselocale(3)</a> call
          may return the value <b>LC_GLOBAL_LOCALE</b>, which results in undefined
          behavior if passed to functions such as <a href="toupper_l.3.html">toupper_l(3)</a>.  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.

       Each locale object created by <b>duplocale</b>() should be deallocated using
       <a href="freelocale.3.html">freelocale(3)</a>.
</pre>
<h2><a id="EXAMPLE" href="duplocale.3.html#EXAMPLE"></a>EXAMPLE  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       The program below uses <a href="uselocale.3.html">uselocale(3)</a> and <b>duplocale</b>() to obtain a
       handle for the current locale which is then passed to <a href="toupper_l.3.html">toupper_l(3)</a>.
       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:

           $ <b>./a.out abc</b>
           ABC

   <b>Program source</b>

       #define _XOPEN_SOURCE 700
       #include &lt;ctype.h&gt;
       #include &lt;stdio.h&gt;
       #include &lt;stdlib.h&gt;
       #include &lt;locale.h&gt;

       #define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \
                               } while (0)

       int
       main(int argc, char *argv[])
       {
           locale_t loc, nloc;
           char *p;

           if (argc != 2) {
               fprintf(stderr, "Usage: %s string\n", argv[0]);
               exit(EXIT_FAILURE);
           }

           /* This sequence is necessary, because uselocale() might return
              the value LC_GLOBAL_LOCALE, which can't be passed as an
              argument to toupper_l() */

           loc = uselocale((locale_t) 0);
           if (loc == (locale_t) 0)
               errExit("uselocale");

           nloc = duplocale(loc);
           if (nloc == (locale_t) 0)
               errExit("duplocale");

           for (p = argv[1]; *p; p++)
               putchar(toupper_l(*p, nloc));

           printf("\n");

           freelocale(nloc);

           exit(EXIT_SUCCESS);
       }
</pre>
<h2><a id="SEE_ALSO" href="duplocale.3.html#SEE_ALSO"></a>SEE ALSO  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       <a href="freelocale.3.html">freelocale(3)</a>, <a href="newlocale.3.html">newlocale(3)</a>, <a href="setlocale.3.html">setlocale(3)</a>, <a href="uselocale.3.html">uselocale(3)</a>, <a href="../man5/locale.5.html">locale(5)</a>,
       <a href="../man7/locale.7.html">locale(7)</a>
</pre>
<h2><a id="COLOPHON" href="duplocale.3.html#COLOPHON"></a>COLOPHON  &nbsp; &nbsp; &nbsp; &nbsp; <a href="duplocale.3.html#top_of_page"><span class="top-link">top</span></a></h2><pre>
       This page is part of release 4.15 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>.

<span class="footline">Linux                            2017-09-15                     DUPLOCALE(3)</span>
</pre>

<hr class="end-man-text" />
<p>Pages that refer to this page: 
    <a href="isalpha.3.html">isalpha(3)</a>,&nbsp; 
    <a href="newlocale.3.html">newlocale(3)</a>,&nbsp; 
    <a href="strfmon.3.html">strfmon(3)</a>,&nbsp; 
    <a href="toupper.3.html">toupper(3)</a>,&nbsp; 
    <a href="towlower.3.html">towlower(3)</a>,&nbsp; 
    <a href="towupper.3.html">towupper(3)</a>,&nbsp; 
    <a href="uselocale.3.html">uselocale(3)</a>,&nbsp; 
    <a href="../man7/locale.7.html">locale(7)</a>
</p>
<hr/>

<p class="page-copyright"><a href="duplocale.3.license.html">Copyright and license for this manual page</a></p> 
<hr class="start-footer" />

<div class="footer"> 

<table class="colophon-table">
    <tr>
    <td class="pub-info">
        <p>
            HTML rendering created 2018-02-02
            by <a href="http://man7.org/mtk/index.html">Michael Kerrisk</a>, 
            author of 
            <a href="http://man7.org/tlpi/"><em>The Linux Programming Interface</em></a>, 
            maintainer of the 
            <a href="https://www.kernel.org/doc/man-pages/">Linux <em>man-pages</em> project</a>.
        </p>
        <p>
            For details of in-depth
            <strong>Linux/UNIX system programming training courses</strong>
            that I teach, look <a href="http://man7.org/training/">here</a>.
        </p>
        <p>
            Hosting by <a href="http://www.jambit.com/index_en.html">jambit GmbH</a>.
        </p>
        <p>
            <a href="http://validator.w3.org/check?uri=referer">
            <img src="http://www.w3.org/Icons/valid-xhtml11"
                alt="Valid XHTML 1.1" height="31" width="88" />
            </a>
        </p>
    </td>
    <td class="colophon-divider">
    </td>
    <td class="tlpi-cover">
        <a href="http://man7.org/tlpi/"><img src="../../../tlpi/cover/TLPI-front-cover-vsmall.png" alt="Cover of TLPI" /></a>
    </td>
    </tr>
</table>

</div>

<hr class="end-footer" />



<!--BEGIN-SITETRACKING-->
<!-- SITETRACKING.man7.org_linux_man-pages -->

<!-- Start of StatCounter Code (xhtml) -->

<script type="text/javascript">
//<![CDATA[
var sc_project=7422636; 
var sc_invisible=1; 
var sc_security="9b6714ff"; 
//]]>
</script>
<script type="text/javascript"
src="http://www.statcounter.com/counter/counter_xhtml.js"></script>
<noscript><div class="statcounter"><a title="website
statistics" href="http://statcounter.com/"
class="statcounter"><img class="statcounter"
src="http://c.statcounter.com/7422636/0/9b6714ff/1/"
alt="website statistics" /></a></div></noscript>

<!-- End of StatCounter Code -->


<!-- Start of Google Analytics Code -->

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-9830363-8']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

<!-- End of Google Analytics Code -->

<!--END-SITETRACKING-->

</body>
</html>
