1
1
/* * This file is part of VLSV file format.
2
2
*
3
- * Copyright 2011-2013 Finnish Meteorological Institute
3
+ * Copyright 2011-2015 Finnish Meteorological Institute
4
+ * Copyright 2016 Arto Sandroos
4
5
*
5
6
* This program is free software: you can redistribute it and/or modify
6
7
* it under the terms of the GNU Lesser General Public License as published by
@@ -155,7 +156,7 @@ namespace vlsv {
155
156
#endif
156
157
return false ;
157
158
}
158
-
159
+
159
160
// If given filename includes path, chdir into that path:
160
161
string fnameWithoutPath;
161
162
string pathName;
@@ -168,13 +169,14 @@ namespace vlsv {
168
169
} else {
169
170
pathName = fname.substr (0 ,position);
170
171
fnameWithoutPath = fname.substr (position+1 );
172
+ // Chdir to path containing input file and attempt to open the file,
173
+ // then chdir back to current working directory.
174
+ // Chdir returns zero value if it succeeds
175
+ // Not done if the string is empty as chdir fials in that case.
176
+ if (fileio::chdir (pathName.c_str ()) != 0 ) success = false ;
171
177
}
172
178
}
173
179
174
- // Chdir to path containing input file and attempt to open the file,
175
- // then chdir back to current working directory.
176
- // Chdir returns zero value if it succeeds
177
- if (fileio::chdir (pathName.c_str ()) != 0 ) success = false ;
178
180
filein.open (fnameWithoutPath.c_str (), fstream::in | fstream::binary);
179
181
if (fileio::chdir (cwd) != 0 ) success = false ;
180
182
@@ -185,6 +187,7 @@ namespace vlsv {
185
187
filein.close ();
186
188
success = false ;
187
189
}
190
+
188
191
if (success == false ) {
189
192
#ifndef NDEBUG
190
193
cerr << " vlsv::Reader ERROR: File '" << fnameWithoutPath << " ' could not be opened!" << endl;
0 commit comments