Printing of event log

I’ve found out that even setting all these verbose settings to 0 many things are still printed out by Geant4. Therefore, in my own code I decided to just disable stdout output temporarily when I don’t want the output. Below are the functions I use to do that. I hope you find them useful.

static int outfd = STDOUT_FILENO;

void disable_stdout()
{
	FILE* tmp = fopen("/dev/null", "a+");

	fflush(stdout);

	outfd = dup(STDOUT_FILENO);

	if (outfd == -1 || dup2(fileno(tmp), STDOUT_FILENO) == -1)
		errx(1, "failed to disable stdout");

	fclose(tmp);
}

void enable_stdout()
{
	fflush(stdout);

	if (dup2(outfd, STDOUT_FILENO) == -1)
		errx(1, "failed to enable stdout");

	close(outfd);
}