[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [leafnode-list] [ANNOUNCE:] leafnode-1.9.12

From: Joerg Dietrich <joerg@xxxxxxxxxxxx>

> On Sat, Apr 01, 2000 at 06:04:12PM -0500, Curly wrote:

> > Here's your test program with the changes inserted:
> >     char *zone = getenv("TZ" );    // save current offset
> This is clearly non-portable. TZ isn't set here, and I would
> rely on any environment variable, esp. if your program runs as a
> system user (news in this case).

What's "here"?  I'm running RedHat 6.x for all x,  I have AIX 4.1
and Interactive Unix 3.2.  I can only speak to portability within
these bounds.

On these systems, TZ is the final word on time zones.  There is a
fallback to a system setting in a file in /etc/localtime that is
used if TZ is unset.  I'm not sure if Interactive supports
/etc/localtime.  In any case, the value is set by a routine
"tzset".  This routine is called by the library functions that
deal with local time.  TZ is about as portable as anything in

Being a "system user" does not allow you to ignore the inputs
used by a library function.  For example, in AIX the sysadmin can
edit a file which contains the initial environment for any new
login or system program.  The sysadmin may set TZ in this file.
Read `man environment` on AIX.  I haven't seen this on other
systems, but there's some wierd stuff out there!

> - Does time( NULL ) return seconds since the epoch in local
>   (Yes according to MA)

No, according to the man pages on my systems.

I think the oldest page says it most clearly, but they all agree
that time(0) returns UTC.  From the Interactive Unix man page:

    The time system call returns the value of time in seconds
    since 00:00:00 Greenwich Mean Time (GMT), January 1, 1970.

I verified this on Linux with a program that twiddled TZ and
printed both the decimal and decoded values of time().

> > >     age = mktime( &timearray ) - ltime->tm_gmtoff;
> mktime -- at least on my glibc-2.1.2 Linux system -- sets the
> external variable tzname correctly (to EST in my case).

Actually, tzset() sets this value.  The man pages say that all
functions that deal with local time call tzset to set that
variable.  See `man tzset` if you have it.  If not, I can quote
it for you.  It's long, but interesting.

>From the AIX man pages:

    The tzname external variable contains the name of the
    standard time zone (tzname[0]) and of the time zone when
    Daylight Savings Time is in effect (tzname[1]). For

       char *tzname[2] = {"EST", "EDT"};

Linux man pages agree with AIX, but are less readable.
Interactive Unix does not document tzname or tzset in the man
pages.  However, a three-line program indicates both exist and
work correctly.

> - Is tm_gmtoff "time(NULL, UTC) - time(NULL, local time)" or
>   versa?

This doesn't exist on Interactive or on AIX.  The only reference
I can find to is in the Linux header file where:

  # ifdef __USE_BSD
    long int tm_gmtoff;      /* Seconds east of UTC.  */
    __const char *tm_zone;   /* Timezone abbreviation.  */
  # else
    long int __tm_gmtoff;    /* Seconds east of UTC.  */
    __const char *__tm_zone; /* Timezone abbreviation.  */
  # endif

it is obviously not portable.

I would suggest instead building a function to construct the
value.  That would be portable to any *nix unless there is one
out there that does not use TZ?

I'd include such a function, but this timezone is about to spring
forward and I haven't played *any* NetHack today!  <grin>

Oisin  "Curly++"  Curtin                     ocurtin@SPAM@usa.net
Surface Liaison, Minetown Digger                    Send no SPAM@

leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list