shithub: npe

Download patch

ref: ea4e9e55d8fd27607c4204416d4c3a36370ff359
parent: 320b7d8531b3fb2a1a002ac214c7c703a9e92082
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Mar 15 10:14:31 EDT 2021

rearrange and rename to avoid conflicts

--- a/include/npe/limits.h
+++ b/include/npe/limits.h
@@ -1,18 +1,64 @@
 #ifndef _limits_h_
 #define _limits_h_
 
-#define INT16_MAX 0x7fff
-#define INT16_MIN ((int16_t)0x8000)
-#define INT64_MIN ((int64_t)0x8000000000000000ULL)
-#define INT32_MAX 0x7fffffff
-#define INT_MAX INT32_MAX
-#define INT32_MIN (-INT32_MAX-1)
-#define INT_MIN INT32_MIN
+#ifndef SHRT_MAX
 #define SHRT_MAX 0x7fff
+#endif
+
+#ifndef SHRT_MIN
 #define SHRT_MIN (-SHRT_MAX-1)
+#endif
+
+#ifndef SIZE_MAX
 #define SIZE_MAX 0xffffffffU
+#endif
+
+#ifndef PATH_MAX
+#define PATH_MAX 256
+#endif
+
+#ifndef INT16_MAX
+#define INT16_MAX 0x7fff
+#endif
+
+#ifndef INT32_MAX
+#define INT32_MAX  0x7fffffff
+#endif
+
+#ifndef UINT32_MAX
 #define UINT32_MAX 0xffffffffU
-#define UINT_MAX UINT32_MAX
+#endif
+
+#ifndef INT64_MAX
+#define INT64_MAX 0x7fffffffffffffff
+#endif
+
+#ifndef UINT64_MAX
 #define UINT64_MAX 0xffffffffffffffffULL
+#endif
+
+#ifndef INT_MAX
+#define INT_MAX INT32_MAX
+#endif
+
+#ifndef UINT_MAX
+#define UINT_MAX UINT32_MAX
+#endif
+
+#ifndef INT16_MIN
+#define INT16_MIN ((s16int)0x8000)
+#endif
+
+#ifndef INT32_MIN
+#define INT32_MIN (-INT32_MAX-1)
+#endif
+
+#ifndef INT64_MIN
+#define INT64_MIN ((s64int)0x8000000000000000ULL)
+#endif
+
+#ifndef INT_MIN
+#define INT_MIN INT32_MIN
+#endif
 
 #endif
--- a/include/npe/plan9.h
+++ b/include/npe/plan9.h
@@ -7,14 +7,14 @@
 
 #pragma lib "libnpe.a"
 
-#define PATH_MAX 256
-
+#ifndef __attribute__
 #define __attribute__(a)
-#define main __main
-#define NSEC 1000000000ULL
+#endif
 
-int rm_r(char *dir);
-uvlong nanosec(void);
-void nsleep(uvlong ns);
+/* to override "main" with our own threadmain */
+#define main npe_main_renamed
+
+uvlong npe_nanosec(void);
+void npe_nsleep(uvlong ns);
 
 #endif
--- a/include/npe/stdio.h
+++ b/include/npe/stdio.h
@@ -1,1 +1,8 @@
+#ifndef _stdio_h_
+#define _stdio_h_
+
 #include "plan9.h"
+
+int rename(char *old, char *new);
+
+#endif
--- a/include/npe/stdlib.h
+++ b/include/npe/stdlib.h
@@ -3,6 +3,13 @@
 
 #include "plan9.h"
 
-#define exit(x) exits(x == 0 ? nil : "error")
+#define getenv npe_getenv
+
+#ifndef exit
+void threadexitsall(char *);
+#define exit(x) threadexitsall(x == 0 ? nil : "error")
+#endif
+
+char *npe_getenv(char *s);
 
 #endif
--- a/include/npe/sys/stat.h
+++ b/include/npe/sys/stat.h
@@ -1,1 +1,8 @@
+#ifndef _sys_stat_h_
+#define _sys_stat_h_
+
 #include "plan9.h"
+
+int mkdir(char *path, int perm);
+
+#endif
--- a/include/npe/unistd.h
+++ b/include/npe/unistd.h
@@ -28,9 +28,10 @@
 	S_IXOTH = 00001,
 };
 
