get.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * \file lib/segment/get.c
  3. *
  4. * \brief Get segment 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 "local_proto.h"
  15. /*bugfix: buf: char* vs int* -> wrong pointer arithmetics!!!. Pierre de Mouveaux - 09 april 2000 */
  16. /* int Segment_get (SEGMENT *SEG, register int *buf,int row,int col) */
  17. /**
  18. * \brief Get value from segment file.
  19. *
  20. * Provides random read access to the segmented data. It gets
  21. * <i>len</i> bytes of data into <b>buf</b> from the segment file
  22. * <b>seg</b> for the corresponding <b>row</b> and <b>col</b> in the
  23. * original data matrix.
  24. *
  25. * \param[in] SEG segment
  26. * \param[in,out] buf value return buffer
  27. * \param[in] row
  28. * \param[in] col
  29. * \return 1 of successful
  30. * \return -1 if unable to seek or read segment file
  31. */
  32. int Segment_get(SEGMENT * SEG, void *buf, off_t row, off_t col)
  33. {
  34. int index, n, i;
  35. SEG->address(SEG, row, col, &n, &index);
  36. if ((i = seg_pagein(SEG, n)) < 0)
  37. return -1;
  38. memcpy(buf, &SEG->scb[i].buf[index], SEG->len);
  39. return 1;
  40. }