put.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <grass/rowio.h>
  4. /*!
  5. * \brief write a row
  6. *
  7. * Rowio_put()
  8. * writes the buffer <b>buf</b>, which holds the data for row <b>n</b>, into
  9. * the ROWIO structure <b>r.</b> If the row requested is currently in memory,
  10. * the buffer is simply copied into the structure and marked as having been
  11. * changed. It will be written out later. Otherwise it is written immediately.
  12. * Note that when the row is finally written to disk, the <b>putrow()</b>
  13. * routine specified in <i>rowio_setup</i> is called to write row <b>n</b>
  14. * to the file. <b>rowio_flush</b> ( r) force pending updates to disk ROWIO *r;
  15. * Rowio_flush() forces all rows modified by <i>rowio_put</i> to be written
  16. * to the file. This routine must be called before closing the file or releasing
  17. * the rowio structure if rowio_put() has been called.
  18. *
  19. * \param r
  20. * \param buf
  21. * \param n
  22. * \return int
  23. */
  24. int rowio_put(ROWIO * R, const void *buf, int row)
  25. {
  26. int i;
  27. if (row < 0)
  28. return 0;
  29. for (i = 0; i < R->nrows; i++)
  30. if (row == R->rcb[i].row) {
  31. memcpy(R->rcb[i].buf, buf, R->len);
  32. R->rcb[i].dirty = 1;
  33. return 1;
  34. }
  35. return ((*R->putrow) (R->fd, buf, row, R->len));
  36. }