This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Improve the fix for libstdc++/13731


Hi,

the below brings some stylistic consistency betweem xwrite and
xwritev and avoids recursion (which I don't like in this area)

Regtested x86-linux (+ some additional tests with FIFOs)

Paolo.

//////////////


2004-02-17  Paolo Carlini  <pcarlini@suse.de>

	* config/io/basic_file_stdio.cc (__gnu_internal::xwritev):
	Rewrite, avoiding recursion.
	(__gnu_internal::xwrite): Minor tweaks.
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 12 19:24:07 2004
--- libstdc++-v3/config/io/basic_file_stdio.cc	Tue Feb 17 23:12:56 2004
*************** namespace __gnu_internal
*** 111,126 ****
    xwrite(int __fd, const char* __s, std::streamsize __n)
    {
      std::streamsize __nleft = __n;
!     while (__nleft > 0)
        {
  	const std::streamsize __ret = write(__fd, __s, __nleft);
  	if (__ret == -1L && errno == EINTR)
  	  continue;
! 	else if (__ret == -1L)
  	  break;
  	__nleft -= __ret;
  	__s += __ret;
        }
      return __n - __nleft;
    }
  
--- 111,132 ----
    xwrite(int __fd, const char* __s, std::streamsize __n)
    {
      std::streamsize __nleft = __n;
! 
!     for (;;)
        {
  	const std::streamsize __ret = write(__fd, __s, __nleft);
  	if (__ret == -1L && errno == EINTR)
  	  continue;
! 	if (__ret == -1L)
  	  break;
+ 
  	__nleft -= __ret;
+ 	if (__nleft == 0)
+ 	  break;
+ 
  	__s += __ret;
        }
+ 
      return __n - __nleft;
    }
  
*************** namespace __gnu_internal
*** 130,162 ****
    xwritev(int __fd, const char* __s1, std::streamsize __n1,
  	  const char* __s2, std::streamsize __n2)
    {
!     std::streamsize __ret;
  
      struct iovec __iov[2];
-     __iov[0].iov_base = const_cast<char*>(__s1);
-     __iov[0].iov_len = __n1;
      __iov[1].iov_base = const_cast<char*>(__s2);
      __iov[1].iov_len = __n2;
  
!     do
!       __ret = writev(__fd, __iov, 2);
!     while (__ret == -1L && errno == EINTR);
! 
!     if (__ret == -1L)
!       __ret = 0;
!     else if (__ret < __n1 + __n2)
        {
! 	if (__ret >= __n1)
  	  {
! 	    const std::streamsize __off = __ret - __n1;
! 	    __ret += xwrite(__fd, __s2 + __off, __n2 - __off);
  	  }
! 	else
! 	  __ret += xwritev(__fd, __s1 + __ret, __n1 - __ret,
! 			   __s2, __n2);
        }
  
!     return __ret;
    }
  #endif
  } // namespace __gnu_internal
--- 136,175 ----
    xwritev(int __fd, const char* __s1, std::streamsize __n1,
  	  const char* __s2, std::streamsize __n2)
    {
!     std::streamsize __nleft = __n1 + __n2;
!     std::streamsize __n1_left = __n1;
  
      struct iovec __iov[2];
      __iov[1].iov_base = const_cast<char*>(__s2);
      __iov[1].iov_len = __n2;
  
!     for (;;)
        {
! 	__iov[0].iov_base = const_cast<char*>(__s1);
! 	__iov[0].iov_len = __n1_left;
! 
! 	const std::streamsize __ret = writev(__fd, __iov, 2);
! 	if (__ret == -1L && errno == EINTR)
! 	  continue;
! 	if (__ret == -1L)
! 	  break;
! 
! 	__nleft -= __ret;
! 	if (__nleft == 0)
! 	  break;
! 
! 	const std::streamsize __off = __ret - __n1_left;
! 	if (__off >= 0)
  	  {
! 	    __nleft -= xwrite(__fd, __s2 + __off, __n2 - __off);
! 	    break;
  	  }
! 	
! 	__s1 += __ret;
! 	__n1_left -= __ret;
        }
  
!     return __n1 + __n2 - __nleft;
    }
  #endif
  } // namespace __gnu_internal

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]