Frank Hofmann wrote:
> On Wed, 4 Jul 2007, Frank Hofmann wrote:
> > I wonder what is the simplest way to validate, from a C program, whether a
> > given string can be successfully parsed as TZ (timezone) environment
> > variable.
> >
> > Thing is, tzset(3C) is not returning any error code. So if I putenv()
> > something into TZ, and do the tzset() afterwards, it'll "do something".
> > It'll simply set the global variables timezone/altzone/daylight/tzname[]
> > to 0/0/0/{"GMT", " "}.
> >
> > But that's the same as specifying TZ=GMT (which is actually valid). So
> > it's not sufficient just testing for the tuple above.
> >
> > It seems the thing I need to do to validate something is a usable TZ
> > environment variable is:
> >
> > - putenv(); tzset()
> > - test for the above tuple
> > - additionally validate tzname[0] != <my TZ string>
> >
> > Any better ideas ?
>
> Sorry to followup myself, but I'd like to add an interesting tidbit that
> googling found me there. This old posting:
>
> http://archives.postgresql.org/pgsql-hackers/2001-03/msg01609.php
>
> describes sort of what I try to do. The test program is obvious, I came up
> with the same before finding the above ...
>
> Some of the difficult things to exclude are:
>
> TZ=GMT invalid by POSIX (should be GMT0), but accepted (?)
> TZ=GMT500 rejected by Solaris as out-of-range
> would pass the tests below, though ...
>
> Also, it seems that tzset() resulting in the behaviour below on failure is
> Solaris-specific; that'd be sufficient for my purpose, but a portable way
> of detecting success/failure of using a setting of TZ would be
> appreciated.
What about checking whether the TZ value has a subdir in
/usr/share/lib/zoneinfo/ ?
----
Bye,
Roland
P.S.: Is there any (POSIX) API to list all supported timezones ?
--
__ . . __
(o.\ \/ /.o) [EMAIL PROTECTED]
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 7950090
(;O/ \/ \O;)
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code