Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion imagery/i.ortho.photo/i.ortho.rectify/readcell.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ block *get_block(struct cache *c, int idx)
c->grid[idx] = p;
c->refs[replace] = idx;

if (lseek(c->fd, offset, SEEK_SET) < 0)
if (lseek(c->fd, offset, SEEK_SET) == -1)
G_fatal_error(_("Error seeking on segment file"));

if (read(c->fd, p, sizeof(block)) < 0)
Expand Down
2 changes: 1 addition & 1 deletion imagery/i.rectify/readcell.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ block *get_block(struct cache *c, int idx)
c->grid[idx] = p;
c->refs[replace] = idx;

if (lseek(c->fd, offset, SEEK_SET) < 0)
if (lseek(c->fd, offset, SEEK_SET) == -1)
G_fatal_error(_("Error seeking on segment file"));

if (read(c->fd, p, sizeof(block)) < 0)
Expand Down
9 changes: 8 additions & 1 deletion imagery/i.segment/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <unistd.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <errno.h>

#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/glocale.h>
Expand Down Expand Up @@ -421,7 +424,11 @@ CELL cluster_bands(struct globals *globals)
G_fatal_error(_("Too many objects: integer overflow"));

/* rewind temp file */
lseek(cfd, 0, SEEK_SET);
if (lseek(cfd, 0, SEEK_SET) == -1) {
int err = errno;
G_fatal_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
}

/****************************************************
* PASS 2 *
Expand Down
21 changes: 18 additions & 3 deletions lib/gis/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ int G_open_update(const char *element, const char *name)

fd = G__open(element, name, G_mapset(), 2);
if (fd >= 0)
lseek(fd, 0L, SEEK_END);
if (lseek(fd, 0L, SEEK_END) == -1) {
int err = errno;
G_warning(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
return -1;
}

return fd;
}
Expand Down Expand Up @@ -279,7 +284,12 @@ FILE *G_fopen_append(const char *element, const char *name)
fd = G__open(element, name, G_mapset(), 2);
if (fd < 0)
return (FILE *)0;
lseek(fd, 0L, SEEK_END);
if (lseek(fd, 0L, SEEK_END) == -1) {
int err = errno;
G_warning(_("File read/write operation failed: %s (%d)"), strerror(err),
err);
return NULL;
}

G_debug(2, "\tfile open: append (mode = a)");
return fdopen(fd, "a");
Expand Down Expand Up @@ -307,7 +317,12 @@ FILE *G_fopen_modify(const char *element, const char *name)
fd = G__open(element, name, G_mapset(), 2);
if (fd < 0)
return (FILE *)0;
lseek(fd, 0L, SEEK_END);
if (lseek(fd, 0L, SEEK_END) == -1) {
int err = errno;
G_warning(_("File read/write operation failed: %s (%d)"), strerror(err),
err);
return NULL;
}

G_debug(2, "\tfile open: modify (mode = r+)");
return fdopen(fd, "r+");
Expand Down
21 changes: 18 additions & 3 deletions lib/gis/open_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ int G_open_update_misc(const char *dir, const char *element, const char *name)

fd = G__open_misc(dir, element, name, G_mapset(), 2);
if (fd >= 0)
lseek(fd, 0L, SEEK_END);
if (lseek(fd, 0L, SEEK_END) == -1) {
int err = errno;
G_warning(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
return -1;
}

return fd;
}
Expand Down Expand Up @@ -222,7 +227,12 @@ FILE *G_fopen_append_misc(const char *dir, const char *element,
fd = G__open_misc(dir, element, name, G_mapset(), 2);
if (fd < 0)
return (FILE *)0;
lseek(fd, 0L, SEEK_END);
if (lseek(fd, 0L, SEEK_END) == -1) {
int err = errno;
G_warning(_("File read/write operation failed: %s (%d)"), strerror(err),
err);
return (FILE *)-1;
}

return fdopen(fd, "a");
}
Expand All @@ -235,7 +245,12 @@ FILE *G_fopen_modify_misc(const char *dir, const char *element,
fd = G__open_misc(dir, element, name, G_mapset(), 2);
if (fd < 0)
return (FILE *)0;
lseek(fd, 0L, SEEK_END);
if (lseek(fd, 0L, SEEK_END) == -1) {
int err = errno;
G_warning(_("File read/write operation failed: %s (%d)"), strerror(err),
err);
return (FILE *)-1;
}

return fdopen(fd, "r+");
}
14 changes: 10 additions & 4 deletions lib/gis/seek.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,20 @@ off_t G_ftell(FILE *fp)
void G_fseek(FILE *fp, off_t offset, int whence)
{
#ifdef HAVE_FSEEKO
if (fseeko(fp, offset, whence) != 0)
G_fatal_error(_("Unable to seek: %s"), strerror(errno));
if (fseeko(fp, offset, whence) != 0) {
int err = errno;
G_fatal_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
}
#else
long loff = (long)offset;

if ((off_t)loff != offset)
G_fatal_error(_("Seek offset out of range"));
if (fseek(fp, loff, whence) != 0)
G_fatal_error(_("Unable to seek: %s"), strerror(errno));
if (fseek(fp, loff, whence) != 0) {
int err = errno;
G_fatal_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
}
#endif
}
15 changes: 15 additions & 0 deletions lib/raster/close.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,11 @@ static int close_new(int fd, int ok)
if (fcb->null_row_ptr) { /* compressed nulls */
fcb->null_row_ptr[fcb->cellhd.rows] =
lseek(fcb->null_fd, 0L, SEEK_CUR);
if (fcb->null_row_ptr[fcb->cellhd.rows] == -1) {
int err = errno;
G_fatal_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
}
Rast__write_null_row_ptrs(fd, fcb->null_fd);
}

