GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
segment/setup.c
Go to the documentation of this file.
1 
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <grass/gis.h>
18 #include <grass/segment.h>
19 
20 
35 int segment_setup(SEGMENT * SEG)
36 {
37  int i;
38 
39  SEG->open = 0;
40 
41  if (SEG->nrows <= 0 || SEG->ncols <= 0
42  || SEG->srows <= 0 || SEG->scols <= 0
43  || SEG->len <= 0 || SEG->nseg <= 0) {
44  G_warning("segment_setup: illegal segment file parameters\n");
45  return -1;
46  }
47 
48  /* This is close to the beginning of the file, so doesn't need to be an off_t */
49  SEG->offset = (int)lseek(SEG->fd, 0L, SEEK_CUR);
50 
51  SEG->spr = SEG->ncols / SEG->scols;
52  SEG->spill = SEG->ncols % SEG->scols;
53  if (SEG->spill)
54  SEG->spr++;
55 
56  if ((SEG->scb =
57  (struct SEGMENT_SCB *)G_malloc(SEG->nseg *
58  sizeof(struct SEGMENT_SCB))) == NULL)
59  return -2;
60 
61  SEG->size = SEG->srows * SEG->scols * SEG->len;
62 
63  for (i = 0; i < SEG->nseg; i++) {
64  if ((SEG->scb[i].buf = G_malloc(SEG->size)) == NULL)
65  return -2;
66 
67  SEG->scb[i].n = -1; /* mark free */
68  SEG->scb[i].dirty = 0;
69  SEG->scb[i].age = 0;
70  }
71  SEG->cur = 0;
72  SEG->open = 1;
73 
74  return 1;
75 }
int segment_setup(SEGMENT *SEG)
Setup segment.
Definition: segment/setup.c:35
int
Definition: g3dcolor.c:48
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)