put.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * \file lib/segment/put.c
  3. *
  4. * \brief Segment write routines.
  5. *
  6. * This program is free software under the GNU General Public License
  7. * (>=v2). Read the file COPYING that comes with GRASS for details.
  8. *
  9. * \author GRASS GIS Development Team
  10. *
  11. * \date 2005-2009
  12. */
  13. #include <string.h>
  14. #include <grass/gis.h>
  15. #include "local_proto.h"
  16. /*bugfix: buf: char* vs int* -> wrong pointer arithmetics!!!. Pierre de Mouveaux - 09 april 2000 */
  17. /* int segment_put (SEGMENT *SEG,int *buf,int row,int col) */
  18. /**
  19. * \fn int segment_put (SEGMENT *SEG, void *buf, int row, int col)
  20. *
  21. * \brief Write value to segment file.
  22. *
  23. * Provides random write access to the segmented data. It
  24. * copies <i>len</i> bytes of data from <b>buf</b> into the segment
  25. * structure <b>seg</b> for the corresponding <b>row</b> and <b>col</b> in
  26. * the original data matrix.
  27. *
  28. * The data is not written to disk immediately. It is stored in a memory segment
  29. * until the segment routines decide to page the segment to disk.
  30. *
  31. * \param[in,out] seg segment
  32. * \param[in] buf value to write to segment
  33. * \param[in] row
  34. * \param[in] col
  35. * \return 1 if successful
  36. * \return -1 if unable to seek or write segment file
  37. */
  38. int segment_put(SEGMENT * SEG, const void *buf, off_t row, off_t col)
  39. {
  40. int index, n, i;
  41. SEG->segment_address(SEG, row, col, &n, &index);
  42. if ((i = segment_pagein(SEG, n)) < 0) {
  43. G_warning("segment lib: put: pagein failed");
  44. return -1;
  45. }
  46. SEG->scb[i].dirty = 1;
  47. memcpy(&SEG->scb[i].buf[index], buf, SEG->len);
  48. return 1;
  49. }