scsh-users
[Top] [All Lists]

Help with a little test

To: scsh-news@martigny.ai.mit.edu
Subject: Help with a little test
From: Olin Shivers <shivers@lambda.ai.mit.edu>
Date: 24 Apr 1997 14:31:23 -0400
Organization: Artificial Intelligence Lab, MIT
I would appreciate it if people would try out the following little program on
their OS and tell me what it prints out. It tests the behaviour of the Posix
mktime() function in three cases (a good date, a bad date, and Epoch-1sec,
i.e. 11:59:59 pm UTC 11/31/69). This is what you do:

    - finger shivers@ai.mit.edu to find out which OS's have already
        been covered. Check to see if your case has been done. I already
        have HP-UX, linux, and FreeBSD. I'll add others as people mail them
        in.
    - Put the C code below into a file, tmtest.c
    - Compile and run the program, and mail me the 3 lines of output,
      along with a description of your OS and machine. This will do it:
        cc -o tmtest tmtest.c
        (uname -a; ./tmtest) | mail -s tmtest shivers@ai.mit.edu

I want to check to see if a test to disambiguate time -1 from an error case
works for all the Unix's out there. The ANSI C spec seems to indicate it
should work, but that doesn't mean the implementations do the right thing...

Thanks.
    -Olin
-------------------------------------------------------------------------------
/* Check out if mktime() mungs the day-of-the-week and day-of-the-year
** slots of its argument when there's an error.
**
** Typical output:
** Good date:      t=852076800 wday=3 yday=0
** Bad date:       t=-1 wday=8 yday=367
** Ugly date:      t=-1 wday=3 yday=364
**
** Want test-runs on NetBSD, Solaris, SunOS, Irix, AIX, NeXT, Ultrix, etc.
**
** To run: 
**   cc -o tmtest tmtest.c
**   ./tmtest
**
** Olin Shivers (shivers@ai.mit.edu)
*/

#include <stdio.h>
#include <time.h>

extern char **environ;
static char *utc_env[] = {"TZ=UCT0", 0};

void dotest(char *name, int s, int m, int h, 
                        int mday, int mon, int y)
{
  struct tm date;
  time_t t;

  date.tm_sec = s;
  date.tm_min = m;
  date.tm_hour = h;
  date.tm_mday = mday;
  date.tm_mon = mon;
  date.tm_year = y;
  date.tm_wday = 8;     /* Illegal value */
  date.tm_yday = 367;   /* Illegal value */
  date.tm_isdst = 0;
  t = mktime(&date);
  printf("%s date:\tt=%d wday=%d yday=%d\n", name, t,
                                             date.tm_wday, date.tm_yday);
}

main()
{

  environ = utc_env;    /* Shift to UTC. */
  tzset();              /* Just to be safe -- some loser OS's require this. */

  dotest("Good",  0,0,0, 1,0,97);      /* Good date: Midnight, Jan 1, 1997. */
  dotest("Bad",  70,70,25, 32,13,0);   /* Bad date. */
  dotest("Ugly", 59,59,23, 31,11,69);  /* Time -1: 11:59:59 PM UTC, 12/31/69 */
}

<Prev in Thread] Current Thread [Next in Thread>
  • Help with a little test, Olin Shivers <=