diff options
author | Chet Ramey <chet.ramey@case.edu> | 2022-08-26 11:08:51 -0400 |
---|---|---|
committer | Chet Ramey <chet.ramey@case.edu> | 2022-08-26 11:08:51 -0400 |
commit | b3afafd86d27d61601cf380e1065d9170862fd10 (patch) | |
tree | abaef1c96fadb1cbdab381dbe945b1373dbde51f /lib/sh/setlinebuf.c | |
parent | f36c8c8ecd155104931198d898733bdb961bc27f (diff) | |
download | bash-5.2-rc3.tar.gz |
Bash-5.2-rc3 releasebash-5.2-rc3
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); |