ref: facb661abe23b107da939e575aa9f9fbf58ac88b
parent: 6fa06d8a266d0fdf5c2382fcd108edc1dba4ca12
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Fri Jul 9 09:57:37 EDT 2021
isatty, gmtime, isfinite, signbit (WRONG), ERANGE
--- a/include/npe/errno.h
+++ b/include/npe/errno.h
@@ -5,6 +5,7 @@
enum {
ENOENT = 2,
+ ERANGE = 34,
};
extern int errno;
--- a/include/npe/math.h
+++ b/include/npe/math.h
@@ -49,4 +49,8 @@
int isinf(double d);
int isnormal(double d);
+#define isfinite(x) (!isinf(x))
+/* FIXME this is totally wrong */
+#define signbit(x) (x == -0.0 || x < 0.0)
+
#endif
--- a/include/npe/time.h
+++ b/include/npe/time.h
@@ -21,6 +21,8 @@
#define localtime npe_localtime
struct tm *npe_localtime(time_t *timep);
+#define gmtime npe_gmtime
+struct tm *npe_gmtime(time_t *timep);
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
time_t mktime(struct tm *tm);
--- a/include/npe/unistd.h
+++ b/include/npe/unistd.h
@@ -51,5 +51,6 @@
int npe_stat(char *filename, struct stat *buf);
int access(char *name, int mode);
void usleep(useconds_t us);
+int isatty(int fd);
#endif
--- /dev/null
+++ b/libnpe/gmtime.c
@@ -1,0 +1,27 @@
+#include <time.h>
+
+#undef gmtime
+
+static struct tm tm;
+
+struct tm *
+npe_gmtime(time_t *timep)
+{
+ time_t ti;
+ Tm *t;
+
+ ti = timep ? *timep : time(nil);
+ if((t = gmtime(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;
+}
--- /dev/null
+++ b/libnpe/isatty.c
@@ -1,0 +1,10 @@
+#include <unistd.h>
+#include "_npe.h"
+
+int
+isatty(int fd)
+{
+ char buf[64];
+
+ return fd2path(fd, buf, sizeof(buf)) == 0 && strcmp(buf, "/dev/cons") == 0;
+}
--- a/libnpe/mkfile
+++ b/libnpe/mkfile
@@ -20,9 +20,11 @@
fts_set.$O\
getenv.$O\
gettimeofday.$O\
+ gmtime.$O\
iconv.$O\
iconv_close.$O\
iconv_open.$O\
+ isatty.$O\
isinf.$O\
isnormal.$O\
localtime.$O\