This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: missing API for locale_t in <locale.h>


I'm considering putting in the following change, but I'd like some more
opinions on it first.  I haven't tested this, so if I've gone insane it
might not actually work.

I'm not adding any sort of versioning to the interface to distinguish old
ones without this support from new ones with.  It's a difference in what
values you can pass to nl_langinfo{,_l}.  Applications using this need to
check at runtime if it actually works (old ones return an empty string).
Note that an autoconf check is ill-advised, as there is no versioning that
necessarily prevents building against a libc with the new nl_langinfo
semantics and later running against an older one.

Comments?


Thanks,
Roland

2005-03-28  Roland McGrath  <roland@redhat.com>

	* locale/langinfo.h (_NL_LOCALE_NAME): New macro.
	[__USE_GNU] (NL_LOCALE_NAME): New macro.
	* locale/nl_langinfo.c: Grok special item value for _NL_LOCALE_NAME,
	return locale name string for the category.

Index: locale/langinfo.h
===================================================================
RCS file: /cvs/glibc/libc/locale/langinfo.h,v
retrieving revision 1.54
diff -B -p -u -r1.54 langinfo.h
--- locale/langinfo.h	19 Dec 2004 08:57:26 -0000	1.54
+++ locale/langinfo.h	28 Mar 2005 18:43:51 -0000
@@ -1,5 +1,5 @@
 /* Access to locale-dependent parameters.
-   Copyright (C) 1995-2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1995-2002,2003,2004,2005 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -566,6 +565,13 @@ enum
   _NL_NUM
 };
 
+/* This macro produces an item you can pass to `nl_langinfo' or
+   `nl_langinfo_l' to get the name of the locale in use for CATEGORY.  */
+#define _NL_LOCALE_NAME(category)	_NL_ITEM ((category), -1)
+#ifdef __USE_GNU
+# define NL_LOCALE_NAME(category)	_NL_LOCALE_NAME (category)
+#endif
+
 
 /* Return the current locale's value for ITEM.
    If ITEM is invalid, an empty string is returned.
Index: locale/nl_langinfo.c
===================================================================
RCS file: /cvs/glibc/libc/locale/nl_langinfo.c,v
retrieving revision 1.16
diff -B -p -u -r1.16 nl_langinfo.c
--- locale/nl_langinfo.c	29 Aug 2002 02:17:54 -0000	1.16
+++ locale/nl_langinfo.c	28 Mar 2005 18:43:51 -0000
@@ -1,5 +1,6 @@
 /* User interface for extracting locale-dependent parameters.
-   Copyright (C) 1995,96,97,99,2000,01,02 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,97,99,2000,2001,2002,2005
+	Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -45,6 +46,18 @@ nl_langinfo (item)
     /* Bogus category: bogus item.  */
     return (char *) "";
 
+  /* Special case value for NL_LOCALE_NAME (category).
+     This is not a real item index in the string table.  */
+  if (index == _NL_ITEM_INDEX (_NL_LOCALE_NAME (category)))
+    {
+#ifdef USE_IN_EXTENDED_LOCALE_MODEL
+# define THISLOCALE l
+#else
+# define THISLOCALE _NL_CURRENT_LOCALE
+#endif
+      return (char *) THISLOCALE->__names[category];
+    }
+
 #ifdef USE_IN_EXTENDED_LOCALE_MODEL
   data = l->__locales[category];
 #elif defined NL_CURRENT_INDIRECT


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]