[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "save" to and "load" from file descriptor
From: |
John W. Eaton |
Subject: |
Re: "save" to and "load" from file descriptor |
Date: |
Thu, 14 Jun 2007 16:15:10 -0400 |
On 14-Jun-2007, Michael Goffioul wrote:
| On 6/14/07, John W. Eaton <address@hidden> wrote:
| > Does Cygwin also accept "rb" and "wb"? If not, then we need an ifdef
| > around the following change.
|
| I don't know about cygwin, but I wonder if the proposed change is enough.
| If I look at popen in src/file-io.cc, it uses octave_iprocstream::create; and
if
| I look at octave_iprocstream in src/oct-prcstrm.cc, it calls directly ::popen
| (with an additional #define to _popen for MSVC). Perhaps it would be better
| to wrap the syscall popen into some octave_popen, taking care of the binary
| more and the underscore prepending, and use it in octave's code.
OK, how about the following change then? It avoids the Cygwin issue.
jwe
src/ChangeLog:
2007-06-14 John W. Eaton <address@hidden>
* sysdep.cc (octave_popen, octave_pclose): New functions.
* sysdep.h: Provide decls.
* oct-procbuf.cc (procbuf::open): Use octave_popen.
(procbuf::close): Use octave_pclose.
* oct-prcstrm.cc (octave_oprocstream::octave_oprocstream,
octave_iprocstream::ictave_oprocstream): Likewise.
Index: src/oct-prcstrm.cc
===================================================================
RCS file: /cvs/octave/src/oct-prcstrm.cc,v
retrieving revision 1.16
diff -u -u -r1.16 oct-prcstrm.cc
--- src/oct-prcstrm.cc 26 Oct 2006 14:51:37 -0000 1.16
+++ src/oct-prcstrm.cc 14 Jun 2007 20:13:51 -0000
@@ -28,20 +28,7 @@
#include <cstdio>
#include "oct-prcstrm.h"
-
-// FIXME -- perhaps this should be handled more globally. See also
-// oct-procbuf.cc.
-
-#if defined (_MSC_VER)
-#define popen _popen
-#define pclose _pclose
-#endif
-
-static int
-cxx_pclose (FILE *f)
-{
- return ::pclose (f);
-}
+#include "sysdep.h"
octave_stream
octave_iprocstream::create (const std::string& n, std::ios::openmode arg_md,
@@ -53,8 +40,8 @@
octave_iprocstream::octave_iprocstream (const std::string& n,
std::ios::openmode arg_md,
oct_mach_info::float_format ff)
- : octave_stdiostream (n, ::popen (n.c_str (), "r"),
- arg_md, ff, cxx_pclose)
+ : octave_stdiostream (n, octave_popen (n.c_str (), "r"),
+ arg_md, ff, octave_pclose)
{
}
@@ -73,8 +60,8 @@
octave_oprocstream::octave_oprocstream (const std::string& n,
std::ios::openmode arg_md,
oct_mach_info::float_format ff)
- : octave_stdiostream (n, ::popen (n.c_str (), "w"),
- arg_md, ff, cxx_pclose)
+ : octave_stdiostream (n, octave_popen (n.c_str (), "w"),
+ arg_md, ff, octave_pclose)
{
}
Index: src/oct-procbuf.cc
===================================================================
RCS file: /cvs/octave/src/oct-procbuf.cc,v
retrieving revision 1.34
diff -u -u -r1.34 oct-procbuf.cc
--- src/oct-procbuf.cc 14 Jun 2007 18:23:02 -0000 1.34
+++ src/oct-procbuf.cc 14 Jun 2007 20:13:51 -0000
@@ -40,6 +40,7 @@
#include "lo-utils.h"
#include "oct-procbuf.h"
#include "oct-syscalls.h"
+#include "sysdep.h"
#include "variables.h"
#include "defun.h"
@@ -51,17 +52,6 @@
static octave_procbuf *octave_procbuf_list = 0;
-// FIXME -- perhaps this should be handled more globally. See also
-// oct-prcstrm.cc.
-
-#if defined (__CYGWIN__)
-#define W32POPEN popen
-#define W32PCLOSE pclose
-#elif defined (__MINGW32__) || defined (_MSC_VER)
-#define W32POPEN _popen
-#define W32PCLOSE _pclose
-#endif
-
#ifndef BUFSIZ
#define BUFSIZ 1024
#endif
@@ -74,7 +64,7 @@
if (is_open ())
return 0;
- f = ::W32POPEN (command, (mode & std::ios::in) ? "rb" : "wb");
+ f = octave_popen (command, (mode & std::ios::in) ? "r" : "w");
if (! f)
return 0;
@@ -179,7 +169,7 @@
if (f)
{
- wstatus = ::W32PCLOSE (f);
+ wstatus = octave_pclose (f);
f = 0;
}
Index: src/sysdep.cc
===================================================================
RCS file: /cvs/octave/src/sysdep.cc,v
retrieving revision 1.129
diff -u -u -r1.129 sysdep.cc
--- src/sysdep.cc 5 Jun 2007 05:50:10 -0000 1.129
+++ src/sysdep.cc 14 Jun 2007 20:13:51 -0000
@@ -516,6 +516,36 @@
curr_on = on;
}
+FILE *
+octave_popen (const char *command, const char *mode)
+{
+#if defined (__MINGW32__) || defined (_MSC_VER)
+ if (mode && mode[0] && ! mode[1])
+ {
+ char tmode[3];
+ tmode[0] = mode[0];
+ tmode[1] = 'b';
+ tmode[2] = 0;
+
+ return _popen (command, tmode);
+ }
+ else
+ return _popen (command, mode);
+#else
+ return popen (command, mode);
+#endif
+}
+
+int
+octave_pclose (FILE *f)
+{
+#if defined (__MINGW32__) || defined (_MSC_VER)
+ return _pclose (f);
+#else
+ return pclose (f);
+#endif
+}
+
// Read one character from the terminal.
int
Index: src/sysdep.h
===================================================================
RCS file: /cvs/octave/src/sysdep.h,v
retrieving revision 1.33
diff -u -u -r1.33 sysdep.h
--- src/sysdep.h 6 Jun 2007 05:18:54 -0000 1.33
+++ src/sysdep.h 14 Jun 2007 20:13:51 -0000
@@ -24,6 +24,8 @@
#if !defined (octave_sysdep_h)
#define octave_sysdep_h 1
+#include <cstdio>
+
#include <string>
#include "lo-ieee.h"
@@ -35,6 +37,9 @@
extern void raw_mode (bool, bool wait = true);
+extern FILE *octave_popen (const char *command, const char *mode);
+extern int octave_pclose (FILE *f);
+
extern OCTINTERP_API int octave_kbhit (bool wait = true);
extern void w32_set_quiet_shutdown (void);
- Re: "save" to and "load" from file descriptor, David Bateman, 2007/06/12
- Re: "save" to and "load" from file descriptor, Thomas Geiger, 2007/06/12
- Re: "save" to and "load" from file descriptor, John W. Eaton, 2007/06/12
- Re: "save" to and "load" from file descriptor, Olaf Till, 2007/06/13
- Re: "save" to and "load" from file descriptor, John W. Eaton, 2007/06/13
- RE: "save" to and "load" from file descriptor, Aaron Birenboim, 2007/06/13
- Re: "save" to and "load" from file descriptor, Michael Goffioul, 2007/06/14
- Re: "save" to and "load" from file descriptor, John W. Eaton, 2007/06/14
- Re: "save" to and "load" from file descriptor, Michael Goffioul, 2007/06/14
- Re: "save" to and "load" from file descriptor,
John W. Eaton <=
- Re: "save" to and "load" from file descriptor, Michael Goffioul, 2007/06/15
- Re: "save" to and "load" from file descriptor, Olaf Till, 2007/06/14
- Re: "save" to and "load" from file descriptor, Olaf Till, 2007/06/16