浏览代码

segment lib: add LFS check

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@46432 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 14 年之前
父节点
当前提交
4c83c6a9d4
共有 1 个文件被更改,包括 28 次插入0 次删除
  1. 28 0
      lib/segment/format.c

+ 28 - 0
lib/segment/format.c

@@ -18,6 +18,7 @@
 #include <unistd.h>
 #include <limits.h>
 #include <grass/gis.h>
+#include <grass/glocale.h>
 #include <grass/segment.h>
 
 
@@ -119,6 +120,33 @@ static int _segment_format(int fd,
 	return -3;
     }
 
+    if (sizeof(off_t) == 4 && sizeof(double) >= 8) {
+	double d_size;
+	off_t o_size;
+
+	spr = ncols / scols;
+	if (ncols % scols)
+	    spr++;
+
+	/* calculate total number of segments */
+	d_size = (double) spr * ((nrows + srows - 1) / srows);
+	/* multiply with segment size */
+	d_size *= srows * scols * len;
+
+	/* add header */
+	d_size += 5 * sizeof(int);
+
+	o_size = (off_t) d_size;
+
+	/* this test assumes that all off_t values can be exactly 
+	 * represented as double if sizeof(off_t) = 4 and sizeof(double) >= 8 */
+	if ((double) o_size != d_size) {
+	    G_warning(_("Segment format: file size too large"));
+	    G_warning(_("Please recompile with Large File Support (LFS)"));
+	    return -1;
+	}
+    }
+
     if (lseek(fd, 0L, SEEK_SET) == (off_t) -1) {
 	G_warning("Segment_format: %s", strerror(errno));
 	return -1;