GRASS GIS 7 Programmer's Manual  7.0.5(2016)-r00000
get_row.c
Go to the documentation of this file.
1 
15 #include <stdio.h>
16 #include <unistd.h>
17 #include <string.h>
18 #include <errno.h>
19 #include <grass/gis.h>
20 #include "local_proto.h"
21 
22 
43 int Segment_get_row(const SEGMENT * SEG, void *buf, off_t row)
44 {
45  int size;
46  off_t ncols, col;
47  int scols;
48  int n, index;
49 
50  ncols = SEG->ncols - SEG->spill;
51  scols = SEG->scols;
52  size = scols * SEG->len;
53 
54  for (col = 0; col < ncols; col += scols) {
55  SEG->address(SEG, row, col, &n, &index);
56  SEG->seek(SEG, n, index);
57 
58  if (read(SEG->fd, buf, size) != size) {
59  G_warning("Segment_get_row: %s", strerror(errno));
60  return -1;
61  }
62 
63  /* The buf variable is a void pointer and thus points to anything. */
64  /* Therefore, it's size is unknown and thus, it cannot be used for */
65  /* pointer arithmetic (some compilers treat this as an error - SGI */
66  /* MIPSPro compiler for one). Since the read command is reading in */
67  /* "size" bytes, cast the buf variable to char * before incrementing */
68  buf = ((char *)buf) + size;
69  }
70  if ((size = SEG->spill * SEG->len)) {
71  SEG->address(SEG, row, col, &n, &index);
72  SEG->seek(SEG, n, index);
73 
74  if (read(SEG->fd, buf, size) != size) {
75  G_warning("Segment_get_row: %s", strerror(errno));
76  return -1;
77  }
78  }
79 
80  return 1;
81 }
int Segment_get_row(const SEGMENT *SEG, void *buf, off_t row)
Definition: get_row.c:43
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition: gis/error.c:203