/****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2009,2010 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 *
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ * and: Juergen Pfeifer 2008 *
****************************************************************************/
-
-
/*
** setbuf.c
**
#include <curses.priv.h>
-MODULE_ID("$Id: setbuf.c,v 1.5 1999/02/27 20:00:15 tom Exp $")
+MODULE_ID("$Id: setbuf.c,v 1.16 2010/08/28 21:08:31 tom Exp $")
/*
* If the output file descriptor is connected to a tty (the typical case) it
* do indeed get confused by changing setbuf on/off, and will overrun the
* buffer. So we disable this by default (there may yet be a workaround).
*/
-void _nc_set_buffer(FILE *ofp, bool buffered)
+NCURSES_EXPORT(void)
+NCURSES_SP_NAME(_nc_set_buffer) (NCURSES_SP_DCLx FILE *ofp, bool buffered)
{
- /* optional optimization hack -- do before any output to ofp */
+ int Cols;
+ int Lines;
+
+ if (0 == SP_PARM)
+ return;
+
+ Cols = *(ptrCols(SP_PARM));
+ Lines = *(ptrLines(SP_PARM));
+
+ /* optional optimization hack -- do before any output to ofp */
#if HAVE_SETVBUF || HAVE_SETBUFFER
+ if (SP_PARM->_buffered != buffered) {
unsigned buf_len;
char *buf_ptr;
if (getenv("NCURSES_NO_SETBUF") != 0)
- return;
+ 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! */
- }
+#ifdef __DJGPP__
+ setmode(ofp, O_BINARY);
+#endif
+ if (buffered != 0) {
+ buf_len = (unsigned) min(Lines * (Cols + 6), 2800);
+ if ((buf_ptr = SP_PARM->_setbuf) == 0) {
+ if ((buf_ptr = typeMalloc(char, buf_len)) == NULL)
+ return;
+ SP_PARM->_setbuf = buf_ptr;
+ /* Don't try to free this! */
+ }
#if !USE_SETBUF_0
- else return;
+ else
+ return;
#endif
} 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? */
+#ifdef SETVBUF_REVERSED /* pre-svr3? */
(void) setvbuf(ofp, buf_ptr, buf_len, buf_len ? _IOFBF : _IOLBF);
#else
(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_PARM->_buffered = buffered;
+ }
#endif /* HAVE_SETVBUF || HAVE_SETBUFFER */
}
+
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(void)
+_nc_set_buffer(FILE *ofp, bool buffered)
+{
+ NCURSES_SP_NAME(_nc_set_buffer) (CURRENT_SCREEN, ofp, buffered);
+}
+#endif