From e3ae2174187923d1ad43227458ef9bdaaa1f878e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 19 Nov 2016 18:24:48 +0000 Subject: [PATCH] regress: Allow harness code to wrap main if it wants to 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 --- regress/hnonfuzz.c | 3 +++ regress/hredirect.h.m4 | 3 +++ 2 files changed, 6 insertions(+) diff --git a/regress/hnonfuzz.c b/regress/hnonfuzz.c index e6fa2fa..82c0fcd 100644 --- a/regress/hnonfuzz.c +++ b/regress/hnonfuzz.c @@ -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) { diff --git a/regress/hredirect.h.m4 b/regress/hredirect.h.m4 index 8241e03..a40783c 100644 --- a/regress/hredirect.h.m4 +++ b/regress/hredirect.h.m4 @@ -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 -- 2.30.2