diff options
Diffstat (limited to 'lib/sh/setlinebuf.c')
-rw-r--r-- | lib/sh/setlinebuf.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/sh/setlinebuf.c b/lib/sh/setlinebuf.c index 67805ed0..dd76e9fc 100644 --- a/lib/sh/setlinebuf.c +++ b/lib/sh/setlinebuf.c @@ -1,6 +1,6 @@ /* setlinebuf.c - line-buffer a stdio stream. */ -/* Copyright (C) 1997 Free Software Foundation, Inc. +/* Copyright (C) 1997,2022 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -25,31 +25,39 @@ #include <xmalloc.h> #if defined (USING_BASH_MALLOC) -# define LBUF_BUFSIZE 1008 +# define LBUF_BUFSIZE 2016 #else # define LBUF_BUFSIZE BUFSIZ #endif +static char *stdoutbuf = 0; +static char *stderrbuf = 0; + /* Cause STREAM to buffer lines as opposed to characters or blocks. */ int sh_setlinebuf (stream) FILE *stream; { - char *local_linebuf; - #if !defined (HAVE_SETLINEBUF) && !defined (HAVE_SETVBUF) return (0); #endif +#if defined (HAVE_SETVBUF) + char *local_linebuf; + #if defined (USING_BASH_MALLOC) - local_linebuf = (char *)xmalloc (LBUF_BUFSIZE); + if (stream == stdout && stdoutbuf == 0) + local_linebuf = stdoutbuf = (char *)xmalloc (LBUF_BUFSIZE); + else if (stream == stderr && stderrbuf == 0) + local_linebuf = stderrbuf = (char *)xmalloc (LBUF_BUFSIZE); + else + local_linebuf = (char *)NULL; /* let stdio handle it */ #else local_linebuf = (char *)NULL; #endif -#if defined (HAVE_SETVBUF) return (setvbuf (stream, local_linebuf, _IOLBF, LBUF_BUFSIZE)); -# else /* !HAVE_SETVBUF */ +#else /* !HAVE_SETVBUF */ setlinebuf (stream); return (0); |