+typedef unsigned useconds_t;
+
 #define getcwd getwd
-#define getenv getenv9
-#define stat stat9
+#define stat npe_stat
 
 struct stat9 {
 	uvlong st_size;
@@ -37,11 +38,8 @@
 	int st_mode;
 };
 
-char *getenv9(char *s);
-int stat9(char *filename, struct stat9 *buf);
-int mkdir(char *path, int perm);
+int npe_stat(char *filename, struct stat9 *buf);
 int access(char *name, int mode);
-int rename(char *old, char *new);
-void usleep(unsigned us);
+void usleep(useconds_t us);
 
 #endif
--- a/libnpe/_main.c
+++ b/libnpe/_main.c
@@ -4,9 +4,9 @@
 void
 threadmain(int argc, char **argv)
 {
-	int __main(int argc, char *argv[]);
+	int npe_main_renamed(int argc, char *argv[]);
 
 	setfcr(getfcr() & ~(FPINVAL|FPOVFL));
 
-	threadexitsall(__main(argc, argv) == 0 ? nil : "error");
+	threadexitsall(npe_main_renamed(argc, argv) == 0 ? nil : "error");
 }
--- a/libnpe/_plan9.c
+++ b/libnpe/_plan9.c
@@ -1,6 +1,10 @@
 #include "plan9.h"
 #include <tos.h>
 
+enum {
+	Nsec = 1000000000ULL,
+};
+
 /*
  * nsec() is wallclock and can be adjusted by timesync
  * so need to use cycles() instead, but fall back to
@@ -7,7 +11,7 @@
  * nsec() in case we can't
  */
 uvlong
-nanosec(void)
+npe_nanosec(void)
 {
 	static uvlong fasthz, xstart;
 	uvlong x, div;
@@ -31,17 +35,17 @@
 	x -= xstart;
 
 	/* this is ugly */
-	for(div = NSEC; x < 0x1999999999999999ULL && div > 1 ; div /= 10ULL, x *= 10ULL);
+	for(div = Nsec; x < 0x1999999999999999ULL && div > 1 ; div /= 10ULL, x *= 10ULL);
 
 	return x / (fasthz / div);
 }
 
 void
-nsleep(uvlong ns)
+npe_nsleep(uvlong ns)
 {
 	uvlong start, end;
 
-	start = nanosec();
+	start = npe_nanosec();
 	end = start + ns;
 	ns = start;
 	do{
@@ -53,6 +57,6 @@
 			sleep(1);
 		else
 			break;
-		ns = nanosec();
+		ns = npe_nanosec();
 	}while(ns < end);
 }
--- a/libnpe/getenv.c
+++ b/libnpe/getenv.c
@@ -3,7 +3,7 @@
 #undef getenv
 
 char *
-getenv9(char *s)
+npe_getenv(char *s)
 {
 	static char *e;
 
--- a/libnpe/stat.c
+++ b/libnpe/stat.c
@@ -3,7 +3,7 @@
 #undef stat
 
 int
-stat9(char *filename, struct stat9 *buf)
+npe_stat(char *filename, struct stat9 *buf)
 {
 	Dir *d;
 
--- a/libnpe/usleep.c
+++ b/libnpe/usleep.c
@@ -1,7 +1,7 @@
 #include <unistd.h>
 
 void
-usleep(unsigned us)
+usleep(useconds_t us)
 {
-	nsleep((uvlong)us*1000ULL);
+	npe_nsleep((uvlong)us*1000ULL);
 }
--- a/libnpe_sdl2/sdl2.c
+++ b/libnpe_sdl2/sdl2.c
@@ -935,7 +935,7 @@
 void
 SDL_Delay(Uint32 ms)
 {
-	nsleep((uvlong)ms*1000000ULL);
+	npe_nsleep((uvlong)ms*1000000ULL);
 }
 
 static void *
@@ -1242,7 +1242,7 @@
 Uint32
 SDL_GetTicks(void)
 {
-	return nanosec()/1000000ULL;
+	return npe_nanosec()/1000000ULL;
 }
 
 SDL_bool