GRASS GIS 8 Programmer's Manual 8.4.1(2025)-45ca3179ab
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 GIS 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
43int Segment_put(SEGMENT *SEG, const void *buf, off_t row, off_t col)
44{
45 int index, n, i;
46
47 if (SEG->cache) {
48 memcpy(SEG->cache + ((size_t)row * SEG->ncols + col) * SEG->len, buf,
49 SEG->len);
50
51 return 1;
52 }
53
54 SEG->address(SEG, row, col, &n, &index);
55 if ((i = seg_pagein(SEG, n)) < 0) {
56 G_warning("segment lib: put: pagein failed");
57 return -1;
58 }
59
60 SEG->scb[i].dirty = 1;
61
62 memcpy(&SEG->scb[i].buf[index], buf, SEG->len);
63
64 return 1;
65}
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition gis/error.c:203
int seg_pagein(SEGMENT *SEG, int n)
Internal use only.
Definition pagein.c:35
int Segment_put(SEGMENT *SEG, const void *buf, off_t row, off_t col)
Definition segment/put.c:43