This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


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

[patch] config/c_io_libio.cc - __basic_file::open(...)


The following prog bails because we are not closing the __fd for
the opened file, since _IO_file_attach() sets _IO_DELETE_DONT_CLOSE
in _flags. the patch further below unsets _IO_DELETE_DONT_CLOSE when
__basic_file::open() is used.

NOTE: I haven't been able to test this -- libstdc++-v3 is causing
an ICE in gcc-20000619 -- but I believe it will do the right thing.

  Brent

#include <fstream>
#include <cassert>

int
main()
{
  const int more_than_max_open_files = 8200;
  const char* some_file_on_your_system = "/etc/resolv.conf";
  
  for(int i = 0;++i < more_than_max_open_files){
    std::ifstream ifs(some_file_on_your_system);
    assert(ifs);
  }
  
  return 0;
}


Index: c_io_libio.cc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/config/c_io_libio.cc,v
retrieving revision 1.4
diff -c -p -3 -r1.4 c_io_libio.cc
*** c_io_libio.cc	2000/07/02 02:15:26	1.4
--- c_io_libio.cc	2000/07/03 03:43:46
*************** namespace std {
*** 152,158 ****
  #if _G_HAVE_IO_FILE_OPEN
  	__c_file_type* __f;
  	__f = _IO_file_open(this, __name, __p_mode, __prot, __rw_mode, 0);
! 	__retval = __f ? this: NULL;
  #else
  	int __fd = ::open(__name, __p_mode, __prot);
  	if (__fd >= 0)
--- 152,159 ----
  #if _G_HAVE_IO_FILE_OPEN
  	__c_file_type* __f;
  	__f = _IO_file_open(this, __name, __p_mode, __prot, __rw_mode, 0);
! 	this->_flags &= ~_IO_DELETE_DONT_CLOSE; // make sure this isn't set -=db=-
!   __retval = __f ? this: NULL;
  #else
  	int __fd = ::open(__name, __p_mode, __prot);
  	if (__fd >= 0)


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