diff src/syscalls.cc @ 8549:424ba638d8f1

[mq]: fstat
author file-io.cc (Ffstat): new function
date Tue, 20 Jan 2009 20:02:43 -0500
parents 6f2d95255911
children eb63fbe60fab
line wrap: on
line diff
--- a/src/syscalls.cc
+++ b/src/syscalls.cc
@@ -63,7 +63,7 @@
 #include "input.h"
 
 static Octave_map
-mk_stat_map (const file_stat& fs)
+mk_stat_map (const base_file_stat& fs)
 {
   Octave_map m;
 
@@ -722,6 +722,43 @@
   return retval;
 }
 
+DEFUN (fstat, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} fstat (@var{fid})\n\
+Return information about about the open file @var{fid}.  See @code{stat}\n\
+for a description of the contents of @var{info}.\n\
+@end deftypefn")
+{
+  octave_value_list retval;
+
+  if (args.length () == 1)
+    {
+      int fid = octave_stream_list::get_file_number (args(0));
+
+      if (! error_state)
+	{
+	  file_fstat fs (fid);
+
+	  if (fs)
+	    {
+	      retval(2) = std::string ();
+	      retval(1) = 0;
+	      retval(0) = octave_value (mk_stat_map (fs));
+	    }
+	  else
+	    {
+	      retval(2) = fs.error ();
+	      retval(1) = -1;
+	      retval(0) = Matrix ();
+	    }
+	}
+    }
+  else
+    print_usage ();
+
+  return retval;
+}
+
 DEFUN (lstat, args, ,
   "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {[@var{info}, @var{err}, @var{msg}] =} lstat (@var{file})\n\