changeset 3631:0b6b55fd0a5c

[project @ 2000-03-23 09:16:36 by jwe]
author jwe
date Thu, 23 Mar 2000 09:16:37 +0000
parents 8fbe6931e709
children 95d7c4b2b2e8
files src/ChangeLog src/oct-procbuf.cc src/oct-procbuf.h
diffstat 3 files changed, 33 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,8 @@
 2000-03-23  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* oct-procbuf.h, oct-procbuf.cc (octave_procbuf):
+	Derive from c_file_ptr_buf instead of filebuf.
+
 	* oct-stream.cc (octave_base_stream::printf): Use octave_format
 	instead of ostream::form.  Return number of characters written.
 
--- a/src/oct-procbuf.cc
+++ b/src/oct-procbuf.cc
@@ -54,11 +54,6 @@
 
 // This class is based on the procbuf class from libg++, written by
 // Per Bothner, Copyright (C) 1993 Free Software Foundation.
-//
-// It should work with the filebuf class from libg++, but it might not
-// work with others since it depends on being able to get at the
-// underlying file descriptor with filebuf::fd(), which is not
-// standard.
 
 static octave_procbuf *octave_procbuf_list = 0;
 
@@ -104,7 +99,7 @@
 
       while (octave_procbuf_list)
 	{
-	  ::close (octave_procbuf_list->fd ());
+	  ::fclose (octave_procbuf_list->f);
 	  octave_procbuf_list = octave_procbuf_list->next;
 	}
 
@@ -124,7 +119,9 @@
       return 0;
     }
 
-  attach (parent_end);
+  f = ::fdopen (parent_end, (mode & std::ios::in) ? "w" : "r");
+
+  open_p = true;
 
   next = octave_procbuf_list;
   octave_procbuf_list = this;
@@ -138,8 +135,8 @@
 #endif
 }
 
-int
-octave_procbuf::sys_close (void)
+octave_procbuf *
+octave_procbuf::close (void)
 {
 #if defined (HAVE_SYS_WAIT_H)
 
@@ -159,27 +156,24 @@
 	}
     }
 
-  if (status < 0 || ::close (fd ()) < 0)
-    return -1;
-
-  {
-    using namespace std;
+  if (status == 0 && ::fclose (f) == 0)
+    {
+      using namespace std;
 
-    do
-      {
-	wait_pid = ::waitpid (proc_pid, &wstatus, 0);
-      }
-    while (wait_pid == -1 && errno == EINTR);
-  }
+      do
+	{
+	  wait_pid = ::waitpid (proc_pid, &wstatus, 0);
+	}
+      while (wait_pid == -1 && errno == EINTR);
+    }
 
-  if (wait_pid == -1)
-    return -1;
+  open_p = false;
 
-  return wstatus;
+  return this;
 
 #else
 
-  return -1;
+  return 0;
 
 #endif
 }
--- a/src/oct-procbuf.h
+++ b/src/oct-procbuf.h
@@ -26,41 +26,43 @@
 #if !defined (octave_octave_procbuf_h)
 #define octave_octave_procbuf_h 1
 
-#include <fstream>
-
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
 
+#include "c-file-ptr-stream.h"
+
 class
-octave_procbuf : public std::filebuf
+octave_procbuf : public c_file_ptr_buf
 {
 public:
 
   octave_procbuf (void)
-    : std::filebuf (), wstatus (-1), proc_pid (-1), next (0) { }
+    : c_file_ptr_buf (0), wstatus (-1), open_p (false), proc_pid (-1),
+      next (0) { }
 
   octave_procbuf (const char *command, int mode)
-    : std::filebuf (), wstatus (-1), proc_pid (-1), next (0)
-  { open (command, mode); }
+    : c_file_ptr_buf (0), wstatus (-1), open_p (false), proc_pid (-1),
+      next (0) { open (command, mode); }
 
   ~octave_procbuf (void) { close (); }
 
   octave_procbuf *open (const char *command, int mode);
 
-  octave_procbuf *close (void)
-    { return static_cast<octave_procbuf *> (std::filebuf::close ()); }
-
-  virtual int sys_close (void);
+  octave_procbuf *close (void);
 
   int wait_status (void) const { return wstatus; }
 
+  bool is_open (void) const { return open_p; }
+
   pid_t pid (void) { return proc_pid; }
 
 protected:
 
   int wstatus;
 
+  bool open_p;
+
   pid_t proc_pid;
 
   octave_procbuf *next;