Expand Down Expand Up @@ -437,6 +442,11 @@ static int close_new(int fd, int ok)

if (fcb->open_mode == OPEN_NEW_COMPRESSED) { /* auto compression */
fcb->row_ptr[fcb->cellhd.rows] = lseek(fcb->data_fd, 0L, SEEK_CUR);
if (fcb->row_ptr[fcb->cellhd.rows] == -1) {
int err = errno;
G_fatal_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
}
Rast__write_row_ptrs(fd);
}

Expand Down Expand Up @@ -531,6 +541,11 @@ void Rast__close_null(int fd)

if (fcb->null_row_ptr) { /* compressed nulls */
fcb->null_row_ptr[fcb->cellhd.rows] = lseek(fcb->null_fd, 0L, SEEK_CUR);
if (fcb->null_row_ptr[fcb->cellhd.rows] == -1) {
int err = errno;
G_fatal_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
}
Rast__write_null_row_ptrs(fd, fcb->null_fd);
G_free(fcb->null_row_ptr);
}
Expand Down
6 changes: 5 additions & 1 deletion lib/raster/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ static int write_row_ptrs(int nrows, off_t *row_ptr, int fd)
unsigned char *buf, *b;
int len, row, result;

lseek(fd, 0L, SEEK_SET);
if (lseek(fd, 0L, SEEK_SET) == -1) {
int err = errno;
G_fatal_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
}

