+ if (isatty(fileno(stderr))) {
+ output = stderr;
+ } else if ((ch = open("/dev/tty", O_WRONLY)) >= 0) {
+ output = fdopen(ch, "w");
+ } else {
+ fprintf(stderr, "cannot open terminal for output\n");
+ ExitProgram(EXIT_FAILURE);
+ }
+ if (newterm(NULL, output, stdin) == 0) {
+ fprintf(stderr, "Cannot initialize terminal\n");
+ fclose(output);
+ ExitProgram(EXIT_FAILURE);
+ }