GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
segment/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/segment.h>
20 
21 
42 int segment_get_row(const SEGMENT * SEG, void *buf, int row)
43 {
44  int size;
45  int ncols;
46  int scols;
47  int n, index, col;
48 
49  ncols = SEG->ncols - SEG->spill;
50  scols = SEG->scols;
51  size = scols * SEG->len;
52 
53  for (col = 0; col < ncols; col += scols) {
54  segment_address(SEG, row, col, &n, &index);
55  if (segment_seek(SEG, n, index) < 0)
56  return -1;
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  segment_address(SEG, row, col, &n, &index);
72  if (segment_seek(SEG, n, index) < 0)
73  return -1;
74 
75  if (read(SEG->fd, buf, size) != size) {
76  G_warning("segment_get_row: %s", strerror(errno));
77  return -1;
78  }
79  }
80 
81  return 1;
82 }
int segment_seek(const SEGMENT *SEG, int n, int index)
Definition: segment/seek.c:37
int segment_address(const SEGMENT *SEG, int row, int col, int *n, int *index)
Definition: address.c:31
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
int segment_get_row(const SEGMENT *SEG, void *buf, int row)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int errno
int n
Definition: dataquad.c:291