release.c 947 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * \file release.c
  3. *
  4. * \brief Segment release 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-2006
  12. */
  13. #include <stdlib.h>
  14. #include <grass/segment.h>
  15. /**
  16. * \fn int segment_release (SEGMENT *SEG)
  17. *
  18. * \brief Free memory allocated to segment.
  19. *
  20. * Releases the allocated memory associated with the segment file
  21. * <b>seg</b>.
  22. *
  23. * <b>Note:</b> Does not close the file. Does not flush the data which
  24. * may be pending from previous <i>segment_put()</i> calls.
  25. *
  26. * \param[in,out] seg
  27. * \return 1 if successful
  28. * \return -1 if segment is not available (not open)
  29. */
  30. int segment_release(SEGMENT * SEG)
  31. {
  32. int i;
  33. if (SEG->open != 1)
  34. return -1;
  35. for (i = 0; i < SEG->nseg; i++)
  36. free(SEG->scb[i].buf);
  37. free(SEG->scb);
  38. SEG->open = 0;
  39. return 1;
  40. }