15 #include <grass/config.h>
21 #include <grass/segment.h>
24 static int _segment_format(
int,
int,
int,
int,
int,
int,
int);
25 static int write_int(
int,
int);
26 static int zero_fill(
int, off_t);
65 return _segment_format(fd, nrows, ncols, srows, scols, len, 1);
105 return _segment_format(fd, nrows, ncols, srows, scols, len, 0);
109 static int _segment_format(
int fd,
110 int nrows,
int ncols,
111 int srows,
int scols,
int len,
int fill)
116 if (nrows <= 0 || ncols <= 0 || len <= 0 || srows <= 0 || scols <= 0) {
117 G_warning(
"segment_format(fd,%d,%d,%d,%d,%d): illegal value(s)",
118 nrows, ncols, srows, scols, len);
122 if (lseek(fd, 0L, SEEK_SET) == (off_t) -1) {
123 G_warning(
"segment_format(): Unable to seek (%s)", strerror(
errno));
127 if (!write_int(fd, nrows) || !write_int(fd, ncols)
128 || !write_int(fd, srows) || !write_int(fd, scols)
129 || !write_int(fd, len))
139 size = srows * scols * len;
142 nbytes = spr * ((nrows + srows - 1) / srows);
151 if (zero_fill(fd, nbytes) < 0)
158 static int write_int(
int fd,
int n)
160 if (write(fd, &n,
sizeof(
int)) !=
sizeof(
int)) {
161 G_warning(
"segment_format(): Unable to write (%s)", strerror(
errno));
169 static int zero_fill(
int fd, off_t nbytes)
177 n = nbytes >
sizeof(
buf) ?
sizeof(buf) : nbytes;
183 n = nbytes >
sizeof(
buf) ?
sizeof(buf) : nbytes;
184 if (write(fd, buf, n) != n) {
185 G_warning(
"segment zero_fill(): Unable to write (%s)", strerror(
errno));
199 static const char buf[10];
201 G_debug(3,
"Using new segmentation code...");
202 if (lseek(fd, nbytes - 1, SEEK_CUR) < 0) {
203 G_warning(
"segment zero_fill(): Unable to seek (%s)", strerror(
errno));
206 if (write(fd, buf, 1) != 1) {
207 G_warning(
"segment zero_fill(): Unable to write (%s)", strerror(
errno));
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.