Listing 2: gtimes.c

NAME

   gtimes.c - Calculate clock times.

SYNOPSIS
   
   gtimes [ clock value ]
	- where clock value is a long integer which was previously returned
	  by the time system call.

DESCRIPTION

   This program without an argument will report the current system time
   both as an ASCII string, and as a long integer which is directly
   reported from time(S).
   Invocation with an argument results in the ASCII time string which
   matches the clock value on the command line.

RETURN VALUE

   Always returns 0.

WARNINGS

   There are no provisions for bad data, or overflow.

 ------------------------------------------------------------------------- */
/* Copyright 1988 Chris Hare */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <errno.h>

main( argc, argv )
int argc;
char *argv[];

   {

   char *ctime(),		/* declare ctime(S) */
	*timestr;		/* storage area for time string */
   long int t_secs,		/* return value from time(S) */
	    o_secs,		/* long integer value of command argument */
	    atol(),		/* declare atol(S) */
	    time();		/* declare time(S) */
	struct tm *mytime;
	struct tm *localtime();
	char *atime_str;

   if ( argc == 1 )
      t_secs = time(0L);
   else
      t_secs = atol(argv[1]);

   timestr = ctime(&t_secs);

   printf( "Clock : %ld\nDate  : %s\n", t_secs, timestr );

   exit(0);

   }
