close.c 925 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * \file lib/segment/close.c
  3. *
  4. * \brief Segment closing routine.
  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 2012
  12. */
  13. #include <unistd.h>
  14. #include <fcntl.h>
  15. #include <grass/gis.h>
  16. #include <grass/glocale.h>
  17. #include "local_proto.h"
  18. /**
  19. * \fn int segment_close (SEGMENT *SEG)
  20. *
  21. * \brief Free memory allocated to segment, delete temp file.
  22. *
  23. * Releases the allocated memory associated with the segment file
  24. * <b>seg</b> and deletes the temporary file.
  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_close(SEGMENT *SEG)
  31. {
  32. if (SEG->open != 1)
  33. return -1;
  34. segment_release(SEG);
  35. close(SEG->fd);
  36. unlink(SEG->fname);
  37. SEG->fd = -1;
  38. SEG->fname = NULL;
  39. return 1;
  40. }