Michael Kerrisk wrote:
> > In order to have nl_langinfo(3) return the proper information
> > it is required to call setlocale (TYPE, "") first, which isn't
> > mentioned in the manpage of nl_langinfo(3).  Please add.
> 
> Joey,
> 
> is nl_langinfo(3) somehow different here from a host of
> other functions whose behaviour depends on setlocale().
> E.g., strptime(3), printf(3), etc, most of which do not
> explicitly mention the need to call setlocale()?

Not sure about the other functions you mentioned but for nl_langinfo
you'll have to execute setlocale first.  Please see the attached
test program as an example:

finlandia!joey(tty6):/tmp/work> LC_CTYPE=en_US.ISO-8859-1 ./test_nl_langinfo
LC_CTYPE=ANSI_X3.4-1968
LC_CTYPE=ISO-8859-1
finlandia!joey(tty6):/tmp/work>

Here's a simple patch to the manpage:

Index: nl_langinfo.3
===================================================================
RCS file: /var/cvs/debian/manpages/man3/nl_langinfo.3,v
retrieving revision 1.1.1.4
diff -u -p -r1.1.1.4 nl_langinfo.3
--- nl_langinfo.3       23 Nov 2005 06:32:33 -0000      1.1.1.4
+++ nl_langinfo.3       30 Apr 2006 08:06:47 -0000
@@ -26,6 +26,8 @@ in a more flexible way than
 .BR localeconv (3)
 does. Individual and additional elements of the locale categories can
 be queried.
+.BR setlocale (3)
+needs to be executed with proper arguments before.
 .PP
 Examples for the locale elements that can be specified in \fIitem\fP
 using the constants defined in <langinfo.h> are:


Regards,

        Joey

-- 
Every use of Linux is a proper use of Linux.  -- Jon 'maddog' Hall

Please always Cc to me when replying to me on the lists.
/*
    Copyright (c) 2006  Joey Schulze <[EMAIL PROTECTED]>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <langinfo.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>


/*
 * Determine the output character set
 */
int main()
{
  char *charset = NULL;

  charset = strdup (nl_langinfo(CODESET));

  printf ("LC_CTYPE=%s\n", charset);

  setlocale (LC_CTYPE, "");

  charset = strdup (nl_langinfo(CODESET));

  printf ("LC_CTYPE=%s\n", charset);
  
  return 0;
}

Reply via email to