GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71933
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
segment/put.c
Go to the documentation of this file.
1 
2 /**
3  * \file lib/segment/put.c
4  *
5  * \brief Segment write routines.
6  *
7  * This program is free software under the GNU General Public License
8  * (>=v2). Read the file COPYING that comes with GRASS for details.
9  *
10  * \author GRASS GIS Development Team
11  *
12  * \date 2005-2009
13  */
14 
15 #include <string.h>
16 #include <grass/gis.h>
17 #include "local_proto.h"
18 
19 
20 /*bugfix: buf: char* vs int* -> wrong pointer arithmetics!!!. Pierre de Mouveaux - 09 april 2000 */
21 /* int Segment_put (SEGMENT *SEG,int *buf,int row,int col) */
22 
23 
24 /**
25  * \fn int Segment_put (SEGMENT *SEG, void *buf, int row, int col)
26  *
27  * \brief Write value to segment file.
28  *
29  * Provides random write access to the segmented data. It
30  * copies <i>len</i> bytes of data from <b>buf</b> into the segment
31  * structure <b>seg</b> for the corresponding <b>row</b> and <b>col</b> in
32  * the original data matrix.
33  *
34  * The data is not written to disk immediately. It is stored in a memory segment
35  * until the segment routines decide to page the segment to disk.
36  *
37  * \param[in,out] seg segment
38  * \param[in] buf value to write to segment
39  * \param[in] row
40  * \param[in] col
41  * \return 1 if successful
42  * \return -1 if unable to seek or write segment file
43  */
44 
45 int Segment_put(SEGMENT * SEG, const void *buf, off_t row, off_t col)
46 {
47  int index, n, i;
48 
49  SEG->address(SEG, row, col, &n, &index);
50  if ((i = seg_pagein(SEG, n)) < 0) {
51  G_warning("segment lib: put: pagein failed");
52  return -1;
53  }
54 
55  SEG->scb[i].dirty = 1;
56 
57  memcpy(&SEG->scb[i].buf[index], buf, SEG->len);
58 
59  return 1;
60 }
int len
Definition: segment.h:24
char * buf
Definition: segment.h:47
int(* address)()
Definition: segment.h:40
char dirty
Definition: segment.h:48
int Segment_put(SEGMENT *SEG, const void *buf, off_t row, off_t col)
Definition: segment/put.c:45
int seg_pagein(SEGMENT *SEG, int n)
Internal use only.
Definition: pagein.c:37
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition: gis/error.c:203
struct SEGMENT::scb * scb