# HG changeset patch
# User Jaroslav Hajek
# Date 1266480268 -3600
# Node ID b47a8fb707b8206e268728aa748cae82433c538f
# Parent db540cb0e95984605f29d81952fcbaa8d558fabe
[mq]: fstat.diff
diff --git a/scripts/deprecated/fstat.m b/scripts/deprecated/fstat.m
new file mode 100644
--- /dev/null
+++ b/scripts/deprecated/fstat.m
@@ -0,0 +1,35 @@
+## Copyright (C) 2010 VZLU Prague
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING. If not, see
+## .
+
+## -*- texinfo -*-
+## @deftypefn {Function File} address@hidden, @var{err}, @var{msg}] = } fstat (fid)
+## This function has been deprecated. Use stat instead.
+## @end deftypefn
+
+## Deprecated in version 3.4
+
+function [info, err, msg] = fstat (fid)
+ persistent warned = false;
+ if (! warned)
+ warned = true;
+ warning ("Octave:deprecated-function",
+ "fstat is obsolete and will be removed from a future version of Octave, please use stat instead");
+ endif
+
+ [info, err, msg] = stat (fid);
+endfunction
diff --git a/scripts/deprecated/module.mk b/scripts/deprecated/module.mk
--- a/scripts/deprecated/module.mk
+++ b/scripts/deprecated/module.mk
@@ -6,6 +6,7 @@
deprecated/complement.m \
deprecated/create_set.m \
deprecated/dmult.m \
+ deprecated/fstat.m \
deprecated/iscommand.m \
deprecated/israwcommand.m \
deprecated/isstr.m \
diff --git a/src/ChangeLog b/src/ChangeLog
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -0,0 +1,6 @@
+2010-02-18 Jaroslav Hajek
+
+ * syscalls.cc (mk_stat_result): New helper function.
+ (Flstat): Call it here.
+ (Fstat): Also here. Handle also the fstat case here.
+
diff --git a/src/syscalls.cc b/src/syscalls.cc
--- a/src/syscalls.cc
+++ b/src/syscalls.cc
@@ -85,6 +85,27 @@
return m;
}
+static octave_value_list
+mk_stat_result (const base_file_stat& fs)
+{
+ octave_value_list retval;
+
+ 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 ();
+ }
+
+ return retval;
+}
+
DEFUNX ("dup2", Fdup2, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} address@hidden, @var{msg}] =} dup2 (@var{old}, @var{new})\n\
@@ -719,43 +740,6 @@
return retval;
}
-DEFUNX ("fstat", Ffstat, args, ,
- "-*- texinfo -*-\n\
address@hidden {Built-in Function} address@hidden, @var{err}, @var{msg}] =} fstat (@var{fid})\n\
-Return information about the open file @var{fid}. See @code{stat}\n\
-for a description of the contents of @var{info}.\n\
address@hidden 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;
-}
-
DEFUNX ("lstat", Flstat, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} address@hidden, @var{err}, @var{msg}] =} lstat (@var{file})\n\
@@ -772,18 +756,7 @@
{
file_stat fs (fname, false);
- if (fs)
- {
- retval(2) = std::string ();
- retval(1) = 0;
- retval(0) = mk_stat_map (fs);
- }
- else
- {
- retval(2) = fs.error ();
- retval(1) = -1;
- retval(0) = Matrix ();
- }
+ retval = mk_stat_result (fs);
}
}
else
@@ -792,8 +765,6 @@
return retval;
}
-
-
DEFUNX ("mkfifo", Fmkfifo, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} address@hidden, @var{msg}] =} mkfifo (@var{name}, @var{mode})\n\
@@ -999,23 +970,26 @@
if (args.length () == 1)
{
- std::string fname = args(0).string_value ();
+ if (args(0).is_scalar_type ())
+ {
+ int fid = octave_stream_list::get_file_number (args(0));
- if (! error_state)
+ if (! error_state)
+ {
+ file_fstat fs (fid);
+
+ retval = mk_stat_result (fs);
+ }
+ }
+ else
{
- file_stat fs (fname);
+ std::string fname = args(0).string_value ();
- if (fs)
+ if (! error_state)
{
- 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 ();
+ file_stat fs (fname);
+
+ retval = mk_stat_result (fs);
}
}
}