asctime.c
/* Copyright (C) 1984 by Manx Software Systems */
#include <time.h>

char *
asctime(tm)
struct tm *tm;
{
	static char days[7][4] = {
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
	};
	static char months[12][4] = {
		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
	};
	static char buffer[26];

	sprintf(buffer, "%s %s %2d %02d:%02d:%02d %4d\n",
		days[tm->tm_wday], months[tm->tm_mon], tm->tm_mday,
		tm->tm_hour, tm->tm_min, tm->tm_sec, tm->tm_year+1900);
	return buffer;
}
ctime.c
/* Copyright (C) 1984 by Manx Software Systems */
#include <time.h>

char *
ctime(clock)
long *clock;
{
	struct tm *tm;

	tm = localtime(clock);
	return asctime(tm);
}
localtim.c
/* Copyright (C) 1986 by Manx Software Systems */
#include <time.h>

struct tm *
gmtime(clock)
long *clock;
{
	struct tm *localtime();

	return localtime(clock);
}

struct tm *
localtime(clock)
long *clock;
{
	register long l, t;
	register int i;
	static struct tm tm;
	static int days[12] = {
		31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
	};

	l = *clock;
	tm.tm_sec = l % 60;
	l /= 60;
	tm.tm_min = l % 60;
	l /= 60;
	tm.tm_hour = l % 24;
	l /= 24;
	tm.tm_wday = l%7;
	tm.tm_year = 78 + (l/(4*365+1)) * 4;
	l %= 4 * 365 + 1;
	while (l) {
		t = 365;
		if ((tm.tm_year&3) == 0)
			t++;
		if (l < t)
			break;
		l -= t;
		tm.tm_year++;
	}
	tm.tm_yday = ++l;
	for (i=0;i<12;i++) {
		t = days[i];
		if (i == 1 && (tm.tm_year&3) == 0)
			t++;
		if (l < t)
			break;
		l -= t;
	}
	tm.tm_mon = i;
	tm.tm_mday = l;
	return &tm;
}

makefile
.SUFFIXES: .r
CFLAGS=

.c.r:
	c68 +b $(CFLAGS) -o $@ $*.c

.c.r32:
	c68 +bl $(CFLAGS) -o $@ $*.c

C=asctime.r ctime.r localtim.r time.r
C32=asctime.r32 ctime.r32 localtim.r32 time.r32

all:	$(C) $(C32)
	echo

time.c
/* Copyright (C) 1986 by Manx Software Systems */

#include	<exec/types.h>
#include	<exec/lists.h>
#include	<devices/timer.h>

long
time(tt)
long *tt;
{
	struct MsgPort *CreatePort();
	unsigned long hz;
	struct timerequest t;

	if (OpenDevice(TIMERNAME, UNIT_VBLANK, &t, 0L)) {
		printf("timer is not available\n");
		exit(1);
	}

	t.tr_node.io_Message.mn_ReplyPort = CreatePort(0L, 0L);
	t.tr_node.io_Command = TR_GETSYSTIME;
	DoIO(&t);
	hz = t.tr_time.tv_secs + (t.tr_time.tv_micro + 500000) / 1000000;
	CloseDevice(&t);
	DeletePort(t.tr_node.io_Message.mn_ReplyPort);

	if (tt)
		*tt = hz;
	return(hz);
}

