GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
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-2018
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
if
(SEG->
cache
) {
50
memcpy(SEG->
cache
+ ((
size_t
)row * SEG->
ncols
+ col) * SEG->
len
, buf, SEG->
len
);
51
52
return
1;
53
}
54
55
SEG->
address
(SEG, row, col, &n, &index);
56
if
((i =
seg_pagein
(SEG, n)) < 0) {
57
G_warning
(
"segment lib: put: pagein failed"
);
58
return
-1;
59
}
60
61
SEG->
scb
[i].
dirty
= 1;
62
63
memcpy(&SEG->
scb
[i].
buf
[index], buf, SEG->
len
);
64
65
return
1;
66
}
SEGMENT::address
int(* address)()
Definition:
segment.h:40
SEGMENT::len
int len
Definition:
segment.h:24
gis.h
SEGMENT::scb::buf
char * buf
Definition:
segment.h:47
SEGMENT::ncols
off_t ncols
Definition:
segment.h:23
SEGMENT::scb::dirty
char dirty
Definition:
segment.h:48
Segment_put
int Segment_put(SEGMENT *SEG, const void *buf, off_t row, off_t col)
Definition:
segment/put.c:45
SEGMENT::cache
char * cache
Definition:
segment.h:62
G_warning
void G_warning(const char *,...) __attribute__((format(printf
seg_pagein
int seg_pagein(SEGMENT *SEG, int n)
Internal use only.
Definition:
pagein.c:37
SEGMENT
Definition:
segment.h:19
SEGMENT::scb
struct SEGMENT::scb * scb
lib
segment
put.c
Generated on Tue Feb 14 2023 05:56:01 for GRASS GIS 8 Programmer's Manual by
1.8.13