GRASS Programmer's Manual  6.4.2(2012)
rowio/setup.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <grass/rowio.h>
00004 
00005 
00028 int rowio_setup(ROWIO * R,
00029                 int fd, int nrows, int len,
00030                 int (*getrow) (int, void *, int, int),
00031                 int (*putrow) (int, const void *, int, int))
00032 {
00033     int i;
00034 
00035     R->getrow = getrow;
00036     R->putrow = putrow;
00037     R->nrows = nrows;
00038     R->len = len;
00039     R->cur = -1;
00040     R->buf = NULL;
00041     R->fd = fd;
00042 
00043     R->rcb = (struct ROWIO_RCB *)malloc(nrows * sizeof(struct ROWIO_RCB));
00044     if (R->rcb == NULL) {
00045         fprintf(stderr, "rowio_setup: out of memory\n");
00046         return -1;
00047     }
00048     for (i = 0; i < nrows; i++) {
00049         R->rcb[i].buf = malloc(len);
00050         if (R->rcb[i].buf == NULL) {
00051             fprintf(stderr, "rowio_setup: out of memory\n");
00052             return -1;
00053         }
00054         R->rcb[i].row = -1;     /* mark not used */
00055     }
00056     return 1;
00057 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines