[TUHS] Off topic: BSD timezone function vs. POSIX timezone variable

Chet Ramey chet.ramey at case.edu
Fri Dec 15 01:49:20 AEST 2023

On 12/14/23 10:14 AM, Leah Neukirchen wrote:
> Aharon Robbins <arnold at skeeve.com> writes:
>> Hi All.
>> This is a bit off-topic, but people here are likely to know the answer.
>> V7 had a timzone function:
>> 	char *timezone(int zone, int dst);
>> that returned a timezone name.  POSIX has a timezone variable which is
>> the offset in seconds from UTC.
>> The man pages for all of {Net,Free,Open}BSD seem to indicate that both
>> are available on those systems.
>> My question is, how? The declarations for both are given as being in <time.h>.
>> But don't the symbols in libc.a conflict with each other? How does a programmer
>> on *BSD choose which version of timezone they will get?
> OpenBSD 7.3 only has "extern long timezone" and no timezone(3) function.
> FreeBSD 14.0 only has the timezone(3) function (under _BSD_VISIBLE),
> and doesn't set any variables.

Darwin (macOS) conditionally defines them. If you want POSIX 2003
compatibility, define __DARWIN_UNIX03 and get

extern long timezone __DARWIN_ALIAS(timezone);

If you don't define that, you get

char *timezone(int, int);

``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet at case.edu    http://tiswww.cwru.edu/~chet/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 203 bytes
Desc: OpenPGP digital signature
URL: <http://www.tuhs.org/pipermail/tuhs/attachments/20231214/404dd912/attachment-0001.sig>

More information about the TUHS mailing list