]> gcc.gnu.org Git - gcc.git/blobdiff - libstdc++-v3/config/c_io_stdio.cc
char_traits.cc: Move to ...
[gcc.git] / libstdc++-v3 / config / c_io_stdio.cc
index ddcdff4b6761e79233005e22bbf332ff646a2dcf..c9ac7705c5562e81c0106261271d8154cea54715 100644 (file)
@@ -1,6 +1,6 @@
 // Wrapper of C-language FILE struct -*- C++ -*-
 
-// Copyright (C) 2000 Free Software Foundation, Inc.
+// Copyright (C) 2000, 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
@@ -32,6 +32,7 @@
 //
 
 #include <bits/basic_file.h>
+#include <unistd.h>
 
 namespace std {
 
@@ -94,14 +95,17 @@ namespace std {
 
       _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
 
-      if (!this->is_open())
+      int __dupfd = dup(__fd);
+
+      if (__dupfd != -1 && !this->is_open())
        {
-         if ((_M_cfile = fdopen(__fd, __c_mode)))
+         if ((_M_cfile = fdopen(__dupfd, __c_mode)))
            {
-             _M_fileno = __fd;
+             _M_fileno = __dupfd;
              __ret = this;
            }
        }
+
       return __ret;
     }
   
@@ -160,13 +164,13 @@ namespace std {
     streamoff
     __basic_file<_CharT>::seekoff(streamoff __off, ios_base::seekdir __way, 
                                  ios_base::openmode /*__mode*/)
-   { return fseek(_M_cfile, __off, __way); }
+    { fseek(_M_cfile, __off, __way); return ftell(_M_cfile); }
 
   template<typename _CharT>
     streamoff
     __basic_file<_CharT>::seekpos(streamoff __pos, 
                                  ios_base::openmode /*__mode*/)
-   { return fseek(_M_cfile, __pos, ios_base::beg); }
+    { fseek(_M_cfile, __pos, ios_base::beg); return ftell(_M_cfile); }
 
   template<typename _CharT>
     int 
@@ -225,7 +229,10 @@ namespace std {
   template<typename _CharT>
     streamoff
     __basic_file<_CharT>::sys_seek(streamoff __pos, ios_base::seekdir __way)
-   { return fseek(_M_cfile, __pos, __way); }
+    { 
+      fseek(_M_cfile, __pos, __way); 
+      return ftell(_M_cfile); 
+    }
   
   // NB: Unused.
   template<typename _CharT>
This page took 0.034338 seconds and 5 git commands to generate.