help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unable to use fopen in 2.9.2 and 2.9.3


From: John W. Eaton
Subject: Re: Unable to use fopen in 2.9.2 and 2.9.3
Date: Mon, 23 May 2005 22:20:56 -0400

On 23-May-2005, Keith Goodman wrote:

| On 5/23/05, John W. Eaton <address@hidden> wrote:
| > Are you in a directory that has a subdirectory called "test"?
| 
| I may have been since I can reproduce the error if I am. The only test
| directory I have is in the octave cvs. But my file is not really
| called test. And I can also reproduce the error if the file does not
| exist:
| 
| >> [fid,msg]=fopen('sdklfjwperot3049t','r')
| error: fopen: internal error
| 
| That's a much more serious error. (Don't tell me the octave cvs has a
| sdklfjwperot3049t directory.)

OK, I see a reasonable way to fix the problem without too much
effort.  Please try the following patch.  With it, I see

  octave:1> [fid, msg] = fopen ("test", "w")
  fid = -1
  msg = Is a directory

when trying to open a directory for writing.  When trying to open a
nonexistent file for opening, I see

  octave:2> [fid, msg] = fopen ("nonexistent", "r")
  fid = -1
  msg = No such file or directory

I don't think this is a very serious bug, so I'm only applying this
fix to the 2.9.x branch.

jwe


src/ChangeLog:

2005-05-23  John W. Eaton  <address@hidden>

        * file-io.cc (Ffopen): Don't fail with internal error message if
        we fail to create a valid stream object.
        (do_stream_open (const std::string&, const std::string&,
        const std::string&, int&): Always create octave_stream object,
        even if file pointer returne from fopen is 0.

 
Index: src/file-io.cc
===================================================================
RCS file: /cvs/octave/src/file-io.cc,v
retrieving revision 1.169
diff -u -r1.169 file-io.cc
--- src/file-io.cc      18 May 2005 02:18:24 -0000      1.169
+++ src/file-io.cc      24 May 2005 02:23:33 -0000
@@ -414,9 +414,9 @@
            {
              FILE *fptr = ::fopen (name.c_str (), mode.c_str ());
 
-             if (fptr)
-               retval = octave_stdiostream::create (name, fptr, md, flt_fmt);
-             else
+             retval = octave_stdiostream::create (name, fptr, md, flt_fmt);
+
+             if (! fptr)
                {
                  using namespace std;
                  retval.error (::strerror (errno));
@@ -608,23 +608,18 @@
 
       octave_stream os = do_stream_open (args(0), mode, arch, "fopen", fid);
 
-      if (os.is_valid ())
+      if (os && ! error_state)
        {
-         if (os && ! error_state)
-           {
-             retval(1) = "";
-             retval(0) = octave_stream_list::insert (os);
-           }
-         else
-           {
-             int error_number = 0;
-
-             retval(1) = os.error (false, error_number);
-             retval(0) = -1.0;
-           }
+         retval(1) = "";
+         retval(0) = octave_stream_list::insert (os);
        }
       else
-       error ("fopen: internal error");
+       {
+         int error_number = 0;
+
+         retval(1) = os.error (false, error_number);
+         retval(0) = -1.0;
+       }
     }
   else
     print_usage ("fopen");



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]