This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Invalid tm_zone from localtime() when TZ is not set


Any other comments on this topic? Let me explain my proposal again.

The intention of the following code in tzsetwall() should be to pick
up UPPERCASE letters "in ASCII range":

if (isupper(*src)) *dst++ = *src;

NOTE: src is wchar_t *, dst is char *.

As Csaba Raduly pointed out, isw*() functions should be the first
choice if they achieve the desired behavior (select uppercase AND
ASCII). However, iswupper() does not fit for this purpose, as it
returns 1 for L'\uff21' for example. And I could not find isw*()
functions to achieve the behavior.

As the man page mentions, isupper() accepts int as its argument, but
it is defined only when isascii() is true (or EOF). Both isascii() and
isupper() accept int, not char. So it seems to me that

isascii(*src) && isupper(*src)

is fine even if *src is wchar_t, provided that:

1. Type of *src (wchar_t) <= int.
2. Code points used is an extension of ASCII.

I think these conditions are met. Because sizeof(wchar_t) is 2, and
sizeof(int) is 4 in Cygwin. The code points used here is an extension
of ASCII because the Windows function GetTimeZoneInformation() uses
UTF-16 encoding.

The second option might be to use a macro as it was before the
following commit, but I prefer using standard isascii() and isupper():

commit 49808040c5fa1390983945d38c7e8267b2b8a381
Author: Christopher Faylor
Date:   Sat Oct 30 19:22:42 2010 +0000

    * 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.

Regards,

KOBAYASHI Shinji.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]