Browse Source

main.c, fix stdout and stderr redirection and buffering with regard to '-o' and '-p'

in response to a bug report from  Johann Glaser
  "#259 Pipe mode: buffering"
  http://sourceforge.net/p/ngspice/bugs/259/
pre-master-46
h_vogt 12 years ago
committed by rlar
parent
commit
2355bfc0ff
  1. 10
      src/main.c

10
src/main.c

@ -939,8 +939,8 @@ main(int argc, char **argv)
case 'o': /* Output file */
if (optarg) {
/* turn off buffering for stdout */
setbuf(stdout, NULL);
/* switch to line buffering for stdout */
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
sprintf (log_file, "%s", optarg);
orflag = TRUE;
}
@ -950,6 +950,8 @@ main(int argc, char **argv)
iflag = TRUE;
istty = TRUE;
ft_pipemode = TRUE;
/* switch to line buffering for stdout */
setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
break;
case 'q': /* Command completion */
@ -1013,11 +1015,13 @@ main(int argc, char **argv)
}
// oflag = TRUE; /* All further output to -o log file */
#else
/* Connect stdout to file log_file and log stdout */
/* Connect stdout and stderr to file log_file and log stdout */
if (!freopen (log_file, "w", stdout)) {
perror (log_file);
sp_shutdown (EXIT_BAD);
}
dup2(fileno(stdout), fileno(stderr));
setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* enable line buffering */
#endif
} /* orflag */

Loading…
Cancel
Save