From d9dfa9c1e3280e983641eb141877cc1b89370c13 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 27 Mar 2005 18:37:42 +0000 Subject: [PATCH] fix open files bug on solaris git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9752 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/ChangeLog | 6 ++++++ src/tex2lyx/tex2lyx.C | 14 ++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/tex2lyx/ChangeLog b/src/tex2lyx/ChangeLog index ee63d5c291..9d091be9ae 100644 --- a/src/tex2lyx/ChangeLog +++ b/src/tex2lyx/ChangeLog @@ -1,3 +1,9 @@ +2005-03-27 Georg Baum + + * tex2lyx.C (read_syntaxfile): Don't use racy test with IsFileReadable + * tex2lyx.C (tex2lyx): ditto, and don't use fs::is_writable (it + returns false if the file does not exist on solaris) + 2005-03-18 Georg Baum * text.C (parse_text): Fix \start_of_appendix output diff --git a/src/tex2lyx/tex2lyx.C b/src/tex2lyx/tex2lyx.C index f32fdcca28..67f8d30cf3 100644 --- a/src/tex2lyx/tex2lyx.C +++ b/src/tex2lyx/tex2lyx.C @@ -168,12 +168,12 @@ namespace { */ void read_syntaxfile(string const & file_name) { - if (!IsFileReadable(file_name)) { + ifstream is(file_name.c_str()); + if (!is.good()) { cerr << "Could not open syntax file \"" << file_name << "\" for reading." << endl; exit(2); } - ifstream is(file_name.c_str()); // We can use our TeX parser, since the syntax of the layout file is // modeled after TeX. // Unknown tokens are just silently ignored, this helps us to skip some @@ -363,14 +363,16 @@ void tex2lyx(std::istream &is, std::ostream &os) bool tex2lyx(string const &infilename, string const &outfilename) { - if (!(IsFileReadable(infilename) && fs::is_writable(outfilename))) { + ifstream is(infilename.c_str()); + if (!is.good()) { + cerr << "Could not open file \"" << infilename + << "\" for reading." << endl; return false; } if (!overwrite_files && IsFileReadable(outfilename)) { cerr << "Not overwriting existing file " << outfilename << "\n"; return false; } - ifstream is(infilename.c_str()); ofstream os(outfilename.c_str()); #ifdef FILEDEBUG cerr << "File: " << infilename << "\n"; @@ -405,7 +407,8 @@ int main(int argc, char * argv[]) if (!syntaxfile.empty()) read_syntaxfile(syntaxfile); - if (!IsFileReadable(argv[1])) { + ifstream is(argv[1]); + if (!is.good()) { cerr << "Could not open input file \"" << argv[1] << "\" for reading." << endl; return 2; @@ -416,7 +419,6 @@ int main(int argc, char * argv[]) else masterFilePath = lyx::support::getcwd(); - ifstream is(argv[1]); tex2lyx(is, cout); return 0; -- 2.39.2