/*
Copyright (C) 2020 Markus Mützel
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
.
*/
#if defined (HAVE_CONFIG_H)
# include "config.h"
#endif
#include
#include
#include
#include "defun-dld.h"
#include "error.h"
#include "file-stat.h"
#include "oct.h"
#include "ovl.h"
DEFUN_DLD (file_stat_exists, args, ,
"-*- texinfo -*-\
@deftypefn {} {@var{bool} =} file_stat_exists (file_name)\
Return true if file FILE_NAME exists on disk using 'stat'.\
\
@end deftypefn */")
{
if (args.length () != 1)
print_usage ();
// Input check
std::string file_name =
args(0).xstring_value ("file_exists: Not a string.");
bool out = false;
const int LOOPMAX = 1e4;
for (int i_loop = 0; i_loop < LOOPMAX; i_loop++)
{
octave::sys::file_stat fs (file_name);
out = (fs.exists () && fs.is_reg ());
}
return ovl (out);
}