diff src/c-file-ptr-stream.h @ 3716:08fe5f74c7d4

[project @ 2000-09-07 04:59:03 by jwe]
author jwe
date Thu, 07 Sep 2000 04:59:04 +0000
parents 25e84fcef38a
children 13905c3a24af
line wrap: on
line diff
--- a/src/c-file-ptr-stream.h
+++ b/src/c-file-ptr-stream.h
@@ -31,13 +31,16 @@
 #include <stdio.h>
 
 class
-c_file_ptr_buf : public std::streambuf
+c_file_ptr_buf : public std::filebuf
 {
 public:
 
+  typedef int (*close_fcn) (FILE *);
+
   FILE* stdiofile (void) const { return f; }
 
-  c_file_ptr_buf (FILE *f_arg) : std::streambuf (), f (f_arg) { }
+  c_file_ptr_buf (FILE *f_arg, close_fcn cf_arg = ::fclose)
+    : std::filebuf (f_arg ? fileno (f_arg) : -1), f (f_arg), cf (cf_arg) { }
 
   ~c_file_ptr_buf (void);
 
@@ -68,6 +71,8 @@
 protected:
 
   FILE *f;
+
+  close_fcn cf;
 };
 
 class
@@ -75,8 +80,8 @@
 {
 public:
 
-  i_c_file_ptr_stream (FILE* f)
-    : std::istream (), buf (new c_file_ptr_buf (f)) { init (buf); }
+  i_c_file_ptr_stream (FILE* f, c_file_ptr_buf::close_fcn cf = ::fclose)
+    : std::istream (), buf (new c_file_ptr_buf (f, cf)) { init (buf); }
 
   ~i_c_file_ptr_stream (void) { delete buf; buf = 0; }
 
@@ -94,8 +99,8 @@
 {
 public:
 
-  o_c_file_ptr_stream (FILE* f)
-    : std::ostream (), buf (new c_file_ptr_buf (f)) { init (buf); }
+  o_c_file_ptr_stream (FILE* f, c_file_ptr_buf::close_fcn cf = ::fclose)
+    : std::ostream (), buf (new c_file_ptr_buf (f, cf)) { init (buf); }
 
   ~o_c_file_ptr_stream (void) { delete buf; buf = 0; }