Home Man
Today's Posts

Linux & Unix Commands - Search Man Pages
Man Page or Keyword Search:
Select Section of Man Page:
Select Man Page Repository:

Linux 2.6 - man page for setlocale (linux section 3posix)

SETLOCALE(P)			    POSIX Programmer's Manual			     SETLOCALE(P)

       setlocale - set program locale

       #include <locale.h>

       char *setlocale(int category, const char *locale);

       The  setlocale() function selects the appropriate piece of the program's locale, as speci-
       fied by the category and locale arguments, and may be used to change  or  query	the  pro-
       gram's  entire  locale  or  portions thereof. The value LC_ALL for category names the pro-
       gram's entire locale; other values for category name only a part of the program's locale:

	      Affects the behavior of regular expressions and the collation functions.

	      Affects the behavior of regular expressions,  character  classification,	character
	      conversion functions, and wide-character functions.

	      Affects what strings are expected by commands and utilities as affirmative or nega-
	      tive responses.

       It also affects what strings are given by commands and utilities as affirmative	or  nega-
       tive responses, and the content of messages.

	      Affects the behavior of functions that handle monetary values.

	      Affects the behavior of functions that handle numeric values.

	      Affects the behavior of the time conversion functions.

       The  locale argument is a pointer to a character string containing the required setting of
       category. The contents of this string are implementation-defined. In addition, the follow-
       ing preset values of locale are defined for all settings of category:

	      Specifies  the  minimal  environment  for  C-language  translation called the POSIX
	      locale. If setlocale() is not invoked, the POSIX locale is the default at entry  to

       "C"    Equivalent to "POSIX" .

       ""     Specifies  an implementation-defined native environment.	  This corresponds to the
	      value of the associated environment variables, LC_* and LANG ; see the Base Defini-
	      tions  volume  of  IEEE Std 1003.1-2001, Chapter 7, Locale and the Base Definitions
	      volume of IEEE Std 1003.1-2001, Chapter 8, Environment Variables.

       A null pointer
	      Used to direct setlocale() to query the current internationalized  environment  and
	      return the name of the locale.

       The locale state is common to all threads within a process.

       Upon successful completion, setlocale() shall return the string associated with the speci-
       fied category for the new locale. Otherwise, setlocale() shall return a null  pointer  and
       the program's locale is not changed.

       A  null pointer for locale causes setlocale() to return a pointer to the string associated
       with the category for the program's current locale. The	program's  locale  shall  not  be

       The string returned by setlocale() is such that a subsequent call with that string and its
       associated category shall restore that part of the program's locale. The application shall
       not  modify  the  string  returned which may be overwritten by a subsequent call to setlo-

       No errors are defined.

       The following sections are informative.


       The following code illustrates how a program can initialize the international  environment
       for  one  language,  while  selectively	modifying  the program's locale such that regular
       expressions and string operations can be applied to text recorded in a different language:

	      setlocale(LC_ALL, "De");
	      setlocale(LC_COLLATE, "Fr@dict");

       Internationalized programs must call setlocale() to initiate a  specific  language  opera-
       tion. This can be done by calling setlocale() as follows:

	      setlocale(LC_ALL, "");

       Changing  the  setting  of  LC_MESSAGES	has  no effect on catalogs that have already been
       opened by calls to catopen().

       The ISO C standard defines a collection of functions to support internationalization.  One
       of  the	most  significant  aspects  of these functions is a facility to set and query the
       international environment. The international environment is a  repository  of  information
       that affects the behavior of certain functionality, namely:

	1. Character handling

	2. Collating

	3. Date/time formatting

	4. Numeric editing

	5. Monetary formatting

	6. Messaging

       The setlocale() function provides the application developer with the ability to set all or
       portions, called categories, of the international environment. These categories correspond
       to the areas of functionality mentioned above. The syntax for setlocale() is as follows:

	      char *setlocale(int category, const char *locale);

       where category is the name of one of following categories, namely:







       In addition, a special value called LC_ALL directs setlocale() to set all categories.

       There are two primary uses of setlocale():

	1. Querying the international environment to find out what it is set to

	2. Setting the international environment, or locale, to a specific value

       The  behavior  of setlocale() in these two areas is described below. Since it is difficult
       to describe the behavior in words, examples are used to illustrate the  behavior  of  spe-
       cific uses.

       To  query  the  international environment, setlocale() is invoked with a specific category
       and the NULL pointer as the locale. The NULL pointer is a special directive to setlocale()
       that tells it to query rather than set the international environment. The following syntax
       is used to query the name of the international environment:

		  LC_NUMERIC, LC_TIME},(char *) NULL);

       The setlocale() function shall return the string corresponding  to  the	current  interna-
       tional  environment.  This  value may be used by a subsequent call to setlocale() to reset
       the international environment to this value. However, it should be noted that  the  return
       value  from  setlocale()  may be a pointer to a static area within the function and is not
       guaranteed to remain unchanged (that is, it may be modified by a subsequent call to setlo-
       cale()). Therefore, if the purpose of calling setlocale() is to save the value of the cur-
       rent international environment so it can be changed and	reset  later,  the  return  value
       should be copied to an array of char in the calling program.

       There are three ways to set the international environment with setlocale():

       setlocale(category, string)

	      This  usage sets a specific category in the international environment to a specific
	      value corresponding to the value of the string.  A  specific  example  is  provided

	      setlocale(LC_ALL, "fr_FR.ISO-8859-1");

       In  this  example,  all	categories of the international environment are set to the locale
       corresponding to the string "fr_FR.ISO-8859-1" , or to the French language  as  spoken  in
       France using the ISO/IEC 8859-1:1998 standard codeset.

       If  the	string	does  not  correspond  to a valid locale, setlocale() shall return a NULL
       pointer and the international environment is not  changed.  Otherwise,  setlocale()  shall
       return the name of the locale just set.

       setlocale(category, "C")

	      The  ISO C standard states that one locale must exist on all conforming implementa-
	      tions. The name of the locale is C and corresponds to a minimal international envi-
	      ronment needed to support the C programming language.

       setlocale(category, "")

	      This  sets  a  specific category to an implementation-defined default.  This corre-
	      sponds to the value of the environment variables.


       exec() , isalnum() , isalpha() , isblank() , iscntrl() , isdigit() , isgraph() , islower()
       ,  isprint()  , ispunct() , isspace() , isupper() , iswalnum() , iswalpha() , iswblank() ,
       iswcntrl() , iswctype() , iswdigit() , iswgraph() , iswlower() , iswprint() , iswpunct() ,
       iswspace() , iswupper() , iswxdigit() , isxdigit() , localeconv() , mblen() , mbstowcs() ,
       mbtowc() , nl_langinfo() , printf() , scanf() , setlocale , strcoll() , strerror() , strf-
       mon() , strtod() , strxfrm() , tolower() , toupper() , towlower() , towupper() , wcscoll()
       , wcstod() ,  wcstombs()  ,  wcsxfrm()  ,  wctomb()  ,  the  Base  Definitions  volume  of
       IEEE Std 1003.1-2001, <langinfo.h>, <locale.h>

       Portions  of  this  text  are  reprinted  and  reproduced in electronic form from IEEE Std
       1003.1, 2003 Edition, Standard for Information Technology  --  Portable	Operating  System
       Interface  (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by
       the Institute of Electrical and Electronics Engineers, Inc and  The  Open  Group.  In  the
       event  of  any  discrepancy  between this version and the original IEEE and The Open Group
       Standard, the original IEEE and The Open Group Standard is the referee document. The orig-
       inal Standard can be obtained online at http://www.opengroup.org/unix/online.html .

IEEE/The Open Group			       2003				     SETLOCALE(P)

All times are GMT -4. The time now is 12:34 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
Show Password