diff options
Diffstat (limited to 'lib/sh/setlinebuf.c')
-rw-r--r-- | lib/sh/setlinebuf.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/lib/sh/setlinebuf.c b/lib/sh/setlinebuf.c index 05f95793..fb097de4 100644 --- a/lib/sh/setlinebuf.c +++ b/lib/sh/setlinebuf.c @@ -20,22 +20,44 @@ #include <config.h> -#if !defined (HAVE_SETLINEBUF) - #include <stdio.h> +extern char *xmalloc(); + +#if defined (USING_BASH_MALLOC) +# define LBUF_BUFSIZE 1008 +#else +# define LBUF_BUFSIZE BUFSIZ +#endif + /* Cause STREAM to buffer lines as opposed to characters or blocks. */ int -setlinebuf (stream) +sh_setlinebuf (stream) FILE *stream; { -#if defined (_IOLBF) + char *local_linebuf; + +#if !defined (HAVE_SETLINEBUF) && !defined (HAVE_SETVBUF) + return (0); +#endif + +#if defined (USING_BASH_MALLOC) + local_linebuf = xmalloc (LBUF_BUFSIZE); +#else + local_linebuf = (char *)NULL; +#endif + +#if defined (HAVE_SETVBUF) + # if defined (SETVBUF_REVERSED) - setvbuf (stream, _IOLBF, (char *)NULL, BUFSIZ); + return (setvbuf (stream, _IOLBF, local_linebuf, LBUF_BUFSIZE)); # else /* !SETVBUF_REVERSED */ - setvbuf (stream, (char *)NULL, _IOLBF, BUFSIZ); + return (setvbuf (stream, local_linebuf, _IOLBF, LBUF_BUFSIZE)); # endif /* !SETVBUF_REVERSED */ -#endif /* _IOLBF */ +# else /* !HAVE_SETVBUF */ + + setlinebuf (stream)); return (0); + +#endif /* !HAVE_SETVBUF */ } -#endif /* !HAVE_SETLINEBUF */ |