Technical article 100836

ctime(S) and localtime(S) do not use the TZ variable when calculating time.

OpenServer 5.0.0OpenServer 5.0.2

Written · Last revised

Problem

I have compiled the following sample code using the command:

cc -o foo foo.c -Xm -a ods30 -b coff

If I run the resulting binary on SCO UNIX System V/386 Release 3.2 Operating System Version 4.2 or SCO Open Server Release 3.0, the time displayed is incorrect, if Daylight Savings time is active on the system.

For example, the date(C) command on SCO UNIX Operating System Version 4.2 returns:

04:01:24 PM Tue 15 Oct 1996 BST
but the following code returns:
Local time is [Tue Oct 15 15:01:24 1996]
It does not take into account the time zone environment variable
tz(M).
#include <stdio.h>
#include <time.h>
void main()
{
        char datetime[25];
        long clock;
time(&clock);
strncpy(datetime,ctime(&clock),24);
datetime[24] = 0;
        printf("Local time is [%s]\n",datetime);
}

Cause

There is a problem with the ctime(S) and localtime(S) library functions that causes them to fail when run on SCO UNIX Version 4.2 and SCO Open Server Release 3.0 based systems.

Solution

This problem has been reported to SCO Engineering.

From the Xinuos technical article database, record 100836. Reproduced with permission. The original is at www.sco.com/ta/100836, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.