shithub: npe

Download patch

ref: 8d59ff3b29f759e550dc421b8cd14d96b83b5001
parent: 16bd4782f88ee554cba6c749a632c1c2296369d3
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue Mar 16 09:18:00 EDT 2021

make "main" function overriding optional

--- a/README.md
+++ b/README.md
@@ -21,4 +21,8 @@
 
 	CFLAGS=$CFLAGS -p -I/sys/include/npe -D__plan9__ -D__${objtype}__
 
+By default npe will override the `main` function with its own
+`threadmain`.  If that behaviour isn't desired, add
+`-D__plan9_keep_main__` to `CFLAGS`.
+
 [General porting guide](http://docs.9front.org/porting).
--- a/include/npe/plan9.h
+++ b/include/npe/plan9.h
@@ -19,11 +19,16 @@
 #endif
 
 /* some programs do not #include <stdlib.h> */
+#ifndef getenv
 #define getenv npe_getenv
 char *npe_getenv(char *s);
+#endif
 
 /* to override "main" with our own threadmain */
+#ifndef __plan9_keep_main__
 #define main npe_main_renamed
+#pragma lib "libthread.a"
+#endif
 
 uvlong npe_nanosec(void);
 void npe_nsleep(uvlong ns);
--- a/libnpe/_main.c
+++ b/libnpe/_main.c
@@ -1,11 +1,12 @@
-#include "plan9.h"
+#include <u.h>
+#include <libc.h>
 #include <thread.h>
 
+int npe_main_renamed(int argc, char *argv[]);
+
 void
-threadmain(int argc, char **argv)
+threadmain(int argc, char *argv[])
 {
-	int npe_main_renamed(int argc, char *argv[]);
-
 	setfcr(getfcr() & ~(FPINVAL|FPOVFL));
 
 	threadexitsall(npe_main_renamed(argc, argv) == 0 ? nil : "error");