This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] libio: Always use _IO_BUFSIZE for stream buffers [BZ #4099]
- From: Florian Weimer <fweimer at redhat dot com>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Date: Thu, 10 Mar 2016 14:54:22 +0100
- Subject: [PATCH] libio: Always use _IO_BUFSIZE for stream buffers [BZ #4099]
- Authentication-results: sourceware.org; auth=none
Separating this change, as requested by Roland.
Thanks,
Florian
2016-03-08 Florian Weimer <fweimer@redhat.com>
[BZ #4099]
* libio/filedoalloc.c (_IO_file_doallocate): Always use _IO_BUFSIZ
as the buffer size.
diff --git a/libio/filedoalloc.c b/libio/filedoalloc.c
index 4f9d738..74ff79b 100644
--- a/libio/filedoalloc.c
+++ b/libio/filedoalloc.c
@@ -56,8 +56,6 @@
/* Modified for GNU iostream by Per Bothner 1991, 1992. */
#include "libioP.h"
-#include <device-nrs.h>
-#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
@@ -72,36 +70,17 @@ local_isatty (int fd)
}
/* Allocate a file buffer, or switch to unbuffered I/O. Streams for
- TTY devices default to line buffered. */
+ * TTY devices default to line buffered. */
int
_IO_file_doallocate (_IO_FILE *fp)
{
- _IO_size_t size;
- char *p;
- struct stat64 st;
-
- size = _IO_BUFSIZ;
- if (fp->_fileno >= 0 && __builtin_expect (_IO_SYSSTAT (fp, &st), 0) >= 0)
- {
- if (S_ISCHR (st.st_mode))
- {
- /* Possibly a tty. */
- if (
-#ifdef DEV_TTY_P
- DEV_TTY_P (&st) ||
-#endif
- local_isatty (fp->_fileno))
- fp->_flags |= _IO_LINE_BUF;
- }
-#if _IO_HAVE_ST_BLKSIZE
- if (st.st_blksize > 0)
- size = st.st_blksize;
-#endif
- }
- p = malloc (size);
+ /* Switch to line buffering for TTYs. */
+ if (fp->_fileno >= 0 && local_isatty (fp->_fileno))
+ fp->_flags |= _IO_LINE_BUF;
+ char *p = malloc (_IO_BUFSIZ);
if (__glibc_unlikely (p == NULL))
return EOF;
- _IO_setb (fp, p, p + size, 1);
+ _IO_setb (fp, p, p + _IO_BUFSIZ, 1);
return 1;
}
libc_hidden_def (_IO_file_doallocate)
--
2.4.3