[GRASS-SVN] r49771 - grass/branches/develbranch_6/include/iostream

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 15 09:14:16 EST 2011


Author: mmetz
Date: 2011-12-15 06:14:16 -0800 (Thu, 15 Dec 2011)
New Revision: 49771

Modified:
   grass/branches/develbranch_6/include/iostream/ami_stream.h
Log:
clean up error messages

Modified: grass/branches/develbranch_6/include/iostream/ami_stream.h
===================================================================
--- grass/branches/develbranch_6/include/iostream/ami_stream.h	2011-12-15 14:13:31 UTC (rev 49770)
+++ grass/branches/develbranch_6/include/iostream/ami_stream.h	2011-12-15 14:14:16 UTC (rev 49771)
@@ -41,6 +41,7 @@
 #include "mm.h" // Get the memory manager.
 
 #define DEBUG_DELETE if(0)
+#define DEBUG_ASSERT if(0)
 
 // The name of the environment variable which keeps the name of the
 // directory where streams are stored
@@ -81,7 +82,7 @@
     AMI_WRITE_STREAM,		// Open for writing.  Create if non-existent
     AMI_APPEND_STREAM,		// Open for writing at end.  Create if needed.
     AMI_READ_WRITE_STREAM,	// Open to read and write.
-	AMI_APPEND_WRITE_STREAM // Open for writing at end (write only mode).
+    AMI_APPEND_WRITE_STREAM     // Open for writing at end (write only mode).
 };
 
 
@@ -219,7 +220,8 @@
   /* a stream is by default buffered with a buffer of size BUFSIZ=1K */
   buf = new char[STREAM_BUFFER_SIZE];
   if (setvbuf(fp, buf, _IOFBF, STREAM_BUFFER_SIZE) != 0) {
-    cerr << "setvbuf failed (stream " << path << ")" << endl;
+    cerr << "ERROR: setvbuf failed (stream " << path << ") with: "
+         << strerror(errno) << endl;
     exit(1);
   }
   
@@ -264,7 +266,8 @@
   /* a stream is by default buffered with a buffer of size BUFSIZ=1K */
   buf = new char[STREAM_BUFFER_SIZE];
   if (setvbuf(fp, buf, _IOFBF, STREAM_BUFFER_SIZE) != 0) {
-    cerr << "setvbuf failed (stream " << path << ")" << endl;
+    cerr << "ERROR: setvbuf failed (stream " << path << ") with: "
+         << strerror(errno) << endl;
     exit(1);
   }
 
@@ -384,12 +387,12 @@
 
   fseek(fp, posn_save, SEEK_SET);
   return (st_size / sizeof(T));
+
 #else
   struct stat buf;
   if (stat(path, &buf) == -1) {
     perror("AMI_STREAM::stream_len(): fstat failed ");
-	perror(path);
-    assert(0);
+    DEBUG_ASSERT assert(0);
     exit(1);
   }
   return (buf.st_size / sizeof(T));
@@ -428,9 +431,9 @@
   if (substream_level) {    //substream
     if (offset  > (unsigned) (logical_eos - logical_bos)) {
       //offset out of range
-      cerr << "AMI_STREAM::seek bos=" << logical_bos << ", eos=" << logical_eos
-	   << ", offset " << offset << " out of range.\n";
-      assert(0);
+      cerr << "ERROR: AMI_STREAM::seek bos=" << logical_bos << ", eos="
+           << logical_eos << ", offset " << offset << " out of range.\n";
+      DEBUG_ASSERT assert(0);
       exit(1);
     } else {
       //offset in range 
@@ -448,8 +451,8 @@
 #else
   if (fseek(fp, seek_offset, SEEK_SET) == -1) {
 #endif     
-    cerr << "AMI_STREAM::seek offset=" << seek_offset << " failed.\n";
-    assert(0);
+    cerr << "ERROR: AMI_STREAM::seek offset=" << seek_offset << " failed.\n";
+    DEBUG_ASSERT assert(0);
     exit(1);
   }
   
@@ -497,9 +500,9 @@
   // Get rid of the file if not persistent and if not substream.
   if ((per != PERSIST_PERSISTENT) && (substream_level == 0)) {
     if (unlink(path) == -1) {
-      cerr << "AMI_STREAM: failed to unlink " << path << endl;
-      perror("cannot unlink ");
-      assert(0);
+      cerr << "ERROR: AMI_STREAM: failed to unlink " << path << endl;
+      perror("cannot unlink: ");
+      DEBUG_ASSERT assert(0);
       exit(1);
     }
   }
@@ -527,7 +530,7 @@
 	eof_reached = 1;
 	return AMI_ERROR_END_OF_STREAM;
       } else {
-	cerr << "file=" << path << ":";
+	cerr << "ERROR: file=" << path << ":";
 	perror("cannot read!");    
 	return AMI_ERROR_IO_ERROR;
       }
@@ -561,7 +564,7 @@
 	eof_reached = 1;
 	return AMI_ERROR_END_OF_STREAM;
       } else {
-	cerr << "file=" << path << ":";
+	cerr << "ERROR: file=" << path << ":";
 	perror("cannot read!");    
 	return AMI_ERROR_IO_ERROR;
       }
@@ -585,9 +588,12 @@
   
   } else {
     if (fwrite((char*)(&elt), sizeof(T), 1,fp) < 1) {
-      cerr << "AMI_STREAM::write_item failed.\n";
-      perror(path);
-      assert(0);
+      cerr << "ERROR: AMI_STREAM::write_item failed.\n";
+      if (path && *path)
+	perror(path);
+      else
+	perror("AMI_STREAM::write_item: ");
+      DEBUG_ASSERT assert(0);
       exit(1);
     }
 
@@ -609,8 +615,12 @@
   } else {
     nobj = fwrite(data, sizeof(T), len, fp);
     if (nobj  < len) {
-      cerr << "AMI_STREAM::write_item failed.\n";
-      assert(0);
+      cerr << "ERROR: AMI_STREAM::write_array failed.\n";
+      if (path && *path)
+	perror(path);
+      else
+	perror("AMI_STREAM::write_array: ");
+      DEBUG_ASSERT assert(0);
       exit(1);
     }
    return AMI_ERROR_NO_ERROR;



More information about the grass-commit mailing list