changeset 11142:3450551f591e

new function, is_valid_file_id
author John W. Eaton <jwe@octave.org>
date Sat, 23 Oct 2010 01:50:14 -0400
parents 224c80da37c5
children 195cffc2d0a3
files doc/ChangeLog doc/interpreter/io.txi scripts/ChangeLog scripts/io/is_valid_file_id.m scripts/io/module.mk
diffstat 5 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Sat Oct 23 13:37:36 2010 +0800
+++ b/doc/ChangeLog	Sat Oct 23 01:50:14 2010 -0400
@@ -1,3 +1,8 @@
+2010-10-23  John W. Eaton  <jwe@octave.org>
+
+	* interpreter/io.txi (Opening and Closing Files):
+	Document is_valid_file_id.
+
 2010-10-21  John W. Eaton  <jwe@octave.org>
 
 	* interpreter/contributors.in: Add Gunnar Farnebäck to the list.
--- a/doc/interpreter/io.txi	Sat Oct 23 13:37:36 2010 +0800
+++ b/doc/interpreter/io.txi	Sat Oct 23 01:50:14 2010 -0400
@@ -320,6 +320,8 @@
 
 @DOCSTRING(fclose)
 
+@DOCSTRING(is_valid_file_id)
+
 @node Simple Output
 @subsection Simple Output
 
--- a/scripts/ChangeLog	Sat Oct 23 13:37:36 2010 +0800
+++ b/scripts/ChangeLog	Sat Oct 23 01:50:14 2010 -0400
@@ -1,3 +1,8 @@
+2010-10-23  John W. Eaton  <jwe@octave.org>
+
+	* io/is_valid_file_id.m: New function.
+	* io/module.mk (io_FCN_FILES): Add it to the list.
+
 2010-10-23  Ben Abbott <bpabbott@mac.com>
 
 	* io/textscan.m, miscellaneous/unimplemented.m, io/module.mk:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/io/is_valid_file_id.m	Sat Oct 23 01:50:14 2010 -0400
@@ -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
+## <http://www.gnu.org/licenses/>.
+
+## -*- 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
--- a/scripts/io/module.mk	Sat Oct 23 13:37:36 2010 +0800
+++ b/scripts/io/module.mk	Sat Oct 23 01:50:14 2010 -0400
@@ -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