GRASS Programmer's Manual  6.4.2(2012)
chk_dbase.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <sys/types.h>
00003 #include <unistd.h>
00004 #include <sys/stat.h>
00005 #ifndef __MINGW32__
00006 #  include <pwd.h>
00007 #endif
00008 
00009 int can_make_location(char *gisdbase, char *location)
00010 {
00011     struct stat s;
00012     struct passwd *pwd;
00013 
00014     /* make sure this is a directory */
00015     if (stat(gisdbase, &s) != 0) {
00016         fprintf(stderr, "\n** %s not found **\n", gisdbase);
00017         return 0;
00018     }
00019     if (!(s.st_mode & S_IFDIR)) {
00020         fprintf(stderr, "\n** %s is not a directory **\n", gisdbase);
00021         return 0;
00022     }
00023 
00024     /* look for write permission */
00025     if (access(gisdbase, 2) == 0)
00026         return 1;
00027 
00028     fprintf(stderr, "\nNote\n");
00029     fprintf(stderr,
00030             " You don't have permission under %s to create a new location\n",
00031             gisdbase);
00032 #ifndef __MINGW32__
00033     if ((pwd = getpwuid(s.st_uid)))
00034         fprintf(stderr, " See user %s about creating location %s\n",
00035                 pwd->pw_name, location);
00036 #endif
00037     return 0;
00038 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines