GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-535c39c9fc
rowio/put.c
Go to the documentation of this file.
1 /*!
2  \file rowio/put.c
3 
4  \brief RowIO library - Write a row
5 
6  (C) 2001-2009 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Original author CERL
12  */
13 
14 #include <stdio.h>
15 #include <string.h>
16 #include <grass/rowio.h>
17 
18 /*!
19  * \brief Write a row
20  *
21  * Writes the buffer <i>buf</i>, which holds the data for row
22  * <i>n</i>, into the ROWIO structure <i>r</i>. If the row requested
23  * is currently in memory, the buffer is simply copied into the
24  * structure and marked as having been changed. It will be written out
25  * later. Otherwise it is written immediately. Note that when the row
26  * is finally written to disk, the putrow() routine specified in
27  * Rowio_setup() is called to write row <i>n</i> to the
28  * file. Rowio_flush() force pending updates to disk ROWIO *r;
29  * Rowio_flush() forces all rows modified by Rowio_put() to be
30  * written to the file. This routine must be called before closing the
31  * file or releasing the rowio structure if Rowio_put() has been
32  * called.
33  *
34  * \param R pointer to ROWIO structure
35  * \param buf pointer to data buffer
36  * \param row row number
37  *
38  * \return
39  */
40 
41 int Rowio_put(ROWIO *R, const void *buf, int row)
42 {
43  int i;
44 
45  if (row < 0)
46  return 0;
47 
48  for (i = 0; i < R->nrows; i++)
49  if (row == R->rcb[i].row) {
50  memcpy(R->rcb[i].buf, buf, R->len);
51  R->rcb[i].dirty = 1;
52  return 1;
53  }
54  return ((*R->putrow)(R->fd, buf, row, R->len));
55 }
int Rowio_put(ROWIO *R, const void *buf, int row)
Write a row.
Definition: rowio/put.c:41
void * buf
Definition: rowio.h:15
Definition: rowio.h:4
int len
Definition: rowio.h:7
struct ROWIO::ROWIO_RCB * rcb
int fd
Definition: rowio.h:5
int(* putrow)(int, const void *, int, int)
Definition: rowio.h:11
int nrows
Definition: rowio.h:6