mapset.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**********************************************************************
  2. *
  3. * char *
  4. * G_mapset()
  5. *
  6. * returns: pointer to string containing the one word mapset
  7. * name.
  8. * NULL if user does not have access to mapset.
  9. *
  10. **********************************************************************/
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <grass/gis.h>
  14. #include <grass/glocale.h>
  15. /*!
  16. * \brief current mapset name
  17. *
  18. * Returns the name of the
  19. * current mapset in the current location. This routine is often used when
  20. * accessing files in the current mapset. See Mapsets for an
  21. * explanation of mapsets.
  22. *
  23. * \param void
  24. * \return char *
  25. */
  26. char *G_mapset(void)
  27. {
  28. static char mapset[GMAPSET_MAX];
  29. static int first = 1;
  30. char *m;
  31. m = G__mapset();
  32. if (m == NULL)
  33. G_fatal_error(_("MAPSET is not set"));
  34. if (first)
  35. first = 0;
  36. else if (strcmp(mapset, m) == 0)
  37. return mapset;
  38. strcpy(mapset, m);
  39. switch (G__mapset_permissions(mapset)) {
  40. case 0:
  41. case 1:
  42. return mapset;
  43. /*
  44. case 0:
  45. G_fatal_error ("MAPSET %s - permission denied", mapset);
  46. break;
  47. */
  48. default:
  49. G_fatal_error(_("MAPSET %s not found"), mapset);
  50. break;
  51. }
  52. exit(EXIT_FAILURE);
  53. }
  54. char *G__mapset(void)
  55. {
  56. return G__getenv("MAPSET");
  57. }