chiark / gitweb /
Fix typo in changelog entry for 1.6.1
[adns.git] / regress / hfuzz.c
index e09089f6308aac982ceb2f15379cc3441849517a..5d23368e97dea60a94858e65abc3678105e6bc66 100644 (file)
@@ -45,7 +45,7 @@ FILE *Hfopen(const char *path, const char *mode) {
 static int t_argc;
 static char **t_argv;
 
-static FILE *t_stdin;
+static FILE *t_stdin, *stdoutcopy;
 static int t_sys_fd;
 
 static int bail(const char *msg) {
@@ -85,7 +85,8 @@ int Ttestinputfd(void) {
 }
 
 void Texit(int rv) {
-  fprintf(stderr,"**Texit(%d)**\n",rv);
+  fprintf(stdoutcopy,"rc=%d\n",rv);
+  if (ferror(stdoutcopy) || fclose(stdoutcopy)) baile("flush rc msg");
   Tcommonshutdown();
   exit(0);
 }
@@ -96,7 +97,13 @@ int main(int argc, char **argv) {
   if (argc!=1)
     bail("usage: *_fuzz  (no arguments)");
 
+  int stdoutcopyfd= dup(1);
+  if (stdoutcopyfd<0) baile("dup 1 again");
+  stdoutcopy= fdopen(stdoutcopyfd,"w");
+  if (!stdoutcopy) baile("fdopen 1 again");
+
   t_argc = getint(50);
+  if (!t_argc) bail("too few arguments");
   t_argv = calloc(t_argc+1, sizeof(*t_argv));
   for (i=0; i<t_argc; i++) {
     l = getint(1000);
@@ -121,8 +128,6 @@ int main(int argc, char **argv) {
   if (dup2(fileno(t_stdin), 0)) baile("dup2 t_stdin");
   if (fseek(stdin, 0, SEEK_SET)) baile("rewind t_stdin");
 
-  if (dup2(1,2)!=2) baile("redirect stderr to stdout");
-
   int estatus = Hmain(t_argc, t_argv);
   Texit(estatus);
 }