GRASS 8 Programmer's Manual
8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
segment/put.c
Go to the documentation of this file.
1
/**
2
* \file lib/segment/put.c
3
*
4
* \brief Segment write routines.
5
*
6
* This program is free software under the GNU General Public License
7
* (>=v2). Read the file COPYING that comes with GRASS for details.
8
*
9
* \author GRASS Development Team
10
*
11
* \date 2005-2018
12
*/
13
14
#include <
string.h
>
15
#include <
grass/gis.h
>
16
#include "local_proto.h"
17
18
/*bugfix: buf: char* vs int* -> wrong pointer arithmetics!!!. Pierre de Mouveaux
19
* - 09 april 2000 */
20
/* int Segment_put (SEGMENT *SEG,int *buf,int row,int col) */
21
22
/**
23
* \fn int Segment_put (SEGMENT *SEG, void *buf, int row, int col)
24
*
25
* \brief Write value to segment file.
26
*
27
* Provides random write access to the segmented data. It
28
* copies <i>len</i> bytes of data from <b>buf</b> into the segment
29
* structure <b>seg</b> for the corresponding <b>row</b> and <b>col</b> in
30
* the original data matrix.
31
*
32
* The data is not written to disk immediately. It is stored in a memory segment
33
* until the segment routines decide to page the segment to disk.
34
*
35
* \param[in,out] seg segment
36
* \param[in] buf value to write to segment
37
* \param[in] row
38
* \param[in] col
39
* \return 1 if successful
40
* \return -1 if unable to seek or write segment file
41
*/
42
int
Segment_put
(
SEGMENT
*
SEG
,
const
void
*buf,
off_t
row,
off_t
col
)
43
{
44
int
index, n, i;
45
46
if
(
SEG
->cache) {
47
memcpy
(
SEG
->cache + ((
size_t
)row *
SEG
->ncols +
col
) *
SEG
->len, buf,
48
SEG
->len);
49
50
return
1;
51
}
52
53
SEG
->address(
SEG
, row,
col
, &n, &index);
54
if
((i =
seg_pagein
(
SEG
, n)) < 0) {
55
G_warning
(
"segment lib: put: pagein failed"
);
56
return
-1;
57
}
58
59
SEG
->scb[i].dirty = 1;
60
61
memcpy
(&
SEG
->scb[i].
buf
[index], buf,
SEG
->len);
62
63
return
1;
64
}
AMI_STREAM
Definition
ami_stream.h:153
UntypedStream::buf
char * buf
Definition
ami_stream.h:141
G_warning
void G_warning(const char *,...) __attribute__((format(printf
gis.h
seg_pagein
int seg_pagein(SEGMENT *SEG, int n)
Internal use only.
Definition
pagein.c:37
Segment_put
int Segment_put(SEGMENT *SEG, const void *buf, off_t row, off_t col)
Definition
segment/put.c:42
string.h
SEGMENT
Definition
segment.h:19
lib
segment
put.c
Generated on Fri Apr 3 2026 06:59:56 for GRASS 8 Programmer's Manual by
1.9.8