put.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * \file 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/segment.h>
  15. /*bugfix: buf: char* vs int* -> wrong pointer arithmetics!!!. Pierre de Mouveaux - 09 april 2000 */
  16. /* int segment_put (SEGMENT *SEG,int *buf,int row,int col) */
  17. /**
  18. * \fn int segment_put (SEGMENT *SEG, void *buf, int row, int col)
  19. *
  20. * \brief Write value to segment file.
  21. *
  22. * Provides random write access to the segmented data. It
  23. * copies <i>len</i> bytes of data from <b>buf</b> into the segment
  24. * structure <b>seg</b> for the corresponding <b>row</b> and <b>col</b> in
  25. * the original data matrix.
  26. *
  27. * The data is not written to disk immediately. It is stored in a memory segment
  28. * until the segment routines decide to page the segment to disk.
  29. *
  30. * \param[in,out] seg segment
  31. * \param[in] buf value to write to segment
  32. * \param[in] row
  33. * \param[in] col
  34. * \return 1 if successful
  35. * \return -1 if unable to seek or write segment file
  36. */
  37. int segment_put(SEGMENT * SEG, const void *buf, int row, int col)
  38. {
  39. int index, n, i;
  40. segment_address(SEG, row, col, &n, &index);
  41. if ((i = segment_pagein(SEG, n)) < 0) {
  42. G_warning("segment lib: put: pagein failed");
  43. return -1;
  44. }
  45. SEG->scb[i].dirty = 1;
  46. memcpy(&SEG->scb[i].buf[index], buf, SEG->len);
  47. return 1;
  48. }