shithub: npe

Download patch

ref: 2fea808391f397ddb906ec726d8b3f4a2a4b8e7b
parent: c969b291d8a6c543311b0c66ae770b7cb48ba10b
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Mar 17 03:19:16 EDT 2021

time_t and localtime

--- a/include/npe/time.h
+++ b/include/npe/time.h
@@ -1,1 +1,23 @@
+#ifndef _time_h_
+#define _time_h_
+
 #include "plan9.h"
+
+typedef long time_t;
+
+struct tm {
+	int tm_sec;
+	int tm_min;
+	int tm_hour;
+	int tm_mday;
+	int tm_mon;
+	int tm_year;
+	int tm_wday;
+	int tm_yday;
+	int tm_isdst;
+};
+
+#define localtime npe_localtime
+struct tm *npe_localtime(time_t *timep);
+
+#endif
--- /dev/null
+++ b/libnpe/localtime.c
@@ -1,0 +1,27 @@
+#include <time.h>
+
+#undef localtime
+
+static struct tm tm;
+
+struct tm *
+npe_localtime(time_t *timep)
+{
+	time_t ti;
+	Tm *t;
+
+	ti = timep ? *timep : time(nil);
+	if((t = localtime(ti)) != nil){
+		tm.tm_sec = t->sec;
+		tm.tm_min = t->min;
+		tm.tm_hour = t->hour;
+		tm.tm_mday = t->mday;
+		tm.tm_mon = t->mon;
+		tm.tm_year = t->year;
+		tm.tm_wday = t->wday;
+		tm.tm_yday = t->yday;
+		tm.tm_isdst = 0; /* FIXME */
+	}
+
+	return &tm;
+}
--- a/libnpe/mkfile
+++ b/libnpe/mkfile
@@ -16,6 +16,7 @@
 	iconv.$O\
 	iconv_close.$O\
 	iconv_open.$O\
+	localtime.$O\
 	log2.$O\
 	lrint.$O\
 	lrintf.$O\