From 49e522bfb8642bb31afc2a119b2538a6a6465996 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Tue, 21 Mar 1995 07:58:50 +0000 Subject: Tue Mar 21 00:14:27 1995 Roland McGrath * locale/loadlocale.c (_nl_load_locale): If LOCALE/LC_* is a directory, open LOCALE/LC_*/SYS_LC_* instead. * stdio/fpioconst.c, stdio/fpioconst.h, stdio/gmp-impl.h, stdio/gmp.h, stdio/longlong.h, stdio/mp_clz_tab.c, stdio/gen-mpn-copy: Files moved to stdlib. * stdio/Makefile: All mpn stuff moved to stdlib/Makefile. * stdio/printf_fp.c: Use ../stdlib to find fpioconst.h and gmp headers. * stdlib/strtod.c: Don't use ../stdio to find fpioconst.h and gmp headers. --- locale/loadlocale.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'locale') diff --git a/locale/loadlocale.c b/locale/loadlocale.c index 7ad7a21b53..a8cf7d5448 100644 --- a/locale/loadlocale.c +++ b/locale/loadlocale.c @@ -38,7 +38,6 @@ const size_t _nl_category_num_items[] = struct locale_data * _nl_load_locale (int category, char **name) { - char *file; int fd; struct { @@ -69,18 +68,31 @@ _nl_load_locale (int category, char **name) *name = (char *) "local"; } -/* XXX can't use asprintf here */ - if (asprintf (&file, "%s%s/%s", - strchr (*name, '/') != NULL ? "" : "/share/locale/", /* XXX */ - *name, _nl_category_names[category]) == -1) - return NULL; - - fd = __open (file, O_RDONLY); - free (file); - if (fd < 0) - return NULL; - if (__fstat (fd, &st) < 0) - goto puntfd; + { + const char localedir[] = "/share/locale/"; /* XXX */ + const char *catname = _nl_category_names[category]; + size_t namelen = strlen (*name); + size_t catlen = strlen (catname); + char file[sizeof localedir + namelen + catlen * 2 + 4]; + sprintf (file, "%s%s/%s", + strchr (*name, '/') != NULL ? "" : localedir, *name, catname); + fd = __open (file, O_RDONLY); + if (fd < 0) + return NULL; + if (__fstat (fd, &st) < 0) + goto puntfd; + if (S_ISDIR (st.st_mode)) + { + /* LOCALE/LC_* is a directory; open LOCALE/LC_*/SYS_LC_* instead. */ + __close (fd); + memcpy (stpcpy (strchr (file, '\0'), "SYS_"), catname, catlen); + fd = __open (file, O_RDONLY); + if (fd < 0) + return NULL; + if (__fstat (fd, &st) < 0) + goto puntfd; + } + } { /* Map in the file's data. */ -- cgit v1.2.1