put.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. \file rowio/put.c
  3. \brief RowIO library - Write a row
  4. (C) 2001-2009 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Original author CERL
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <grass/rowio.h>
  12. /*!
  13. * \brief Write a row
  14. *
  15. * Writes the buffer <i>buf</i>, which holds the data for row
  16. * <i>n</i>, into the ROWIO structure <i>r</i>. If the row requested
  17. * is currently in memory, the buffer is simply copied into the
  18. * structure and marked as having been changed. It will be written out
  19. * later. Otherwise it is written immediately. Note that when the row
  20. * is finally written to disk, the putrow() routine specified in
  21. * Rowio_setup() is called to write row <i>n</i> to the
  22. * file. Rowio_flush() force pending updates to disk ROWIO *r;
  23. * Rowio_flush() forces all rows modified by Rowio_put() to be
  24. * written to the file. This routine must be called before closing the
  25. * file or releasing the rowio structure if Rowio_put() has been
  26. * called.
  27. *
  28. * \param R pointer to ROWIO structure
  29. * \param buf pointer to data buffer
  30. * \param row row number
  31. *
  32. * \return
  33. */
  34. int Rowio_put(ROWIO * R, const void *buf, int row)
  35. {
  36. int i;
  37. if (row < 0)
  38. return 0;
  39. for (i = 0; i < R->nrows; i++)
  40. if (row == R->rcb[i].row) {
  41. memcpy(R->rcb[i].buf, buf, R->len);
  42. R->rcb[i].dirty = 1;
  43. return 1;
  44. }
  45. return ((*R->putrow) (R->fd, buf, row, R->len));
  46. }