1 /* Fake setlocale - platform independent, for testing purposes.
2 Copyright (C) 2001-2002 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 /* Return string representation of locale CATEGORY. */
27 category_to_name (int category)
35 retval = "LC_COLLATE";
45 retval = "LC_MONETARY";
50 retval = "LC_NUMERIC";
60 retval = "LC_MESSAGES";
65 retval = "LC_RESPONSE";
70 /* This might not make sense but is perhaps better than any other
76 /* If you have a better idea for a default value let me know. */
83 /* An implementation of setlocale that always succeeds, but doesn't
84 actually change the behaviour of locale dependent functions.
85 Assumes setenv()/putenv() is not called. */
87 setlocale (int category, SETLOCALE_CONST char *locale)
89 static char C_string[] = "C";
90 static char *current_locale = C_string;
97 static struct list *facets = NULL;
105 copy = (char *) malloc (strlen (locale) + 1);
106 strcpy (copy, locale);
108 if (category == LC_ALL)
110 while ((facetp = facets) != NULL)
112 facets = facetp->next;
113 free (facetp->current_locale);
116 if (current_locale != C_string)
117 free (current_locale);
118 current_locale = copy;
122 for (facetp = facets; facetp != NULL; facetp = facetp->next)
123 if (category == facetp->category)
125 free (facetp->current_locale);
126 facetp->current_locale = copy;
131 facetp = (struct list *) malloc (sizeof (struct list));
132 facetp->category = category;
133 facetp->current_locale = copy;
134 facetp->next = facets;
140 retval = current_locale;
141 for (facetp = facets; facetp != NULL; facetp = facetp->next)
142 if (category == facetp->category)
144 retval = facetp->current_locale;
148 if (retval[0] == '\0')
150 retval = getenv ("LC_ALL");
151 if (retval == NULL || retval[0] == '\0')
153 retval = getenv (category_to_name (category));
154 if (retval == NULL || retval[0] == '\0')
156 retval = getenv ("LANG");
157 if (retval == NULL || retval[0] == '\0')