# HG changeset patch # User John W. Eaton # Date 1287813014 14400 # Node ID 3450551f591e91e40d89e5153ae7e55834aeb667 # Parent 224c80da37c529ebe936033678315ed5f229a158 new function, is_valid_file_id diff --git a/doc/ChangeLog b/doc/ChangeLog --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2010-10-23 John W. Eaton + + * interpreter/io.txi (Opening and Closing Files): + Document is_valid_file_id. + 2010-10-21 John W. Eaton * interpreter/contributors.in: Add Gunnar Farnebäck to the list. diff --git a/doc/interpreter/io.txi b/doc/interpreter/io.txi --- a/doc/interpreter/io.txi +++ b/doc/interpreter/io.txi @@ -320,6 +320,8 @@ @DOCSTRING(fclose) +@DOCSTRING(is_valid_file_id) + @node Simple Output @subsection Simple Output diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2010-10-23 John W. Eaton + + * io/is_valid_file_id.m: New function. + * io/module.mk (io_FCN_FILES): Add it to the list. + 2010-10-23 Ben Abbott * io/textscan.m, miscellaneous/unimplemented.m, io/module.mk: diff --git a/scripts/io/is_valid_file_id.m b/scripts/io/is_valid_file_id.m new file mode 100644 --- /dev/null +++ b/scripts/io/is_valid_file_id.m @@ -0,0 +1,38 @@ +## Copyright (C) 2010 John W. Eaton +## +## 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} {} is_valid_file_id (@var{fid}) +## Return true if @var{fid} refers to an open file. +## @seealso{fopen} +## @end deftypefn + +function retval = is_valid_file_id (fid) + + retval = false; + + if (nargin == 1) + try + [file, mode, arch] = fopen (fid); + retval = ! isempty (file); + end_try_catch + else + print_usage (); + endif + +endfunction diff --git a/scripts/io/module.mk b/scripts/io/module.mk --- a/scripts/io/module.mk +++ b/scripts/io/module.mk @@ -6,6 +6,7 @@ io/csvwrite.m \ io/dlmwrite.m \ io/fileread.m \ + io/is_valid_file_id.m \ io/strread.m \ io/textscan.m \ io/textread.m