On Mon, 3 May 2004 20:47:31 -0400, Vikram Kulkarni
<[EMAIL PROTECTED]> wrote:
>test=# SELECT timeofday();
>              timeofday
>-------------------------------------
> Wed Dec 31 16:00:00.591964 1969 PST
>(1 row)
>[...]
>That obviously doesn't look right. Isnt' timeofday() supposed to return
>the current time of day? The system clock is set correctly.

Vik, I guess that on your platform time_t is smaller than long.  Please
compile and run the attached C program.

Servus
 Manfred
/*
** timeofday
*/

#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>

static void old_timeofday()
{
        struct timeval tp;
        struct timezone tpz;
        char            templ[100];
        char            buf[100];

        gettimeofday(&tp, &tpz);
        strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
                         localtime((time_t *) &tp.tv_sec));
        snprintf(buf, sizeof(buf), templ, tp.tv_usec);

        printf("old: >>%s<<\n", buf);
}/*old_timeofday*/

static void new_timeofday()
{
        struct timeval tp;
        struct timezone tpz;
        char            templ[100];
        char            buf[100];
        time_t tt;

        gettimeofday(&tp, &tpz);
        tt = tp.tv_sec;
        strftime(templ, sizeof(templ), "%a %b %d %H:%M:%S.%%06d %Y %Z",
                         localtime(&tt));
        snprintf(buf, sizeof(buf), templ, tp.tv_usec);

        printf("new: >>%s<<\n", buf);
}/*new_timeofday*/

int main(int argc, char *argv[])
{
        old_timeofday();
        new_timeofday();
}/*main*/
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to