This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Allow setbuf(_s, 1)
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: bkoz <bkoz at redhat dot com>
- Date: Tue, 17 Jun 2003 20:58:42 +0200
- Subject: [Patch] Allow setbuf(_s, 1)
Hi,
on any implementation of setbuf semantics, I see no problems
with the below, which simply allows (__s, 1) too, equivalent
to the unbuffered case. This is more friendly to existing code.
Tested x86-linux, ok with everyone?
Paolo.
/////////
2003-06-17 Nathan C. Myers <ncm-nospam@cantrip.org>
Paolo Carlini <pcarlini@unitus.it>
* include/bits/fstream.tcc (setbuf): Allow (__s, 1) too,
simply equivalent to the unbuffered case (0, 0).
diff -urN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
--- libstdc++-v3-orig/include/bits/fstream.tcc 2003-06-11 00:00:42.000000000 +0200
+++ libstdc++-v3/include/bits/fstream.tcc 2003-06-17 20:42:18.000000000 +0200
@@ -429,15 +429,16 @@
{
if (!this->is_open() && __s == 0 && __n == 0)
this->_M_buf_size = 1;
- else if (__s && __n > 1)
+ else if (__s && __n >= 1)
{
// This is implementation-defined behavior, and assumes that
- // an external char_type array of length (__s + __n) exists
- // and has been pre-allocated. If this is not the case,
- // things will quickly blow up. The length argument __n must
- // be greater than 1 because __n - 1 positions will be used
- // for the get and put areas, and 1 position is needed to
- // host the overflow char of a full put area.
+ // an external char_type array of length __n exists and has
+ // been pre-allocated. If this is not the case, things will
+ // quickly blow up. When __n > 1, __n - 1 positions will be
+ // used for the get area, __n - 1 for the put area and 1
+ // position is used to host the overflow char of a full put
+ // area. When __n == 1, as in the unbuffered case above, 1
+ // position is used for the get area, 0 for the put area.
// Step 1: Destroy the current internal array.
_M_destroy_internal_buffer();