Skip to content

Instantly share code, notes, and snippets.

@tene
Created March 28, 2010 03:51
Show Gist options
  • Save tene/346555 to your computer and use it in GitHub Desktop.
Save tene/346555 to your computer and use it in GitHub Desktop.
NCURSES_EXPORT(WINDOW *)
initscr(void)
{
WINDOW *result;
NCURSES_CONST char *name;
START_TRACE();
T((T_CALLED("initscr()")));
_nc_init_pthreads();
_nc_lock_global(curses);
/* Portable applications must not call initscr() more than once */
if (!_nc_globals.init_screen) {
_nc_globals.init_screen = TRUE;
if ((name = getenv("TERM")) == 0
|| *name == '\0')
name = "unknown";
#ifdef __CYGWIN__
/*
* 2002/9/21
* Work around a bug in Cygwin. Full-screen subprocesses run from
* bash, in turn spawned from another full-screen process, will dump
* core when attempting to write to stdout. Opening /dev/tty
* explicitly seems to fix the problem.
*/
if (isatty(fileno(stdout))) {
FILE *fp = fopen("/dev/tty", "w");
if (fp != 0 && isatty(fileno(fp))) {
fclose(stdout);
dup2(fileno(fp), STDOUT_FILENO);
stdout = fdopen(STDOUT_FILENO, "w");
}
}
#endif
if (newterm(name, stdout, stdin) == 0) {
fprintf(stderr, "Error opening terminal: %s.\n", name);
exit(EXIT_FAILURE);
}
/* def_shell_mode - done in newterm/_nc_setupscreen */
def_prog_mode();
}
result = stdscr;
_nc_unlock_global(curses);
returnWin(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment