[GRASS-SVN] r49782 - grass/branches/releasebranch_6_4/include/iostream

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Dec 16 03:23:09 EST 2011


Author: mmetz
Date: 2011-12-16 00:23:08 -0800 (Fri, 16 Dec 2011)
New Revision: 49782

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

Modified: grass/branches/releasebranch_6_4/include/iostream/ami_stream.h
===================================================================
--- grass/branches/releasebranch_6_4/include/iostream/ami_stream.h	2011-12-16 01:31:38 UTC (rev 49781)
+++ grass/branches/releasebranch_6_4/include/iostream/ami_stream.h	2011-12-16 08:23:08 UTC (rev 49782)
@@ -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);
   }
 
@@ -388,9 +391,8 @@
 #else
   struct stat buf;
   if (stat(path, &buf) == -1) {
-    perror("AMI_STREAM::stream_len(): fstat failed ");
-	perror(path);
-    assert(0);
+    perror("ERROR: AMI_STREAM::stream_len(): fstat failed ");
+    DEBUG_ASSERT assert(0);
     exit(1);
   }
   return (buf.st_size / sizeof(T));
@@ -429,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 
@@ -449,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);
   }
   
@@ -498,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);
     }
   }
@@ -528,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;
       }
@@ -562,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;
       }
@@ -586,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);
     }
 
@@ -610,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