other.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <fcntl.h>
  2. #include <sys/stat.h>
  3. #include <sys/types.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <grass/gis.h>
  7. #include "local_proto.h"
  8. static char *filename (const char *name, const char *mapset)
  9. {
  10. static char path[GPATH_MAX];
  11. G__file_name (path, "", name, mapset);
  12. return path;
  13. }
  14. int mapset_permissions (const char *mapset)
  15. {
  16. int stat;
  17. stat = G__mapset_permissions (mapset);
  18. if (stat == 1)
  19. {
  20. if(access(filename (".lock", mapset), 0) == 0)
  21. stat = 0;
  22. }
  23. return stat;
  24. }
  25. int mapset_message (const char *mapset)
  26. {
  27. if(printfile(filename (".message", mapset)))
  28. hit_return();
  29. return 0;
  30. }
  31. int mapset_question (const char *mapset)
  32. {
  33. if(printfile(filename(".question", mapset)))
  34. return G_yes("Select this mapset? ", -1);
  35. return 1;
  36. }
  37. int printfile (const char *name)
  38. {
  39. int fd;
  40. int n;
  41. char buf[1024];
  42. fd = open (name, 0);
  43. if (fd < 0) return 0;
  44. while ((n = read (fd, buf, sizeof buf)) > 0)
  45. write (STDOUT_FILENO, buf, n);
  46. close (fd);
  47. return 1;
  48. }