[MOAB-dev] r3342 - MOAB/trunk

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Thu Nov 12 16:25:37 CST 2009


Author: kraftche
Date: 2009-11-12 16:25:37 -0600 (Thu, 12 Nov 2009)
New Revision: 3342

Modified:
   MOAB/trunk/ReadHDF5.cpp
Log:
try to avoid HDF5 library writing junk to stdout/stderr for non-existent files

Modified: MOAB/trunk/ReadHDF5.cpp
===================================================================
--- MOAB/trunk/ReadHDF5.cpp	2009-11-12 22:24:50 UTC (rev 3341)
+++ MOAB/trunk/ReadHDF5.cpp	2009-11-12 22:25:37 UTC (rev 3342)
@@ -61,6 +61,12 @@
 
 #define READ_HDF5_BUFFER_SIZE (40*1024*1024)
 
+#if !defined(WIN32) && !defined(WIN64)
+# include <sys/stat.h>
+# include <unistd.h>
+# include <errno.h>
+#endif
+
 // This function doesn't do anything useful.  It's just a nice
 // place to set a break point to determine why the reader fails.
 static inline MBErrorCode error( MBErrorCode rval )
@@ -257,6 +263,21 @@
 #endif
   }
   else {
+  
+      // first check if file exists, so we can fail w/out
+      // a lot of noise from the HDF5 library if it does not
+#if !defined(WIN32) && !defined(WIN64)
+    struct stat junk;
+    if (stat( filename, &junk)) {
+      if (ENOENT == errno)
+        return MB_FILE_DOES_NOT_EXIST;
+      else
+        return MB_FILE_WRITE_ERROR;
+    }
+    else if (S_ISDIR(junk.st_mode))
+      return MB_FILE_DOES_NOT_EXIST;
+#endif
+  
       // Open the file
     filePtr = mhdf_openFile( filename, 0, NULL, &status );
     if (!filePtr)



More information about the moab-dev mailing list