[GRASS-SVN] r72042 - grass/trunk/lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jan 6 11:04:56 PST 2018
Author: mmetz
Date: 2018-01-06 11:04:56 -0800 (Sat, 06 Jan 2018)
New Revision: 72042
Modified:
grass/trunk/lib/gis/compress.c
Log:
libgis: add warnings when writing compressed data fails
Modified: grass/trunk/lib/gis/compress.c
===================================================================
--- grass/trunk/lib/gis/compress.c 2018-01-06 18:27:45 UTC (rev 72041)
+++ grass/trunk/lib/gis/compress.c 2018-01-06 19:04:56 UTC (rev 72042)
@@ -330,8 +330,13 @@
unsigned char *dst, compressed;
/* Catch errors */
- if (src == NULL || nbytes < 0)
+ if (src == NULL || nbytes < 0) {
+ if (src == NULL)
+ G_warning(_("No source buffer"));
+ if (nbytes <= 0)
+ G_warning(_("Invalid source buffer size %d"), nbytes);
return -1;
+ }
/* get upper bound of compressed size */
dst_sz = G_compress_bound(nbytes, number);
@@ -352,6 +357,7 @@
compressed = G_COMPRESSED_YES;
if (write(fd, &compressed, 1) != 1) {
G_free(dst);
+ G_warning(_("Unable to write compression flag"));
return -1;
}
nwritten = 0;
@@ -360,6 +366,12 @@
if (err >= 0)
nwritten += err;
} while (err > 0 && nwritten < dst_sz);
+ if (err <= 0) {
+ if (err == 0)
+ G_warning(_("Unable to write %d bytes: nothing written"), dst_sz);
+ else
+ G_warning(_("Unable to write %d bytes: %s"), dst_sz, strerror(errno));
+ }
/* Account for extra byte */
nwritten++;
}
@@ -368,6 +380,7 @@
compressed = G_COMPRESSED_NO;
if (write(fd, &compressed, 1) != 1) {
G_free(dst);
+ G_warning(_("Unable to write compression flag"));
return -1;
}
nwritten = 0;
@@ -376,6 +389,12 @@
if (err >= 0)
nwritten += err;
} while (err > 0 && nwritten < nbytes);
+ if (err <= 0) {
+ if (err == 0)
+ G_warning(_("Unable to write %d bytes: nothing written"), nbytes);
+ else
+ G_warning(_("Unable to write %d bytes: %s"), nbytes, strerror(errno));
+ }
/* Account for extra byte */
nwritten++;
} /* if (err > 0) */
@@ -401,8 +420,10 @@
/* Write the compression flag */
compressed = G_COMPRESSED_NO;
- if (write(fd, &compressed, 1) != 1)
+ if (write(fd, &compressed, 1) != 1) {
+ G_warning(_("Unable to write compression flag"));
return -1;
+ }
/* Now write the data */
nwritten = 0;
@@ -411,6 +432,12 @@
if (err > 0)
nwritten += err;
} while (err > 0 && nwritten < nbytes);
+ if (err <= 0) {
+ if (err == 0)
+ G_warning(_("Unable to write %d bytes: nothing written"), nbytes);
+ else
+ G_warning(_("Unable to write %d bytes: %s"), nbytes, strerror(errno));
+ }
if (err < 0 || nwritten != nbytes)
return -1;
More information about the grass-commit
mailing list