len = (nrows + 1) * nbytes + 1;
b = buf = G_malloc(len);
Expand Down
8 changes: 4 additions & 4 deletions lib/raster/get_row.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static void read_data_fp_compressed(int fd, int row, unsigned char *data_buf,
size_t bufsize = fcb->cellhd.cols * fcb->nbytes;
int ret;

if (lseek(fcb->data_fd, t1, SEEK_SET) < 0)
if (lseek(fcb->data_fd, t1, SEEK_SET) == -1)
G_fatal_error(
_("Error seeking fp raster data file for row %d of <%s>: %s"), row,
fcb->name, strerror(errno));
Expand Down Expand Up @@ -138,7 +138,7 @@ static void read_data_compressed(int fd, int row, unsigned char *data_buf,
unsigned char *cmp, *cmp2;
int n;

if (lseek(fcb->data_fd, t1, SEEK_SET) < 0)
if (lseek(fcb->data_fd, t1, SEEK_SET) == -1)
G_fatal_error(
_("Error seeking raster data file for row %d of <%s>: %s"), row,
fcb->name, strerror(errno));
Expand Down Expand Up @@ -854,7 +854,7 @@ static int read_null_bits_compressed(int null_fd, unsigned char *flags, int row,
unsigned char *compressed_buf;
int res;

if (lseek(null_fd, t1, SEEK_SET) < 0)
if (lseek(null_fd, t1, SEEK_SET) == -1)
G_fatal_error(
_("Error seeking compressed null data for row %d of <%s>"), row,
fcb->name);
Expand Down Expand Up @@ -914,7 +914,7 @@ int Rast__read_null_bits(int fd, int row, unsigned char *flags)

offset = (off_t)size * R;

if (lseek(null_fd, offset, SEEK_SET) < 0)
if (lseek(null_fd, offset, SEEK_SET) == -1)
G_fatal_error(_("Error seeking null row %d for <%s>"), R, fcb->name);

if (read(null_fd, flags, size) != size)
Expand Down
12 changes: 11 additions & 1 deletion lib/raster/put_row.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ static void set_file_pointer(int fd, int row)
struct fileinfo *fcb = &R__.fileinfo[fd];

fcb->row_ptr[row] = lseek(fcb->data_fd, 0L, SEEK_CUR);
if (fcb->row_ptr[row] == -1) {
int err = errno;
G_fatal_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
}
}

static void convert_float(float *work_buf, char *null_buf, const FCELL *rast,
Expand Down Expand Up @@ -514,6 +519,11 @@ static void write_null_bits_compressed(const unsigned char *flags, int row,
int res;

fcb->null_row_ptr[row] = lseek(fcb->null_fd, 0L, SEEK_CUR);
if (fcb->null_row_ptr[row] == -1) {
int err = errno;
G_fatal_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
}

/* get upper bound of compressed size */
cmax = G_compress_bound(size, 3);
Expand Down Expand Up @@ -567,7 +577,7 @@ void Rast__write_null_bits(int fd, const unsigned char *flags)

offset = (off_t)size * row;

if (lseek(fcb->null_fd, offset, SEEK_SET) < 0)
if (lseek(fcb->null_fd, offset, SEEK_SET) == -1)
G_fatal_error(_("Error writing null row %d of <%s>"), row, fcb->name);

if ((res = write(fcb->null_fd, flags, size)) < 0 ||
Expand Down
9 changes: 9 additions & 0 deletions lib/raster3d/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include <grass/raster3d.h>
#include <grass/glocale.h>
#include "raster3d_intern.h"
Expand Down Expand Up @@ -295,6 +298,12 @@ void *Rast3d_open_cell_new(const char *name, int typeIntern, int cache,

/* can't use a constant since this depends on sizeof (long) */
nofHeaderBytes = lseek(map->data_fd, (long)0, SEEK_CUR);
if (nofHeaderBytes == -1) {
int err = errno;
Rast3d_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
return (void *)NULL;
}

Rast3d_range_init(map);
Rast3d_adjust_region(region);
Expand Down
9 changes: 9 additions & 0 deletions lib/raster3d/tilewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/glocale.h>

#include "raster3d_intern.h"

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -173,6 +177,11 @@ int Rast3d_write_tile(RASTER3D_Map *map, int tileIndex, const void *tile,
/* compute the length */
map->tileLength[tileIndex] =
lseek(map->data_fd, (long)0, SEEK_END) - map->index[tileIndex];
if (map->tileLength[tileIndex] == -1) {
int err = errno;
G_fatal_error(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
}

return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/segment/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static int seg_format(int fd, off_t nrows, off_t ncols, int srows, int scols,
}
}

if (lseek(fd, 0L, SEEK_SET) == (off_t)-1) {
if (lseek(fd, 0L, SEEK_SET) == -1) {
int err = errno;

G_warning("Segment_format(): Unable to seek (%s)", strerror(err));
Expand Down Expand Up @@ -258,7 +258,7 @@ static int seek_only(int fd, off_t nbytes)

G_debug(3, "Using new segmentation code...");
errno = 0;
if (lseek(fd, nbytes - 1, SEEK_CUR) < 0) {
if (lseek(fd, nbytes - 1, SEEK_CUR) == -1) {
int err = errno;

G_warning("segment zero_fill(): Unable to seek (%s)", strerror(err));
Expand Down
17 changes: 15 additions & 2 deletions lib/segment/get_row.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include <grass/gis.h>
#include <grass/glocale.h>

#include "local_proto.h"

/**
Expand Down Expand Up @@ -57,7 +60,12 @@ int Segment_get_row(const SEGMENT *SEG, void *buf, off_t row)

for (col = 0; col < ncols; col += scols) {
SEG->address(SEG, row, col, &n, &index);
SEG->seek(SEG, n, index);
if (SEG->seek(SEG, n, index) == -1) {
int err = errno;
G_warning(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
return -1;
}

if (read(SEG->fd, buf, size) != size) {
G_warning("Segment_get_row: %s", strerror(errno));
Expand All @@ -73,7 +81,12 @@ int Segment_get_row(const SEGMENT *SEG, void *buf, off_t row)
}
if ((size = SEG->spill * SEG->len)) {
SEG->address(SEG, row, col, &n, &index);
SEG->seek(SEG, n, index);
if (SEG->seek(SEG, n, index) == -1) {
int err = errno;
G_warning(_("File read/write operation failed: %s (%d)"),
strerror(err), err);
return -1;
}

if (read(SEG->fd, buf, size) != size) {
G_warning("Segment_get_row: %s", strerror(errno));
Expand Down
2 changes: 1 addition & 1 deletion lib/segment/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int Segment_init(SEGMENT *SEG, int fd, int nseg)
SEG->fd = fd;
SEG->nseg = nseg;

if (lseek(fd, 0L, SEEK_SET) < 0) {
if (lseek(fd, 0L, SEEK_SET) == -1) {
int err = errno;

G_warning("Segment_init: %s", strerror(err));
Expand Down
4 changes: 4 additions & 0 deletions lib/segment/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@

#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>

#include <grass/gis.h>
#include <grass/glocale.h>

Comment on lines +16 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this file only changing the includes? Were there some changes before, but no real ones after updating the PR with main?

#include "local_proto.h"

/**
Expand Down
Loading
Loading