This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
On Tue, Jan 02, 2001 at 09:54:08AM -0800, Ulrich Drepper wrote: > Jakub Jelinek <jakub@redhat.com> writes: > > > IBM JDK does basically: > > > > char *p = setlocale(LC_CTYPE, ""); > > setlocale(LC_ALL, p); > > This is wrong. The specification explicitly talks about restoring. > This is not restoring. The value for LC_CTYPE is used for LC_ALL. > > > /* use p - as use p you could consider e.g. setlocale(LC_CTYPE, p); */ > > setlocale(LC_CTYPE, p); > > This should work. Some platforms return strings like I'm not entirely sure I understand. Do you say that char *p = setlocale(LC_CTYPE, ""); setlocale(LC_ALL, ""); setlocale(LC_CTYPE, p); should work or did you just mean if the middle setlocale is not present? Those 3 lines don't work in current glibc, but could be made to work much more easily (it is wasteful to allocate the same string again and free the other one soon afterwards): 2001-01-02 Jakub Jelinek <jakub@redhat.com> * locale/setlocale.c (setlocale): Don't allocate/free category name unnecessarily. --- libc/locale/setlocale.c.jj Mon Dec 4 15:07:35 2000 +++ libc/locale/setlocale.c Tue Jan 2 23:19:43 2001 @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 92, 95-99, 2000 Free Software Foundation, Inc. +/* Copyright (C) 1991, 92, 95-99, 2000, 2001 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 @@ -326,9 +326,15 @@ setlocale (int category, const char *loc /* Make a copy of locale name. */ if (newnames[category] != _nl_C_name) { - newnames[category] = strdup (newnames[category]); - if (newnames[category] == NULL) - break; + if (! strcmp (newnames[category], + _nl_current_names[category])) + newnames[category] = _nl_current_names[category]; + else + { + newnames[category] = strdup (newnames[category]); + if (newnames[category] == NULL) + break; + } } } @@ -352,7 +358,8 @@ setlocale (int category, const char *loc } else for (++category; category < __LC_LAST; ++category) - if (category != LC_ALL && newnames[category] != _nl_C_name) + if (category != LC_ALL && newnames[category] != _nl_C_name + && newnames[category] != _nl_current_names[category]) free ((char *) newnames[category]); /* Critical section left. */ Jakub
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |