* localtime.cc (is_upper): Rename to isupper and include ctype.h to pull in

standard macro.
(lcl_is_set): Define as an enum.
(tzsetwall): Assign lcl_is_set to correct enum values.
(tzset): Ditto.  Copy as much of TZ as will fit to TZ buffer.
This commit is contained in:
Christopher Faylor 2010-10-30 19:22:42 +00:00
parent 304bf11a2b
commit 49808040c5
2 changed files with 27 additions and 13 deletions

View File

@ -1,3 +1,11 @@
2010-10-30 Christopher Faylor <me+cygwin@cgf.cx>
* localtime.cc (is_upper): Rename to isupper and include ctype.h to
pull in standard macro.
(lcl_is_set): Define as an enum.
(tzsetwall): Assign lcl_is_set to correct enum values.
(tzset): Ditto. Copy as much of TZ as will fit to TZ buffer.
2010-10-27 Christopher Faylor <me+cygwin@cgf.cx> 2010-10-27 Christopher Faylor <me+cygwin@cgf.cx>
* include/cygwin/version.h: Bump CYGWIN_VERSION_API_MINOR to 233. * include/cygwin/version.h: Bump CYGWIN_VERSION_API_MINOR to 233.

View File

@ -7,6 +7,7 @@
#include "winsup.h" #include "winsup.h"
#include "cygerrno.h" #include "cygerrno.h"
#include "sync.h" #include "sync.h"
#include <ctype.h>
#define STD_INSPIRED #define STD_INSPIRED
#define lint #define lint
@ -595,7 +596,13 @@ static struct state gmtmem;
#endif /* !defined TZ_STRLEN_MAX */ #endif /* !defined TZ_STRLEN_MAX */
static char lcl_TZname[TZ_STRLEN_MAX + 1]; static char lcl_TZname[TZ_STRLEN_MAX + 1];
static int lcl_is_set; static enum lcl_states
{
lcl_setting = -1,
lcl_unset = 0,
lcl_from_environment = 1,
lcl_from_default = 2
} lcl_is_set;
static int gmt_is_set; static int gmt_is_set;
#define tzname _tzname #define tzname _tzname
@ -1374,9 +1381,9 @@ static
void void
tzsetwall P((void)) tzsetwall P((void))
{ {
if (lcl_is_set < 0) if (lcl_is_set == lcl_setting)
return; return;
lcl_is_set = -1; lcl_is_set = lcl_setting;
#ifdef ALL_STATE #ifdef ALL_STATE
if (lclptr == NULL) { if (lclptr == NULL) {
@ -1387,8 +1394,7 @@ tzsetwall P((void))
} }
} }
#endif /* defined ALL_STATE */ #endif /* defined ALL_STATE */
#if defined (_WIN32) || defined (__CYGWIN__) #if defined (__CYGWIN__)
#define is_upper(c) ((unsigned)(c) - 'A' <= 26)
{ {
TIME_ZONE_INFORMATION tz; TIME_ZONE_INFORMATION tz;
char buf[BUFSIZ]; char buf[BUFSIZ];
@ -1398,7 +1404,7 @@ tzsetwall P((void))
GetTimeZoneInformation(&tz); GetTimeZoneInformation(&tz);
dst = cp = buf; dst = cp = buf;
for (src = tz.StandardName; *src; src++) for (src = tz.StandardName; *src; src++)
if (is_upper(*src)) *dst++ = *src; if (isupper(*src)) *dst++ = *src;
if ((dst - cp) < 3) if ((dst - cp) < 3)
{ {
/* In non-english Windows, converted tz.StandardName /* In non-english Windows, converted tz.StandardName
@ -1416,7 +1422,7 @@ tzsetwall P((void))
cp = strchr(cp, 0); cp = strchr(cp, 0);
dst = cp; dst = cp;
for (src = tz.DaylightName; *src; src++) for (src = tz.DaylightName; *src; src++)
if (is_upper(*src)) *dst++ = *src; if (isupper(*src)) *dst++ = *src;
if ((dst - cp) < 3) if ((dst - cp) < 3)
{ {
/* In non-english Windows, converted tz.DaylightName /* In non-english Windows, converted tz.DaylightName
@ -1454,7 +1460,7 @@ tzsetwall P((void))
/* printf("TZ deduced as `%s'\n", buf); */ /* printf("TZ deduced as `%s'\n", buf); */
if (tzparse(buf, lclptr, false) == 0) { if (tzparse(buf, lclptr, false) == 0) {
settzname(); settzname();
lcl_is_set = 1; lcl_is_set = lcl_from_default;
strlcpy(lcl_TZname, buf, sizeof (lcl_TZname)); strlcpy(lcl_TZname, buf, sizeof (lcl_TZname));
#if 0 #if 0
/* Huh? POSIX doesn't mention anywhere that tzset should /* Huh? POSIX doesn't mention anywhere that tzset should
@ -1479,16 +1485,16 @@ tzset P((void))
const char * name = getenv("TZ"); const char * name = getenv("TZ");
if (name == NULL) { if (name == NULL) {
if (!lcl_is_set) if (lcl_is_set != lcl_from_default)
tzsetwall(); tzsetwall();
goto out; goto out;
} }
if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0) if (lcl_is_set > 0 && strncmp(lcl_TZname, name, sizeof(lcl_TZname) - 1) == 0)
goto out; goto out;
lcl_is_set = (strlen(name) < sizeof (lcl_TZname)); lcl_is_set = (strlen(name) < sizeof (lcl_TZname)) ? lcl_from_environment : lcl_unset;
if (lcl_is_set) if (lcl_is_set != lcl_unset)
strcpy(lcl_TZname, name); strlcpy(lcl_TZname, name, sizeof (lcl_TZname));
#ifdef ALL_STATE #ifdef ALL_STATE
if (lclptr == NULL) { if (lclptr == NULL) {