summaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2014-09-07 11:11:32 -0400
committerAdrian Thurston <thurston@complang.org>2014-09-07 11:11:32 -0400
commit0494f274342db2881936ec0e790b041d9812c622 (patch)
tree20c36f25e3a87446522747ff8afc245073c98c90 /src/main.cc
parentb9b55a76f81c832bf0be62c80b20bf60ca332e96 (diff)
downloadcolm-0494f274342db2881936ec0e790b041d9812c622.tar.gz
do an open check in the include load
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main.cc b/src/main.cc
index c7f929f6..486d0e17 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -568,6 +568,19 @@ void processArgs( int argc, const char **argv )
}
}
+bool readCheck( const char *fn )
+{
+ int result = true;
+
+ /* Check if we can open the input file for reading. */
+ ifstream *inFile = new ifstream( fn );
+ if ( ! inFile->is_open() )
+ result = false;
+
+ delete inFile;
+ return result;
+}
+
/* Main, process args and call yyparse to start scanning input. */
int main(int argc, const char **argv)
{
@@ -588,18 +601,15 @@ int main(int argc, const char **argv)
"\" is the same as the input file" << endl;
}
-
#if defined(LOAD_INIT) || defined(LOAD_COLM)
/* Open the input file for reading. */
if ( inputFn == 0 ) {
error() << "colm: no input file given" << endl;
}
else {
- /* Open the input file for reading. */
- ifstream *inFile = new ifstream( inputFn );
- if ( ! inFile->is_open() )
+ /* Check if we can open the input file for reading. */
+ if ( ! readCheck( inputFn ) )
error() << "could not open " << inputFn << " for reading" << endl;
- delete inFile;
}
#endif