1/* setlinebuf.c - line-buffer a stdio stream. */ 2 3/* Copyright (C) 1997 Free Software Foundation, Inc. 4 5 This file is part of GNU Bash, the Bourne Again SHell. 6 7 Bash is free software; you can redistribute it and/or modify it under 8 the terms of the GNU General Public License as published by the Free 9 Software Foundation; either version 2, or (at your option) any later 10 version. 11 12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY 13 WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 for more details. 16 17 You should have received a copy of the GNU General Public License along 18 with Bash; see the file COPYING. If not, write to the Free Software 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA */ 20 21#include <config.h> 22 23#include <stdio.h> 24 25#include <xmalloc.h> 26 27#if defined (USING_BASH_MALLOC) 28# define LBUF_BUFSIZE 1008 29#else 30# define LBUF_BUFSIZE BUFSIZ 31#endif 32 33/* Cause STREAM to buffer lines as opposed to characters or blocks. */ 34int 35sh_setlinebuf (stream) 36 FILE *stream; 37{ 38 char *local_linebuf; 39 40#if !defined (HAVE_SETLINEBUF) && !defined (HAVE_SETVBUF) 41 return (0); 42#endif 43 44#if defined (USING_BASH_MALLOC) 45 local_linebuf = (char *)xmalloc (LBUF_BUFSIZE); 46#else 47 local_linebuf = (char *)NULL; 48#endif 49 50#if defined (HAVE_SETVBUF) 51 52# if defined (SETVBUF_REVERSED) 53 return (setvbuf (stream, _IOLBF, local_linebuf, LBUF_BUFSIZE)); 54# else /* !SETVBUF_REVERSED */ 55 return (setvbuf (stream, local_linebuf, _IOLBF, LBUF_BUFSIZE)); 56# endif /* !SETVBUF_REVERSED */ 57# else /* !HAVE_SETVBUF */ 58 59 setlinebuf (stream); 60 return (0); 61 62#endif /* !HAVE_SETVBUF */ 63} 64