GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
segment/init.c
Go to the documentation of this file.
1 
2 /****************************************************************************
3  *
4  * MODULE: segment
5  * AUTHOR(S): CERL
6  * Bernhard Reiter <bernhard intevation.de>,
7  * Brad Douglas <rez touchofmadness.com>,
8  * Glynn Clements <glynn gclements.plus.com>,
9  * Markus Neteler <neteler itc.it>
10  * PURPOSE: Segment initialization routines
11  * COPYRIGHT: (C) 2000-2006 by the GRASS Development Team
12  *
13  * This program is free software under the GNU General Public
14  * License (>=v2). Read the file COPYING that comes with GRASS
15  * for details.
16  *
17  *****************************************************************************/
18 
19 #include <stdio.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <errno.h>
23 #include <grass/segment.h>
24 
25 
26 static int read_int(int, int *);
27 
28 /* fd must be open for read and write */
29 
30 
56 int segment_init(SEGMENT * SEG, int fd, int nseg)
57 {
58  SEG->open = 0;
59  SEG->fd = fd;
60  SEG->nseg = nseg;
61 
62  if (lseek(fd, 0L, SEEK_SET) < 0) {
63  G_warning("segment_init: %s", strerror(errno));
64  return -1;
65  }
66 
67  /* read the header */
68  if (!read_int(fd, &SEG->nrows)
69  || !read_int(fd, &SEG->ncols)
70  || !read_int(fd, &SEG->srows)
71  || !read_int(fd, &SEG->scols)
72  || !read_int(fd, &SEG->len))
73  return -1;
74 
75  return segment_setup(SEG);
76 }
77 
78 
79 static int read_int(int fd, int *n)
80 {
81  int bytes_read;
82 
83  if ((bytes_read = read(fd, n, sizeof(int))) == -1)
84  G_warning("read_int: %s", strerror(errno));
85 
86  bytes_read = (bytes_read == sizeof(int));
87 
88  return bytes_read;
89 }
int segment_setup(SEGMENT *SEG)
Setup segment.
Definition: segment/setup.c:35
FILE * fd
Definition: g3dcolor.c:368
int segment_init(SEGMENT *SEG, int fd, int nseg)
Initialize segment structure.
Definition: segment/init.c:56
int
Definition: g3dcolor.c:48
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int errno
int n
Definition: dataquad.c:291