GRASS 8 Programmer's Manual
8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
rowio/setup.c
Go to the documentation of this file.
1
/*!
2
\file rowio/setup.c
3
4
\brief RowIO library - Setup
5
6
SPDX-FileCopyrightText: 2001-2009 GRASS Development Team
7
SPDX-License-Identifier: GPL-2.0-or-later
8
9
\author Original author CERL
10
*/
11
12
#include <
stdio.h
>
13
#include <
stdlib.h
>
14
#include <
grass/gis.h
>
15
#include <
grass/glocale.h
>
16
#include <
grass/rowio.h
>
17
18
/*!
19
* \brief Configure rowio structure
20
*
21
* Rowio_setup() initializes the ROWIO structure <i>r</i> and
22
* allocates the required memory buffers. The file descriptor
23
* <i>fd</i> must be open for reading. The number of rows to be held
24
* in memory is <i>nrows</i>. The length in bytes of each row is
25
* <i>len</i>. The routine which will be called to read data from the
26
* file is getrow() and must be provided by the programmer. If the
27
* application requires that the rows be written back into the file if
28
* changed, the file descriptor <i>fd</i> must be open for write as
29
* well, and the programmer must provide a putrow() routine to write
30
* the data into the file. If no writing of the file is to occur,
31
* specify NULL for putrow().
32
*
33
* \param R pointer to ROWIO structure
34
* \param fd file descriptor
35
* \param nrows number of rows
36
* \param getrow get row function
37
*
38
* \return 1 on success
39
* \return -1 no memory
40
*/
41
int
Rowio_setup
(
ROWIO
*R,
int
fd,
int
nrows,
int
len,
42
int
(*getrow)(
int
,
void
*,
int
,
int
),
43
int
(*putrow)(
int
,
const
void
*,
int
,
int
))
44
{
45
int
i;
46
47
R->
getrow
= getrow;
48
R->
putrow
= putrow;
49
R->
nrows
= nrows;
50
R->
len
= len;
51
R->
cur
= -1;
52
R->
buf
=
NULL
;
53
R->
fd
= fd;
54
55
R->
rcb
= (
struct
ROWIO_RCB *)
G_malloc
(nrows *
sizeof
(
struct
ROWIO_RCB));
56
if
(R->
rcb
==
NULL
) {
57
G_warning
(
_
(
"Out of memory"
));
58
return
-1;
59
}
60
for
(i = 0; i < nrows; i++) {
61
R->
rcb
[i].
buf
=
G_malloc
(len);
62
if
(R->
rcb
[i].
buf
==
NULL
) {
63
G_warning
(
_
(
"Out of memory"
));
64
return
-1;
65
}
66
R->
rcb
[i].row = -1;
/* mark not used */
67
}
68
return
1;
69
}
NULL
#define NULL
Definition
ccmath.h:32
UntypedStream::buf
char * buf
Definition
ami_stream.h:141
G_warning
void G_warning(const char *,...) __attribute__((format(printf
G_malloc
#define G_malloc(n)
Definition
defs/gis.h:136
gis.h
glocale.h
_
#define _(str)
Definition
glocale.h:10
Rowio_setup
int Rowio_setup(ROWIO *R, int fd, int nrows, int len, int(*getrow)(int, void *, int, int), int(*putrow)(int, const void *, int, int))
Configure rowio structure.
Definition
rowio/setup.c:41
rowio.h
stdio.h
stdlib.h
ROWIO
Definition
rowio.h:4
ROWIO::buf
void * buf
Definition
rowio.h:9
ROWIO::len
int len
Definition
rowio.h:7
ROWIO::getrow
int(* getrow)(int, void *, int, int)
Definition
rowio.h:10
ROWIO::rcb
struct ROWIO::ROWIO_RCB * rcb
ROWIO::fd
int fd
Definition
rowio.h:5
ROWIO::putrow
int(* putrow)(int, const void *, int, int)
Definition
rowio.h:11
ROWIO::nrows
int nrows
Definition
rowio.h:6
ROWIO::cur
int cur
Definition
rowio.h:8
lib
rowio
setup.c
Generated on Sun Sep 13 2026 06:57:48 for GRASS 8 Programmer's Manual by
1.9.8