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