about summary refs log tree commit diff
path: root/libio
diff options
context:
space:
mode:
Diffstat (limited to 'libio')
-rw-r--r--libio/fileops.c4
-rw-r--r--libio/libio.h17
-rw-r--r--libio/stdio.h6
3 files changed, 21 insertions, 6 deletions
diff --git a/libio/fileops.c b/libio/fileops.c
index 1219abea5d..66c2fc514b 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -316,7 +316,7 @@ _IO_do_write (fp, data, to_do)
     fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, to_do) + 1;
   _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
   fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
-  fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+  fp->_IO_write_end = ((fp->_flags & (_IO_UNBUFFERED))
 		       ? fp->_IO_buf_base : fp->_IO_buf_end);
   return count != to_do ? EOF : 0;
 }
@@ -410,7 +410,7 @@ _IO_file_overflow (f, ch)
       f->_IO_write_end = f->_IO_buf_end;
       f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end;
 
-      if (f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+      if (f->_flags & (_IO_UNBUFFERED))
 	f->_IO_write_end = f->_IO_write_ptr;
       f->_flags |= _IO_CURRENTLY_PUTTING;
     }
diff --git a/libio/libio.h b/libio/libio.h
index c3dd640b2f..410794f77c 100644
--- a/libio/libio.h
+++ b/libio/libio.h
@@ -287,10 +287,23 @@ extern int __overflow __P ((_IO_FILE *, int));
 	  && __underflow (_fp) == EOF ? EOF \
 	: *(unsigned char *) (_fp)->_IO_read_ptr)
 
-#define _IO_putc_unlocked(_ch, _fp) \
+#ifdef __GNUC__
+# define _IO_putc_unlocked(_ch, _fp) \
+  (__extension__ \
+   ({ unsigned char _chl = (_ch); \
+      (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end \
+	|| (_chl == '\n' && ((_fp)->_flags & _IO_LINE_BUF))) \
+       ? __overflow (_fp, (unsigned char) _chl) \
+       : (unsigned char) (*(_fp)->_IO_write_ptr++ = _chl)); }))
+#else
+# define _IO_putc_unlocked(_ch, _fp) \
    (((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
     ? __overflow (_fp, (unsigned char) (_ch)) \
-    : (unsigned char) (*(_fp)->_IO_write_ptr++ = (_ch)))
+    : ((unsigned char) (*(_fp)->_IO_write_ptr = (_ch)) == '\n' \
+       && ((_fp)->_flags & _IO_LINE_BUF) \
+       ? __overflow (_fp, (unsigned char) *(_fp)->_IO_write_ptr) \
+       : (unsigned char) (*(_fp)->_IO_write_ptr++)))
+#endif
 
 #define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
 #define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
diff --git a/libio/stdio.h b/libio/stdio.h
index b220e41081..1167d3cf39 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -32,7 +32,9 @@ __BEGIN_DECLS
 # define __need_NULL
 # include <stddef.h>
 
-# define __need___va_list
+# ifndef __USE_XOPEN
+#  define __need___va_list
+# endif
 # include <stdarg.h>
 
 # include <bits/types.h>
@@ -111,7 +113,7 @@ extern void __libc_fatal __P ((__const char *__message))
 #define SEEK_END	2	/* Seek from end of file.  */
 
 
-#ifdef	__USE_SVID
+#if defined __USE_SVID || defined __USE_XOPEN
 /* Default path prefix for `tempnam' and `tmpnam'.  */
 # define P_tmpdir	"/tmp"
 #endif