chk_dbase.c 884 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #include <sys/stat.h>
  5. #ifndef __MINGW32__
  6. # include <pwd.h>
  7. #endif
  8. int can_make_location (char *gisdbase, char *location)
  9. {
  10. struct stat s;
  11. struct passwd *pwd;
  12. /* make sure this is a directory */
  13. if (stat (gisdbase, &s) != 0)
  14. {
  15. fprintf (stderr, "\n** %s not found **\n", gisdbase);
  16. return 0;
  17. }
  18. if (!(s.st_mode & S_IFDIR))
  19. {
  20. fprintf (stderr, "\n** %s is not a directory **\n", gisdbase);
  21. return 0;
  22. }
  23. /* look for write permission */
  24. if (access (gisdbase, 2) == 0)
  25. return 1;
  26. fprintf (stderr, "\nNote\n");
  27. fprintf (stderr, " You don't have permission under %s to create a new location\n",
  28. gisdbase);
  29. #ifndef __MINGW32__
  30. if ((pwd = getpwuid (s.st_uid)))
  31. fprintf (stderr, " See user %s about creating location %s\n", pwd->pw_name, location);
  32. #endif
  33. return 0;
  34. }