aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/locale/setlocale.c
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>1995-10-23 01:34:17 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>1995-10-23 01:34:17 +0000
commit350a3d3e48232a1040bc3ae87865be85fb5e39de (patch)
treedf3d9138c260a0dd995cf571fe1f86075fc381a2 /lib/libc/locale/setlocale.c
parentb596ee8d4e9cc44a17cb7e7ea7bbb389bcdd1a6d (diff)
downloadsrc-350a3d3e48232a1040bc3ae87865be85fb5e39de.tar.gz
src-350a3d3e48232a1040bc3ae87865be85fb5e39de.zip
Migrate from XPG4 to XPG3 (libxpg4 will be added soon)
Remove big part of my startup_setlocale hack. Add missing manpage links.
Notes
Notes: svn path=/head/; revision=11695
Diffstat (limited to 'lib/libc/locale/setlocale.c')
-rw-r--r--lib/libc/locale/setlocale.c91
1 files changed, 86 insertions, 5 deletions
diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c
index c2efd5b5610c..cb5da653e4e5 100644
--- a/lib/libc/locale/setlocale.c
+++ b/lib/libc/locale/setlocale.c
@@ -43,13 +43,49 @@ static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93";
#include <rune.h>
#include <stdlib.h>
#include <string.h>
-#include "common_setlocale.h"
-#include "common_rune.h"
+#include "collate.h"
+/*
+ * Category names for getenv()
+ */
+static char *categories[_LC_LAST] = {
+ "LC_ALL",
+ "LC_COLLATE",
+ "LC_CTYPE",
+ "LC_MONETARY",
+ "LC_NUMERIC",
+ "LC_TIME",
+};
+
+/*
+ * Current locales for each category
+ */
+static char current_categories[_LC_LAST][32] = {
+ "C",
+ "C",
+ "C",
+ "C",
+ "C",
+ "C",
+};
+
+/*
+ * The locales we are going to try and load
+ */
+static char new_categories[_LC_LAST][32];
+
+static char current_locale_string[_LC_LAST * 33];
char *_PathLocale;
+static char *currentlocale __P((void));
static char *loadlocale __P((int));
+extern int __time_load_locale __P((const char *)); /* strftime.c */
+
+#ifdef XPG4
+extern int _xpg4_setrunelocale __P((char *));
+#endif
+
char *
setlocale(category, locale)
int category;
@@ -58,8 +94,8 @@ setlocale(category, locale)
int found, i, len;
char *env, *r;
- if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE")))
- PathLocale = _PATH_LOCALE;
+ if (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE")))
+ _PathLocale = _PATH_LOCALE;
if (category < 0 || category >= _LC_LAST)
return (NULL);
@@ -139,6 +175,47 @@ setlocale(category, locale)
return (NULL);
}
+#ifndef XPG4
+/* To be compatible with old binaries */
+void
+_startup_setlocale(category, locale)
+ int category;
+ const char *locale;
+{
+ (void) setlocale(category, locale);
+}
+#endif
+
+static char *
+currentlocale()
+{
+ int i, len;
+
+ (void)strcpy(current_locale_string, current_categories[1]);
+
+ for (i = 2; i < _LC_LAST; ++i)
+ if (strcmp(current_categories[1], current_categories[i])) {
+ len = strlen(current_categories[1]) + 1 +
+ strlen(current_categories[2]) + 1 +
+ strlen(current_categories[3]) + 1 +
+ strlen(current_categories[4]) + 1 +
+ strlen(current_categories[5]) + 1;
+ if (len > sizeof(current_locale_string))
+ return NULL;
+ (void) strcpy(current_locale_string, current_categories[1]);
+ (void) strcat(current_locale_string, "/");
+ (void) strcat(current_locale_string, current_categories[2]);
+ (void) strcat(current_locale_string, "/");
+ (void) strcat(current_locale_string, current_categories[3]);
+ (void) strcat(current_locale_string, "/");
+ (void) strcat(current_locale_string, current_categories[4]);
+ (void) strcat(current_locale_string, "/");
+ (void) strcat(current_locale_string, current_categories[5]);
+ break;
+ }
+ return (current_locale_string);
+}
+
static char *
loadlocale(category)
int category;
@@ -151,7 +228,11 @@ loadlocale(category)
return (current_categories[category]);
if (category == LC_CTYPE) {
+#ifdef XPG4
+ if (_xpg4_setrunelocale(new_categories[LC_CTYPE]))
+#else
if (setrunelocale(new_categories[LC_CTYPE]))
+#endif
return (NULL);
(void)strcpy(current_categories[LC_CTYPE],
new_categories[LC_CTYPE]);
@@ -191,7 +272,7 @@ loadlocale(category)
* Some day we will actually look at this file.
*/
(void)snprintf(name, sizeof(name), "%s/%s/%s",
- PathLocale, new_categories[category], categories[category]);
+ _PathLocale, new_categories[category], categories[category]);
#endif
switch (category) {
case LC_MONETARY: