22 #include "local_proto.h"    25 static int seg_format(
int, off_t, off_t, 
int, 
int, 
int, 
int);
    26 static int write_int(
int, 
int);
    27 static int write_off_t(
int, off_t);
    28 static int zero_fill(
int, off_t);
    29 static int seek_only(
int, off_t);
    66     return seg_format(fd, nrows, ncols, srows, scols, len, 1);
   104     return seg_format(fd, nrows, ncols, srows, scols, len, 0);
   108 static int seg_format(
int fd, off_t nrows, off_t ncols,
   109                       int srows, 
int scols, 
int len, 
int fill)
   114     if (nrows <= 0 || ncols <= 0 || len <= 0 || srows <= 0 || scols <= 0) {
   116                   nrows, ncols, srows, scols, len);
   124     size = srows * scols * len;
   126     if (
sizeof(off_t) == 4 && 
sizeof(
double) >= 8) {
   131         d_size = (double) spr * ((nrows + srows - 1) / srows);
   136         d_size += 2 * 
sizeof(off_t) + 3 * 
sizeof(
int);
   138         o_size = (off_t) d_size;
   142         if ((
double) o_size != d_size) {
   143             G_warning(
_(
"Segment format: file size too large"));
   144             G_warning(
_(
"Please recompile with Large File Support (LFS)"));
   149     if (lseek(fd, 0L, SEEK_SET) == (off_t) -1) {
   152         G_warning(
"Segment_format(): Unable to seek (%s)", strerror(err));
   156     if (!write_off_t(fd, nrows) || !write_off_t(fd, ncols)
   157         || !write_int(fd, srows) || !write_int(fd, scols)
   158         || !write_int(fd, len))
   162     nbytes = spr * ((nrows + srows - 1) / srows);
   167         if (seek_only(fd, nbytes) < 0)
   178     if (zero_fill(fd, nbytes) < 0)
   185 static int write_int(
int fd, 
int n)
   188     if (write(fd, &n, 
sizeof(
int)) != 
sizeof(
int)) {
   192             G_warning(
"Segment format: Unable to write (%s)", strerror(err));
   194             G_warning(
"Segment format: Unable to write (insufficient disk space?)");
   201 static int write_off_t(
int fd, off_t n)
   204     if (write(fd, &n, 
sizeof(off_t)) != 
sizeof(off_t)) {
   208             G_warning(
"Segment format: Unable to write (%s)", strerror(err));
   210             G_warning(
"Segment format: Unable to write (insufficient disk space?)");
   217 static int zero_fill(
int fd, off_t 
nbytes)
   225     n = nbytes > 
sizeof(buf) ? 
sizeof(buf) : 
nbytes;
   231         n = nbytes > 
sizeof(buf) ? 
sizeof(buf) : 
nbytes;
   233         if (write(fd, buf, n) != n) {
   237                 G_warning(
"segment zero_fill(): Unable to write (%s)", strerror(err));
   239                 G_warning(
"segment zero_fill(): Unable to write (insufficient disk space?)");
   246     return seek_only(fd, nbytes);
   250 static int seek_only(
int fd, off_t 
nbytes)
   259     static const char buf[10];
   261     G_debug(3, 
"Using new segmentation code...");
   263     if (lseek(fd, nbytes - 1, SEEK_CUR) < 0) {
   266         G_warning(
"segment zero_fill(): Unable to seek (%s)", strerror(err));
   270     if (write(fd, buf, 1) != 1) {
   274             G_warning(
"segment zero_fill(): Unable to write (%s)", strerror(err));
   276             G_warning(
"segment zero_fill(): Unable to write (insufficient disk space?)");
 
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf