aboutsummaryrefslogtreecommitdiff
path: root/src/lib9/ctime.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2003-11-23 18:12:54 +0000
committerrsc <devnull@localhost>2003-11-23 18:12:54 +0000
commitfd04aacee17b348da206c13a550dc1029669805f (patch)
tree9bdd35a25ff6e3d6e9a0171b06240a76723f922c /src/lib9/ctime.c
parent74f990ad84deb1591ddb91be4fc8152ec0c46222 (diff)
downloadplan9port-fd04aacee17b348da206c13a550dc1029669805f.tar.gz
plan9port-fd04aacee17b348da206c13a550dc1029669805f.tar.bz2
plan9port-fd04aacee17b348da206c13a550dc1029669805f.zip
Various additions and fixes.
Diffstat (limited to 'src/lib9/ctime.c')
-rw-r--r--src/lib9/ctime.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/lib9/ctime.c b/src/lib9/ctime.c
new file mode 100644
index 00000000..e9d971bf
--- /dev/null
+++ b/src/lib9/ctime.c
@@ -0,0 +1,51 @@
+#include <u.h>
+#include <libc.h>
+
+static
+void
+ct_numb(char *cp, int n)
+{
+
+ cp[0] = ' ';
+ if(n >= 10)
+ cp[0] = (n/10)%10 + '0';
+ cp[1] = n%10 + '0';
+}
+
+char*
+asctime(Tm *t)
+{
+ char *ncp;
+ static char cbuf[30];
+
+ strcpy(cbuf, "Thu Jan 01 00:00:00 GMT 1970\n");
+ ncp = &"SunMonTueWedThuFriSat"[t->wday*3];
+ cbuf[0] = *ncp++;
+ cbuf[1] = *ncp++;
+ cbuf[2] = *ncp;
+ ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[t->mon*3];
+ cbuf[4] = *ncp++;
+ cbuf[5] = *ncp++;
+ cbuf[6] = *ncp;
+ ct_numb(cbuf+8, t->mday);
+ ct_numb(cbuf+11, t->hour+100);
+ ct_numb(cbuf+14, t->min+100);
+ ct_numb(cbuf+17, t->sec+100);
+ ncp = t->zone;
+ cbuf[20] = *ncp++;
+ cbuf[21] = *ncp++;
+ cbuf[22] = *ncp;
+ if(t->year >= 100) {
+ cbuf[24] = '2';
+ cbuf[25] = '0';
+ }
+ ct_numb(cbuf+26, t->year+100);
+ return cbuf;
+}
+
+char*
+ctime(long t)
+{
+ return asctime(localtime(t));
+}
+