X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fsetbuf.c;h=ba910e8983a4b12af55f13f43ea17baad4a92009;hp=6d0201bfb2aa4b9580925f0bef7245618420484a;hb=8f527f87c0b979d9c2598ef5c3394463af288468;hpb=46722468f47c2b77b3987729b4bcf2321cccfd01 diff --git a/ncurses/tinfo/setbuf.c b/ncurses/tinfo/setbuf.c index 6d0201bf..ba910e89 100644 --- a/ncurses/tinfo/setbuf.c +++ b/ncurses/tinfo/setbuf.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,2000 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2007 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -40,7 +40,7 @@ #include -MODULE_ID("$Id: setbuf.c,v 1.7 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: setbuf.c,v 1.13 2007/05/12 19:04:02 tom Exp $") /* * If the output file descriptor is connected to a tty (the typical case) it @@ -98,47 +98,53 @@ MODULE_ID("$Id: setbuf.c,v 1.7 2000/12/10 02:55:08 tom Exp $") * buffer. So we disable this by default (there may yet be a workaround). */ NCURSES_EXPORT(void) -_nc_set_buffer(FILE * ofp, bool buffered) +_nc_set_buffer(FILE *ofp, bool buffered) { /* optional optimization hack -- do before any output to ofp */ #if HAVE_SETVBUF || HAVE_SETBUFFER - unsigned buf_len; - char *buf_ptr; + if (SP->_buffered != buffered) { + unsigned buf_len; + char *buf_ptr; - if (getenv("NCURSES_NO_SETBUF") != 0) - return; + if (getenv("NCURSES_NO_SETBUF") != 0) + return; - fflush(ofp); - if ((SP->_buffered = buffered) != 0) { - buf_len = min(LINES * (COLS + 6), 2800); - if ((buf_ptr = SP->_setbuf) == 0) { - if ((buf_ptr = typeMalloc(char, buf_len)) == NULL) - return; - SP->_setbuf = buf_ptr; - /* Don't try to free this! */ - } + fflush(ofp); +#ifdef __DJGPP__ + setmode(ofp, O_BINARY); +#endif + if (buffered != 0) { + buf_len = min(LINES * (COLS + 6), 2800); + if ((buf_ptr = SP->_setbuf) == 0) { + if ((buf_ptr = typeMalloc(char, buf_len)) == NULL) + return; + SP->_setbuf = buf_ptr; + /* Don't try to free this! */ + } #if !USE_SETBUF_0 - else - return; + else + return; #endif - } else { + } else { #if !USE_SETBUF_0 - return; + return; #else - buf_len = 0; - buf_ptr = 0; + buf_len = 0; + buf_ptr = 0; #endif - } + } #if HAVE_SETVBUF #ifdef SETVBUF_REVERSED /* pre-svr3? */ - (void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF); + (void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF); #else - (void) setvbuf(ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len); + (void) setvbuf(ofp, buf_ptr, buf_len ? _IOFBF : _IOLBF, buf_len); #endif #elif HAVE_SETBUFFER - (void) setbuffer(ofp, buf_ptr, (int) buf_len); + (void) setbuffer(ofp, buf_ptr, (int) buf_len); #endif + SP->_buffered = buffered; + } #endif /* HAVE_SETVBUF || HAVE_SETBUFFER */ }