summaryrefslogtreecommitdiff
path: root/libc/time
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1996-09-03 22:06:58 +0200
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:31:01 +0200
commit0936b9aeab611665645a4e6bafaded7ca76dd189 (patch)
treefe6384035e96adc260f621d27909be67ad2e724a /libc/time
parente85ee07172eccafd9441362e774f7b184810d008 (diff)
downloaddev86-0936b9aeab611665645a4e6bafaded7ca76dd189.tar.gz
Import Dev86-0.0.7.tar.gzv0.0.7
Diffstat (limited to 'libc/time')
-rw-r--r--libc/time/Config1
-rw-r--r--libc/time/Makefile17
-rw-r--r--libc/time/README7
-rw-r--r--libc/time/asc_conv.c46
-rw-r--r--libc/time/asctime.c15
-rw-r--r--libc/time/ctime.c26
-rw-r--r--libc/time/gmtime.c15
-rw-r--r--libc/time/localtime.c22
-rw-r--r--libc/time/tm_conv.c64
9 files changed, 213 insertions, 0 deletions
diff --git a/libc/time/Config b/libc/time/Config
new file mode 100644
index 0000000..053ab81
--- /dev/null
+++ b/libc/time/Config
@@ -0,0 +1 @@
+time: Unix time manipulation functions.
diff --git a/libc/time/Makefile b/libc/time/Makefile
new file mode 100644
index 0000000..d04e5f4
--- /dev/null
+++ b/libc/time/Makefile
@@ -0,0 +1,17 @@
+# Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
+# This file is part of the Linux-8086 C library and is distributed
+# under the GNU Library General Public License.
+
+TOP=..
+include $(TOP)/Make.defs
+
+OBJ=localtime.o gmtime.o asctime.o ctime.o asc_conv.o tm_conv.o
+
+all: $(OBJ)
+
+libc.a: $(OBJ)
+ ar r ../$(LIBC) $(OBJ)
+ @touch libc.a
+
+clean:
+ rm -f *.o libc.a
diff --git a/libc/time/README b/libc/time/README
new file mode 100644
index 0000000..0d50401
--- /dev/null
+++ b/libc/time/README
@@ -0,0 +1,7 @@
+Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
+This file is part of the Linux-8086 C library and is distributed
+under the GNU Library General Public License.
+
+There's currently nothing special about time.
+
+-Robert
diff --git a/libc/time/asc_conv.c b/libc/time/asc_conv.c
new file mode 100644
index 0000000..0ba48f1
--- /dev/null
+++ b/libc/time/asc_conv.c
@@ -0,0 +1,46 @@
+
+#include <time.h>
+#include <string.h>
+/*
+ * Internal ascii conversion routine, avoid use of printf, it's a bit big!
+ */
+
+static hit(buf, val)
+char * buf;
+int val;
+{
+ *buf = '0' + val%10;
+}
+
+void
+__asctime(buffer, ptm)
+char * buffer;
+struct tm * ptm;
+{
+static days[] = "SunMonTueWedThuFriSat";
+static mons[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+ int year;
+
+ /* 012345678901234567890123456 */
+ strcpy(buffer, "Err Err .. ..:..:.. ....\n");
+ if( ptm->tm_wday >= 0 && ptm->tm_wday <= 6 )
+ memcpy(buffer, days+3*ptm->tm_wday, 3);
+
+ if( ptm->tm_mon >= 1 && ptm->tm_mon <= 12 )
+ memcpy(buffer+4, mons+3*ptm->tm_mon-3, 3);
+
+ hit(buffer+ 8, ptm->tm_mday/10);
+ hit(buffer+ 9, ptm->tm_mday );
+ hit(buffer+11, ptm->tm_hour/10);
+ hit(buffer+12, ptm->tm_hour );
+ hit(buffer+14, ptm->tm_min/10);
+ hit(buffer+15, ptm->tm_min );
+ hit(buffer+17, ptm->tm_sec/10);
+ hit(buffer+18, ptm->tm_sec );
+
+ year = ptm->tm_year + 1900;
+ hit(buffer+20, year/1000);
+ hit(buffer+21, year/100);
+ hit(buffer+22, year/10);
+ hit(buffer+23, year);
+}
diff --git a/libc/time/asctime.c b/libc/time/asctime.c
new file mode 100644
index 0000000..b66cd37
--- /dev/null
+++ b/libc/time/asctime.c
@@ -0,0 +1,15 @@
+
+#include <time.h>
+
+extern void __asctime();
+
+char *
+asctime(timeptr)
+struct tm * timeptr;
+{
+static char timebuf[26];
+
+ if( timeptr == 0 ) return 0;
+ __asctime(timebuf, timeptr);
+ return timebuf;
+}
diff --git a/libc/time/ctime.c b/libc/time/ctime.c
new file mode 100644
index 0000000..bc7283d
--- /dev/null
+++ b/libc/time/ctime.c
@@ -0,0 +1,26 @@
+
+#include <time.h>
+
+extern void __tm_conv();
+extern void __asc_conv();
+
+char *
+ctime(timep)
+time_t * timep;
+{
+static char cbuf[26];
+ struct tm tmb;
+ struct timezone tz;
+ time_t offt;
+
+ gettimeofday((void*)0, &tz);
+
+ offt = -tz.tz_minuteswest*60L;
+
+ /* tmb.tm_isdst = ? */
+ __tm_conv(&tmb, &timep, offt);
+
+ __asc_conv(cbuf, &tmb);
+
+ return cbuf;
+}
diff --git a/libc/time/gmtime.c b/libc/time/gmtime.c
new file mode 100644
index 0000000..29907d0
--- /dev/null
+++ b/libc/time/gmtime.c
@@ -0,0 +1,15 @@
+
+#include <time.h>
+
+extern void __tm_conv();
+
+struct tm *
+gmtime(timep)
+time_t * timep;
+{
+ static struct tm tmb;
+
+ __tm_conv(&tmb, &timep, 0L);
+
+ return &tmb;
+}
diff --git a/libc/time/localtime.c b/libc/time/localtime.c
new file mode 100644
index 0000000..b0b729c
--- /dev/null
+++ b/libc/time/localtime.c
@@ -0,0 +1,22 @@
+
+#include <time.h>
+
+extern void __tm_conv();
+
+struct tm *
+localtime(timep)
+time_t * timep;
+{
+ static struct tm tmb;
+ struct timezone tz;
+ time_t offt;
+
+ gettimeofday((void*)0, &tz);
+
+ offt = -tz.tz_minuteswest*60L;
+
+ /* tmb.tm_isdst = ? */
+ __tm_conv(&tmb, &timep, offt);
+
+ return &tmb;
+}
diff --git a/libc/time/tm_conv.c b/libc/time/tm_conv.c
new file mode 100644
index 0000000..96f4735
--- /dev/null
+++ b/libc/time/tm_conv.c
@@ -0,0 +1,64 @@
+
+#include <time.h>
+
+/* This is a translation from ALGOL in Collected Algorithms of CACM. */
+/* Copied from Algorithm 199, Author: Robert G. Tantzen */
+
+void
+__tm_conv(tmbuf, timep, offset)
+struct tm *tmbuf;
+time_t *timep;
+time_t offset;
+{
+static int moffset[] =
+ {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
+
+ long s;
+ long j, d, m, y;
+
+ offset += *timep;
+
+ tmbuf->tm_isdst = 0; /* Someone else can set this */
+
+ j = offset / 86400L + 719469;
+ s = offset % 86400L;
+
+ if( s < 0 ) { s += 86400L; j--; }
+
+ tmbuf->tm_sec = s % 60;
+ tmbuf->tm_min = (s / 60) % 60;
+ tmbuf->tm_hour = s / 3600;
+
+ tmbuf->tm_wday = (j+2) % 7;
+
+ /*
+ * Julian date converter. Takes a julian date (the number of days since
+ * some distant epoch or other), and fills tmbuf.
+ */
+
+ y = (4L * j - 1L) / 146097L;
+ j = 4L * j - 1L - 146097L * y;
+ d = j / 4L;
+ j = (4L * d + 3L) / 1461L;
+ d = 4L * d + 3L - 1461L * j;
+ d = (d + 4L) / 4L;
+ m = (5L * d - 3L) / 153L;
+ d = 5L * d - 3 - 153L * m;
+ d = (d + 5L) / 5L;
+ y = 100L * y + j;
+ if (m < 10)
+ m += 2;
+ else
+ {
+ m -= 10;
+ ++y;
+ }
+
+ tmbuf->tm_year = y - 1900;
+ tmbuf->tm_mon = m;
+ tmbuf->tm_mday = d;
+
+ tmbuf->tm_yday = d + moffset[m];
+ if (m > 1 && ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0)))
+ tmbuf->tm_yday++;
+}