File: setup.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (58 lines) | stat: -rw-r--r-- 1,613 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include "rowio.h"


/*!
 * \brief configure rowio structure
 *
 * Rowio_setup()
 * initializes the ROWIO structure <b>r</b> and allocates the required memory
 * buffers. The file descriptor <b>fd</b> must be open for reading. The number
 * of rows to be held in memory is <b>nrows.</b> The length in bytes of each
 * row is <b>len.</b> The routine which will be called to read data from the
 * file is <b>getrow()</b> and must be provided by the programmer. If the
 * application requires that the rows be written back into the file if changed,
 * the file descriptor <b>fd</b> must be open for write as well, and the
 * programmer must provide a <b>putrow()</b> routine to write the data into
 * the file. If no writing of the file is to occur, specify NULL for
 * <b>putrow().</b>
 * Return codes:
 * 1 ok 
 * -1 there is not enough memory for buffer allocation
 *
 *  \param 
 *  \return int
 */

int rowio_setup (ROWIO *R,int fd, int nrows, int len,
                 int (*getrow)(), int (*putrow)())
{
    int i;
    char *malloc();

    R->getrow = getrow;
    R->putrow = putrow;
    R->nrows = nrows;
    R->len = len;
    R->cur = -1;
    R->buf = NULL;
    R->fd = fd;

    R->rcb = (struct ROWIO_RCB *) malloc (nrows * sizeof(struct ROWIO_RCB));
    if (R->rcb == NULL)
    {
	fprintf (stderr, "rowio_setup: out of memory\n");
	return -1;
    }
    for (i = 0; i < nrows; i++)
    {
	R->rcb[i].buf = malloc (len);
	if (R->rcb[i].buf == NULL)
	{
	    fprintf (stderr, "rowio_setup: out of memory\n");
	    return -1;
	}
	R->rcb[i].row = -1;	/* mark not used */
    }
    return 1;
}