duplocale - Online Linux Manual PageSection : 3
Updated : 2023-02-05
Source : Linux man-pages 6.03

NAMEduplocale − duplicate a locale object

LIBRARYStandard C library (libc, −lc)

SYNOPSIS#include <locale.h>locale_t duplocale(locale_t locobj);Feature Test Macro Requirements for glibc (see feature_test_macros(7)): duplocale(): Since glibc 2.10: _XOPEN_SOURCE >= 700 Before glibc 2.10: _GNU_SOURCE

DESCRIPTIONThe duplocale() function creates a duplicate of the locale object referred to by locobj. If locobj is LC_GLOBAL_LOCALE, duplocale() creates a locale object containing a copy of the global locale determined by setlocale(3).

RETURN VALUEOn success, duplocale() returns a handle for the new locale object. On error, it returns (locale_t) 0, and sets errno to indicate the error.

ERRORSENOMEM  Insufficient memory to create the duplicate locale object.

VERSIONSThe duplocale() function were added in glibc 2.3.

STANDARDSPOSIX.1-2008.

NOTESDuplicating 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 newlocale(3)). • To obtain a handle for the current locale which can used in other functions that employ a locale handle, such as toupper_l(3). This is done by applying duplocale() to the value returned by the following call: loc = uselocale((locale_t) 0);This technique is necessary, because the above uselocale(3) call may return the value LC_GLOBAL_LOCALE, which results in undefined behavior if passed to functions such as toupper_l(3). Calling duplocale() can be used to ensure that the LC_GLOBAL_LOCALE value is converted into a usable locale object. See EXAMPLES, below. Each locale object created by duplocale() should be deallocated using freelocale(3).

EXAMPLESThe program below uses uselocale(3) and duplocale() to obtain a handle for the current locale which is then passed to toupper_l(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: $ ./a.out abc ABC

Program source#define _XOPEN_SOURCE 700 #include <ctype.h> #include <locale.h> #include <stdio.h> #include <stdlib.h> #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \ } while (0) int main(int argc, char *argv[]) { locale_t loc, nloc; 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 (char *p = argv[1]; *p; p++) putchar(toupper_l(*p, nloc)); printf("\n"); freelocale(nloc); exit(EXIT_SUCCESS); }

SEE ALSOfreelocale(3), newlocale(3), setlocale(3), uselocale(3), locale(5), locale(7)
0
Johanes Gumabo
Data Size   :   14,661 byte
man-duplocale.3Build   :   2024-12-29, 07:25   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   3 / 259,891
Visitor ID   :     :  
Visitor IP   :   3.145.166.178   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.29
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.