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]

[PATCH] Fix nl_langinfo(ERA) returns NULL under C locale


This patch fixes nl_langinfo(ERA) returns NULL, not empty strings
under C locale.  As you know, ERA is defined in SUSv3, and
nl_langinfo() should return empty strings, not NULL, when you pass
invalid (or undefined) variables for this function.  For example, the
following test program warns it's NULL under C locale.

	#include <locale.h>
	#include <stdio.h>
	#include <langinfo.h>
	#include <string.h>
	
	int main(void)
	{
	  char *s;
	  setlocale(LC_ALL, "");
	
	  s = nl_langinfo(ERA);
	  if (s == NULL)
	    printf("NULL strings, error.\n");
	  else
	    printf("%s, len=%d\n", s, strlen(s));
	
	  return 0;
	}

Regards,
-- gotom

2004-08-10  GOTO Masanori  <gotom@debian.or.jp>

	* locale/C-time.c: Change default ERA value from NULL to "".
	* locale/tst-C-locale.c: Add test case for ERA keywords.


Index: locale/C-time.c
===================================================================
RCS file: /cvs/glibc/libc/locale/C-time.c,v
retrieving revision 1.26
diff -u -r1.26 C-time.c
--- locale/C-time.c	16 Dec 2002 02:05:07 -0000	1.26
+++ locale/C-time.c	10 Aug 2004 04:18:53 -0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995-2000, 2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2000, 2001, 2002, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@gnu.org>, 1995.
 
@@ -76,7 +76,7 @@
     { .string = "%m/%d/%y" },
     { .string = "%H:%M:%S" },
     { .string = "%I:%M:%S %p" },
-    { .string = NULL },
+    { .string = "" },
     { .string = "" },
     { .string = "" },
     { .string = "" },
Index: locale/tst-C-locale.c
===================================================================
RCS file: /cvs/glibc/libc/locale/tst-C-locale.c,v
retrieving revision 1.12
diff -u -r1.12 tst-C-locale.c
--- locale/tst-C-locale.c	17 Mar 2003 19:11:36 -0000	1.12
+++ locale/tst-C-locale.c	10 Aug 2004 04:18:53 -0000
@@ -1,5 +1,5 @@
 /* Tests of C and POSIX locale contents.
-   Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -154,6 +154,11 @@
   STRTEST (D_FMT, "%m/%d/%y");
   STRTEST (T_FMT, "%H:%M:%S");
   STRTEST (T_FMT_AMPM, "%I:%M:%S %p");
+  STRTEST (ERA, "");
+  STRTEST (ERA_D_FMT, "");
+  STRTEST (ERA_T_FMT, "");
+  STRTEST (ERA_D_T_FMT, "");
+  STRTEST (ALT_DIGITS, "");
 
   STRTEST (RADIXCHAR, ".");
   STRTEST (THOUSEP, "");
@@ -206,6 +211,10 @@
   WSTRTEST (_NL_WD_FMT, L"%m/%d/%y");
   WSTRTEST (_NL_WT_FMT, L"%H:%M:%S");
   WSTRTEST (_NL_WT_FMT_AMPM, L"%I:%M:%S %p");
+  WSTRTEST (_NL_WERA_D_FMT, L"");
+  WSTRTEST (_NL_WERA_T_FMT, L"");
+  WSTRTEST (_NL_WERA_D_T_FMT, L"");
+  WSTRTEST (_NL_WALT_DIGITS, L"");
 
   STRTEST (_DATE_FMT, "%a %b %e %H:%M:%S %Z %Y");
   WSTRTEST (_NL_W_DATE_FMT, L"%a %b %e %H:%M:%S %Z %Y");
@@ -297,6 +306,11 @@
       STRTEST (D_FMT, "%m/%d/%y");
       STRTEST (T_FMT, "%H:%M:%S");
       STRTEST (T_FMT_AMPM, "%I:%M:%S %p");
+      STRTEST (ERA, "");
+      STRTEST (ERA_D_FMT, "");
+      STRTEST (ERA_T_FMT, "");
+      STRTEST (ERA_D_T_FMT, "");
+      STRTEST (ALT_DIGITS, "");
 
       STRTEST (RADIXCHAR, ".");
       STRTEST (THOUSEP, "");
@@ -349,6 +363,10 @@
       WSTRTEST (_NL_WD_FMT, L"%m/%d/%y");
       WSTRTEST (_NL_WT_FMT, L"%H:%M:%S");
       WSTRTEST (_NL_WT_FMT_AMPM, L"%I:%M:%S %p");
+      WSTRTEST (_NL_WERA_D_FMT, L"");
+      WSTRTEST (_NL_WERA_T_FMT, L"");
+      WSTRTEST (_NL_WERA_D_T_FMT, L"");
+      WSTRTEST (_NL_WALT_DIGITS, L"");
 
       STRTEST (_DATE_FMT, "%a %b %e %H:%M:%S %Z %Y");
       WSTRTEST (_NL_W_DATE_FMT, L"%a %b %e %H:%M:%S %Z %Y");


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