get.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. * \fn int segment_get (SEGMENT *SEG, void *buf, int row, int col)
  19. *
  20. * \brief Get value from segment file.
  21. *
  22. * Provides random read access to the segmented data. It gets
  23. * <i>len</i> bytes of data into <b>buf</b> from the segment file
  24. * <b>seg</b> for the corresponding <b>row</b> and <b>col</b> in the
  25. * original data matrix.
  26. *
  27. * \param[in] seg segment
  28. * \param[in,out] buf value return buffer
  29. * \param[in] row
  30. * \param[in] col
  31. * \return 1 of successful
  32. * \return -1 if unable to seek or read segment file
  33. */
  34. int segment_get(SEGMENT * SEG, void *buf, off_t row, off_t col)
  35. {
  36. int index, n, i;
  37. SEG->segment_address(SEG, row, col, &n, &index);
  38. if ((i = segment_pagein(SEG, n)) < 0)
  39. return -1;
  40. memcpy(buf, &SEG->scb[i].buf[index], SEG->len);
  41. return 1;
  42. }