[MOAB-dev] r3788 - MOAB/trunk/src

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Fri Apr 16 17:52:39 CDT 2010


Author: kraftche
Date: 2010-04-16 17:52:39 -0500 (Fri, 16 Apr 2010)
New Revision: 3788

Modified:
   MOAB/trunk/src/Core.cpp
Log:
fix ticked #159: do set_last_error when asked to read non-existant file

Modified: MOAB/trunk/src/Core.cpp
===================================================================
--- MOAB/trunk/src/Core.cpp	2010-04-16 21:30:59 UTC (rev 3787)
+++ MOAB/trunk/src/Core.cpp	2010-04-16 22:52:39 UTC (rev 3788)
@@ -42,6 +42,10 @@
 #include "moab/ReaderIface.hpp"
 #include "moab/WriterIface.hpp"
 
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+
 #ifdef USE_MPI
 /* Leave ParallelComm.hpp before mpi.h or MPICH2 will fail
  * because its C++ headers do not like SEEK_* macros.
@@ -364,6 +368,28 @@
                                const int* set_tag_vals,
                                int num_set_tag_vals )
 {
+  int status;
+#if defined(WIN32) || defined(WIN64) || defined(MSC_VER)
+  struct _stat stat_data;
+  status = _stat(file_name, &stat_data);
+#else
+  struct stat stat_data;
+  status = stat(file_name, &stat_data);
+#endif
+  if (status) {
+    mError->set_last_error( "%s: %s", file_name, strerror(errno) );
+    return MB_FILE_DOES_NOT_EXIST;
+  }
+#if defined(WIN32) || defined(WIN64) || defined(MSC_VER)
+  else if (_S_IFDIR(stat_data.st_mode)) {
+#else
+  else if (S_ISDIR(stat_data.st_mode)) {
+#endif
+    mError->set_last_error( "%s: Cannot read directory/folder.", file_name );
+    return MB_FILE_DOES_NOT_EXIST;
+  }
+
+
   FileOptions opts(options);
   ErrorCode rval;
   ReaderIface::IDTag t = { set_tag_name, set_tag_vals, num_set_tag_vals, 0, 0 };









More information about the moab-dev mailing list