File: chk_dbase.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (38 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#ifndef __MINGW32__
#  include <pwd.h>
#endif

int can_make_location (char *gisdbase, char *location)
{
    struct stat s;
    struct passwd *pwd;

/* make sure this is a directory */
    if (stat (gisdbase, &s) != 0)
    {
	fprintf (stderr, "\n** %s not found **\n", gisdbase);
	return 0;
    }
    if (!(s.st_mode & S_IFDIR))
    {
	fprintf (stderr, "\n** %s is not a directory **\n", gisdbase);
	return 0;
    }

/* look for write permission */
    if (access (gisdbase, 2) == 0)
	return 1;
    
    fprintf (stderr, "\nNote\n");
    fprintf (stderr, " You don't have permission under %s to create a new location\n",
	gisdbase);
#ifndef __MINGW32__
    if (pwd = getpwuid (s.st_uid))
	fprintf (stderr, " See user %s about creating location %s\n", pwd->pw_name, location);
#endif
    return 0;
}