[tz] [PROPOSED PATCH 6/9] strftime: remove support for long-obsolete SunOS locale files
Paul Eggert
eggert at cs.ucla.edu
Mon Aug 25 06:59:50 UTC 2014
These files were removed from Solaris long ago,
and are not present on any current platforms.
* Makefile, NEWS: Document this.
* private.h (LOCALE_HOME): Remove.
* strftime.c: Assume LOCALE_HOME is not defined.
Do not include sys/stat.h.
(localebuf, _loc) [LOCALE_HOME]: Remove. All uses removed.
---
Makefile | 1 -
NEWS | 2 +
private.h | 4 --
strftime.c | 132 -------------------------------------------------------------
4 files changed, 2 insertions(+), 137 deletions(-)
diff --git a/Makefile b/Makefile
index 0a8696c..3a52875 100644
--- a/Makefile
+++ b/Makefile
@@ -121,7 +121,6 @@ LDLIBS=
# -DHAVE_TZSET=0 if your system lacks a tzset function
# -DHAVE_UNISTD_H=0 if your compiler lacks a "unistd.h" (Microsoft C++ 7?)
# -DHAVE_UTMPX_H=1 if your compiler has a "utmpx.h"
-# -DLOCALE_HOME=\"path\" if locales are in "path", not "/usr/lib/locale"
# -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU=1
# if you do not want run time warnings about formats that may cause
# year 2000 grief
diff --git a/NEWS b/NEWS
index 9cf4b04..9432dd4 100644
--- a/NEWS
+++ b/NEWS
@@ -86,6 +86,8 @@ Unreleased, experimental changes
For easier maintenance later, some C code has been simplified
and some lint has been removed.
+ The long-obsolete LOCALE_HOME code has been removed.
+
The long-obsolete 'gtime' function has been removed.
Changes affecting build procedure
diff --git a/private.h b/private.h
index 31239e1..5d44919 100644
--- a/private.h
+++ b/private.h
@@ -62,10 +62,6 @@
#define HAVE_UTMPX_H 0
#endif /* !defined HAVE_UTMPX_H */
-#ifndef LOCALE_HOME
-#define LOCALE_HOME "/usr/lib/locale"
-#endif /* !defined LOCALE_HOME */
-
#if HAVE_INCOMPATIBLE_CTIME_R
#define asctime_r _incompatible_asctime_r
#define ctime_r _incompatible_ctime_r
diff --git a/strftime.c b/strftime.c
index 8f75499..ef2471b 100644
--- a/strftime.c
+++ b/strftime.c
@@ -41,15 +41,7 @@ struct lc_time_T {
const char * date_fmt;
};
-#ifdef LOCALE_HOME
-#include "sys/stat.h"
-static struct lc_time_T localebuf;
-static struct lc_time_T * _loc(void);
-#define Locale _loc()
-#endif /* defined LOCALE_HOME */
-#ifndef LOCALE_HOME
#define Locale (&C_time_locale)
-#endif /* !defined LOCALE_HOME */
static const struct lc_time_T C_time_locale = {
{
@@ -122,9 +114,6 @@ strftime(char * const s, const size_t maxsize, const char *const format,
int warn;
tzset();
-#ifdef LOCALE_HOME
- localebuf.mon[0] = 0;
-#endif /* defined LOCALE_HOME */
warn = IN_NONE;
p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
@@ -615,124 +604,3 @@ _yconv(int a, int b, bool convert_top, bool convert_yy,
pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim);
return pt;
}
-
-#ifdef LOCALE_HOME
-static struct lc_time_T *
-_loc(void)
-{
- static const char locale_home[] = LOCALE_HOME;
- static const char lc_time[] = "LC_TIME";
- static char * locale_buf;
-
- int fd;
- bool oldsun; /* "...ain't got nothin' to do..." */
- char * lbuf;
- char * name;
- char * p;
- const char ** ap;
- const char * plim;
- char filename[FILENAME_MAX];
- struct stat st;
- size_t namesize;
- size_t bufsize;
-
- /*
- ** Use localebuf.mon[0] to signal whether locale is already set up.
- */
- if (localebuf.mon[0])
- return &localebuf;
- name = setlocale(LC_TIME, NULL);
- if (name == NULL || *name == '\0')
- goto no_locale;
- /*
- ** If the locale name is the same as our cache, use the cache.
- */
- lbuf = locale_buf;
- if (lbuf != NULL && strcmp(name, lbuf) == 0) {
- p = lbuf;
- for (ap = (const char **) &localebuf;
- ap < (const char **) (&localebuf + 1);
- ++ap)
- *ap = p += strlen(p) + 1;
- return &localebuf;
- }
- /*
- ** Slurp the locale file into the cache.
- */
- namesize = strlen(name) + 1;
- if (sizeof filename <
- ((sizeof locale_home) + namesize + (sizeof lc_time)))
- goto no_locale;
- oldsun = false;
- sprintf(filename, "%s/%s/%s", locale_home, name, lc_time);
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
- /*
- ** Old Sun systems have a different naming and data convention.
- */
- oldsun = true;
- sprintf(filename, "%s/%s/%s", locale_home,
- lc_time, name);
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- goto no_locale;
- }
- if (fstat(fd, &st) != 0)
- goto bad_locale;
- if (st.st_size <= 0)
- goto bad_locale;
- bufsize = namesize + st.st_size;
- locale_buf = NULL;
- lbuf = (lbuf == NULL) ? malloc(bufsize) : realloc(lbuf, bufsize);
- if (lbuf == NULL)
- goto bad_locale;
- strcpy(lbuf, name);
- p = lbuf + namesize;
- plim = p + st.st_size;
- if (read(fd, p, st.st_size) != st.st_size)
- goto bad_lbuf;
- if (close(fd) != 0)
- goto bad_lbuf;
- /*
- ** Parse the locale file into localebuf.
- */
- if (plim[-1] != '\n')
- goto bad_lbuf;
- for (ap = (const char **) &localebuf;
- ap < (const char **) (&localebuf + 1);
- ++ap) {
- if (p == plim)
- goto bad_lbuf;
- *ap = p;
- while (*p != '\n')
- ++p;
- *p++ = '\0';
- }
- if (oldsun) {
- /*
- ** SunOS 4 used an obsolescent format; see localdtconv(3).
- ** c_fmt had the "short format for dates and times together"
- ** (SunOS 4 date, "%a %b %e %T %Z %Y" in the C locale);
- ** date_fmt had the "long format for dates"
- ** (SunOS 4 strftime %C, "%A, %B %e, %Y" in the C locale).
- ** Discard the latter in favor of the former.
- */
- localebuf.date_fmt = localebuf.c_fmt;
- }
- /*
- ** Record the successful parse in the cache.
- */
- locale_buf = lbuf;
-
- return &localebuf;
-
-bad_lbuf:
- free(lbuf);
-bad_locale:
- close(fd);
-no_locale:
- localebuf = C_time_locale;
- locale_buf = NULL;
- return &localebuf;
-}
-#endif /* defined LOCALE_HOME */
--
1.9.1
More information about the tz
mailing list