This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Fix first part of libstdc++/13731
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Cc: rittle at labs dot mot dot com
- Date: Wed, 11 Feb 2004 19:05:59 +0100
- Subject: [Patch] Fix first part of libstdc++/13731
Hi everyone, hi Loren,
this is the first part, dealing with write (the second part will affect
writev, and therefore xsputn).
I briefly recall that this work is needed because, when pipes are involved,
and n > PIPE_BUF, partial but succesful writes are possible: therefore we
must iterate 'til completion or error.
I would like you all to stress test in mainline this first part for a few
days, in the meanwhile work on the second part, which is less
straighforward,
but still manageable since our writev are always of 1 or 2 buffers, not
fully general.
Tested x86-linux.
Paolo.
////////////////
2004-02-11 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/13731 (first part: write)
* config/io/basic_file_stdio.h (__basic_file<char>::xwrite):
New, declare.
* config/io/basic_file_stdio.cc (__basic_file<char>::xwrite):
Define it: a wrapper around write() handling partial write.
(__basic_file<char>::xsputn): Use it.
(__basic_file<char>::xsputn_2): Likewise.
diff -prN libstdc++-v3-orig/config/io/basic_file_stdio.cc libstdc++-v3/config/io/basic_file_stdio.cc
*** libstdc++-v3-orig/config/io/basic_file_stdio.cc Thu Feb 5 21:11:32 2004
--- libstdc++-v3/config/io/basic_file_stdio.cc Wed Feb 11 18:52:16 2004
*************** namespace std
*** 200,215 ****
while (__ret == -1L && errno == EINTR);
return __ret;
}
!
! streamsize
! __basic_file<char>::xsputn(const char* __s, streamsize __n)
{
! streamsize __ret;
! do
! __ret = write(this->fd(), __s, __n);
! while (__ret == -1L && errno == EINTR);
! return __ret;
}
streamsize
__basic_file<char>::xsputn_2(const char* __s1, streamsize __n1,
--- 200,227 ----
while (__ret == -1L && errno == EINTR);
return __ret;
}
!
! // Wrapper handling partial write.
! streamsize
! __basic_file<char>::xwrite(const char* __s, streamsize __n)
{
! streamsize __nleft = __n;
! while (__nleft > 0)
! {
! const streamsize __ret = write(this->fd(), __s, __nleft);
! if (__ret == -1L && errno == EINTR)
! continue;
! else if (__ret == -1L)
! break;
! __nleft -= __ret;
! __s += __ret;
! }
! return __n - __nleft;
}
+
+ streamsize
+ __basic_file<char>::xsputn(const char* __s, streamsize __n)
+ { return __basic_file<char>::xwrite(__s, __n); }
streamsize
__basic_file<char>::xsputn_2(const char* __s1, streamsize __n1,
*************** namespace std
*** 228,246 ****
while (__ret == -1L && errno == EINTR);
#else
if (__n1)
! do
! __ret = write(this->fd(), __s1, __n1);
! while (__ret == -1L && errno == EINTR);
if (__ret == __n1)
! {
! do
! __ret = write(this->fd(), __s2, __n2);
! while (__ret == -1L && errno == EINTR);
!
! if (__ret != -1L)
! __ret += __n1;
! }
#endif
return __ret;
}
--- 240,249 ----
while (__ret == -1L && errno == EINTR);
#else
if (__n1)
! __ret = __basic_file<char>::xwrite(__s1, __n1);
if (__ret == __n1)
! __ret += __basic_file<char>::xwrite(__s2, __n2);
#endif
return __ret;
}
diff -prN libstdc++-v3-orig/config/io/basic_file_stdio.h libstdc++-v3/config/io/basic_file_stdio.h
*** libstdc++-v3-orig/config/io/basic_file_stdio.h Thu Feb 5 06:24:17 2004
--- libstdc++-v3/config/io/basic_file_stdio.h Wed Feb 11 17:59:49 2004
*************** namespace std
*** 84,89 ****
--- 84,92 ----
~__basic_file();
streamsize
+ xwrite(const char* __s, streamsize __n);
+
+ streamsize
xsputn(const char* __s, streamsize __n);
streamsize