chiark / gitweb /
regress: Allow harness code to wrap main if it wants to
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 19 Nov 2016 18:24:48 +0000 (18:24 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Jun 2020 15:13:02 +0000 (16:13 +0100)
The fuzzer is going to want to wrap main().  This is a bit awkward
because everyone defines it their own way (in ways which are obviously
equivalent but which trigger compiler warnings).  Our warnings mean we
have to make sure the comiler sees a declaration.

Luckily the only occurence of main() anywhere in one of the client
programs is (necessarily) the definition of main, which is always
defined to return int.  So we can arrange the expansion to produce
both declaration and definition of Hmain.

Then in hnonfuzz.c we need to declare Hmain.  (Which we can't declare
in the global header file.)  We hope that type errors in main are
unlikely.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
regress/hnonfuzz.c
regress/hredirect.h.m4

index e6fa2fa06deb258ad08a2164fec03c0003adb017..82c0fcd2ebcce37de9d3fba43c0a8ccfd400abd6 100644 (file)
@@ -27,6 +27,9 @@
 
 #include "harness.h"
 
+extern int Hmain(int argc, char **argv);
+int main(int argc, char **argv) { return Hmain(argc, argv); }
+
 FILE *Hfopen(const char *path, const char *mode) { return fopen(path,mode); }
 
 int Ttestinputfd(void) {
index 8241e03897318b07abd846c7e65edeb2c7177d21..a40783c9562ff589aece94d8ddf23b835f50c677 100644 (file)
@@ -36,4 +36,7 @@ m4_define(`hm_specsyscall',`#undef $2
 #define $2 H$2')
 m4_include(`hsyscalls.i4')
 
+m4_dnl only usage site is definition of main
+#define main(C, V) Hmain(C, V); int Hmain(C, V)
+
 #endif