[GRASS-SVN] r62429 - grass/trunk/lib/segment

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Oct 28 01:05:55 PDT 2014


Author: mmetz
Date: 2014-10-28 01:05:55 -0700 (Tue, 28 Oct 2014)
New Revision: 62429

Modified:
   grass/trunk/lib/segment/format.c
Log:
libsegment: improve messages on write failure

Modified: grass/trunk/lib/segment/format.c
===================================================================
--- grass/trunk/lib/segment/format.c	2014-10-28 07:40:49 UTC (rev 62428)
+++ grass/trunk/lib/segment/format.c	2014-10-28 08:05:55 UTC (rev 62429)
@@ -22,7 +22,7 @@
 #include "local_proto.h"
 
 
-static int _Segment_format(int, off_t, off_t, int, int, int, int);
+static int seg_format(int, off_t, off_t, int, int, int, int);
 static int write_int(int, int);
 static int write_off_t(int, off_t);
 static int zero_fill(int, off_t);
@@ -62,7 +62,7 @@
 int Segment_format(int fd, off_t nrows, off_t ncols, int srows, int scols,
 		   int len)
 {
-    return _Segment_format(fd, nrows, ncols, srows, scols, len, 1);
+    return seg_format(fd, nrows, ncols, srows, scols, len, 1);
 }
 
 /**
@@ -100,11 +100,11 @@
 int Segment_format_nofill(int fd, off_t nrows, off_t ncols, int srows, int scols,
 			  int len)
 {
-    return _Segment_format(fd, nrows, ncols, srows, scols, len, 0);
+    return seg_format(fd, nrows, ncols, srows, scols, len, 0);
 }
 
 
-static int _Segment_format(int fd,
+static int seg_format(int fd,
 			   off_t nrows, off_t ncols,
 			   int srows, int scols, int len, int fill)
 {
@@ -147,7 +147,9 @@
     }
 
     if (lseek(fd, 0L, SEEK_SET) == (off_t) -1) {
-	G_warning("Segment_format(): Unable to seek (%s)", strerror(errno));
+	int err = errno;
+
+	G_warning("Segment_format(): Unable to seek (%s)", strerror(err));
 	return -1;
     }
 
@@ -178,8 +180,14 @@
 
 static int write_int(int fd, int n)
 {
+    errno = 0;
     if (write(fd, &n, sizeof(int)) != sizeof(int)) {
-	G_warning("Segment_format(): Unable to write (%s)", strerror(errno));
+	int err = errno;
+
+	if (err)
+	    G_warning("Segment format: Unable to write (%s)", strerror(err));
+	else
+	    G_warning("Segment format: Unable to write (insufficient disk space?)");
 	return 0;
     }
 
@@ -188,8 +196,14 @@
 
 static int write_off_t(int fd, off_t n)
 {
+    errno = 0;
     if (write(fd, &n, sizeof(off_t)) != sizeof(off_t)) {
-	G_warning("Segment_format(): Unable to write (%s)", strerror(errno));
+	int err = errno;
+
+	if (err)
+	    G_warning("Segment format: Unable to write (%s)", strerror(err));
+	else
+	    G_warning("Segment format: Unable to write (insufficient disk space?)");
 	return 0;
     }
 
@@ -211,8 +225,14 @@
 
     while (nbytes > 0) {
 	n = nbytes > sizeof(buf) ? sizeof(buf) : nbytes;
+	errno = 0;
 	if (write(fd, buf, n) != n) {
-	    G_warning("segment zero_fill(): Unable to write (%s)", strerror(errno));
+	    int err = errno;
+
+	    if (err)
+		G_warning("segment zero_fill(): Unable to write (%s)", strerror(err));
+	    else
+		G_warning("segment zero_fill(): Unable to write (insufficient disk space?)");
 	    return -1;
 	}
 	nbytes -= n;
@@ -229,12 +249,21 @@
     static const char buf[10];
 
     G_debug(3, "Using new segmentation code...");
+    errno = 0;
     if (lseek(fd, nbytes - 1, SEEK_CUR) < 0) {
-	G_warning("segment zero_fill(): Unable to seek (%s)", strerror(errno));
+	int err = errno;
+
+	G_warning("segment zero_fill(): Unable to seek (%s)", strerror(err));
 	return -1;
     }
+    errno = 0;
     if (write(fd, buf, 1) != 1) {
-	G_warning("segment zero_fill(): Unable to write (%s)", strerror(errno));
+	int err = errno;
+
+	if (err)
+	    G_warning("segment zero_fill(): Unable to write (%s)", strerror(err));
+	else
+	    G_warning("segment zero_fill(): Unable to write (insufficient disk space?)");
 	return -1;
     }
 



More information about the grass-commit mailing list