GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mapset.c
Go to the documentation of this file.
1 
2 /**********************************************************************
3  *
4  * char *
5  * G_mapset()
6  *
7  * returns: pointer to string containing the one word mapset
8  * name.
9  * NULL if user does not have access to mapset.
10  *
11  **********************************************************************/
12 
13 #include <string.h>
14 #include <stdlib.h>
15 #include <grass/gis.h>
16 #include <grass/glocale.h>
17 
18 
31 char *G_mapset(void)
32 {
33  static char mapset[GMAPSET_MAX];
34  static int first = 1;
35  char *m;
36 
37  m = G__mapset();
38  if (m == NULL)
39  G_fatal_error(_("MAPSET is not set"));
40 
41  if (first)
42  first = 0;
43  else if (strcmp(mapset, m) == 0)
44  return mapset;
45  strcpy(mapset, m);
46 
47  switch (G__mapset_permissions(mapset)) {
48  case 0:
49  case 1:
50  return mapset;
51  /*
52  case 0:
53  G_fatal_error ("MAPSET %s - permission denied", mapset);
54  break;
55  */
56  default:
57  G_fatal_error(_("MAPSET %s not found"), mapset);
58  break;
59  }
60  exit(EXIT_FAILURE);
61 }
62 
63 char *G__mapset(void)
64 {
65  return G__getenv("MAPSET");
66 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
int G__mapset_permissions(const char *mapset)
Check for user mapset permission.
Definition: mapset_msc.c:115
char * G__getenv(const char *name)
Get environment variable.
Definition: env.c:312
char * G__mapset(void)
Definition: mapset.c:63
int first
Definition: form/open.c:25
return NULL
Definition: dbfopen.c:1394
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.