]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
basic_file.h (__basic_file::fd): New function.
authorPhil Edwards <pme@gcc.gnu.org>
Mon, 17 Dec 2001 17:08:57 +0000 (17:08 +0000)
committerPhil Edwards <pme@gcc.gnu.org>
Mon, 17 Dec 2001 17:08:57 +0000 (17:08 +0000)
2001-12-17  Phil Edwards  <pme@gcc.gnu.org>

* include/bits/basic_file.h (__basic_file::fd):  New function.
* config/io/basic_file_stdio.h (__basic_file::fd):  Define.
* include/bits/std_fstream.h (basic_filebuf::fd):  New function.
* include/bits/fstream.tcc (basic_filebuf::fd):  Define.
* testsuite/27_io/filebuf_members.cc (test_02):  New test.

From-SVN: r48107

libstdc++-v3/ChangeLog
libstdc++-v3/config/io/basic_file_stdio.h
libstdc++-v3/include/bits/basic_file.h
libstdc++-v3/include/bits/fstream.tcc
libstdc++-v3/include/bits/std_fstream.h
libstdc++-v3/testsuite/27_io/filebuf_members.cc

index 79feca47fe38884504e8ff47e4d3812133f977c9..8ef11b77c83df6a7041414462130c13511687e0a 100644 (file)
@@ -1,3 +1,11 @@
+2001-12-17  Phil Edwards  <pme@gcc.gnu.org>
+
+       * include/bits/basic_file.h (__basic_file::fd):  New function.
+       * config/io/basic_file_stdio.h (__basic_file::fd):  Define.
+       * include/bits/std_fstream.h (basic_filebuf::fd):  New function.
+       * include/bits/fstream.tcc (basic_filebuf::fd):  Define.
+       * testsuite/27_io/filebuf_members.cc (test_02):  New test.
+
 2001-12-16  Nathan Sidwell  <nathan@codesourcery.com>
 
        * po/Makefile.am (.po.mo): Use POSIXLY_CORRECT argument ordering.
index edf4d98baa9340d18bce22b174880c12bd2d4677..b83085240d6f41fa45c4156286552ee9653466d4 100644 (file)
@@ -133,6 +133,10 @@ namespace std
     bool 
     __basic_file<_CharT>::is_open() { return _M_cfile != 0; }
   
+  template<typename _CharT>
+    int 
+    __basic_file<_CharT>::fd() { return fileno(_M_cfile) ; }
+  
   template<typename _CharT>
     __basic_file<_CharT>* 
     __basic_file<_CharT>::close()
index aa624eec448e4664711902d0ce5dd6214d4df529..9c0c1d364419442f12d87050a02b4c8db89d4939 100644 (file)
@@ -168,6 +168,9 @@ namespace std
       bool 
       is_open();
 
+      int 
+      fd();
+
       // NB: Must match FILE specific jump table starting here--this
       // means all virtual functions starting with the dtor must match,
       // slot by slot. For glibc-based dystems, this means the _IO_FILE
index fad1682793045a70a470bfae8679602634435d88..7f90f2a383e2df0fd611fb001099d16434d889f0 100644 (file)
@@ -138,6 +138,14 @@ namespace std
        }
     }
 
+  template<typename _CharT, typename _Traits>
+    int
+    basic_filebuf<_CharT, _Traits>::
+    fd()
+    {
+      return _M_file->fd();
+    }
+
   template<typename _CharT, typename _Traits>
     typename basic_filebuf<_CharT, _Traits>::__filebuf_type* 
     basic_filebuf<_CharT, _Traits>::
index 52c62d4b1989f6158b1e0174fbf2097ff90caf50..1a651b725e39338f38e7c64ca6f74e773c597f06 100644 (file)
@@ -97,6 +97,10 @@ namespace std
       basic_filebuf(__c_file_type* __f, ios_base::openmode __mode, 
                    int_type __s = static_cast<int_type>(BUFSIZ));
  
+      // Non-standard member:
+      int
+      fd();
+
       virtual 
       ~basic_filebuf() 
       { 
index 4d61ec10a23d182c1998bb657641511e59eb3b7a..d955ef7ed1f1eea1205d4350e6225ee3e1cba865 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2000 Free Software Foundation, Inc.
+// Copyright (C) 2001 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -24,7 +24,6 @@
 // the non-portable functionality in the libstdc++-v3 IO library
 
 #include <fstream>
-#include <cassert>
 #include <unistd.h>
 #include <fcntl.h>
 #include <testsuite_hooks.h>
@@ -32,9 +31,9 @@
 // verify that std::filebuf doesn't close files that it didn't open
 // when using the following std::filebuf ctor:
 //
-//      std::filebuf(int __fd,
-//                   const char* __unused,
-//                   ios_base::openmode __mode);
+//      std::filebuf(__c_file_type*  __f,
+//                   ios_base::openmode __mode,
+//                   int_type  __s);
 //
 // thanks to "George T. Talbot" <george@moberg.com> for uncovering
 // this bug/situation. 
@@ -78,10 +77,30 @@ test_01()
   return test;
 }
 
+int
+test_02()
+{
+  int first_fd = ::open(name_01, O_RDONLY);
+  VERIFY( first_fd != -1 );
+  FILE* first_file = ::fdopen(first_fd, "r");
+  VERIFY( first_file != NULL );
+  std::filebuf fb (first_file, std::ios_base::in);
+
+  int second_fd = fb.fd();
+
+  bool test = first_fd == second_fd;
+
+#ifdef DEBUG_ASSERT
+  assert(test);
+#endif
+
+  return test;
+}
 
 int
 main()
 {
   test_01();
+  test_02();
   return 0;
 }