GRASS GIS 7 Programmer's Manual  7.0.3(2016)-r00000
mapset.c
Go to the documentation of this file.
1 
14 #include <string.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include <grass/gis.h>
18 #include <grass/glocale.h>
19 
20 #include "gis_local_proto.h"
21 
33 const char *G_mapset(void)
34 {
35  const char *m = G__mapset();
36 
37  if (!m)
38  G_fatal_error(_("MAPSET is not set"));
39 
40  return m;
41 }
42 
51 const char *G__mapset(void)
52 {
53  return G_getenv_nofatal("MAPSET");
54 }
55 
73 char *G_mapset_path(void)
74 {
75  char *mapset;
76 
77  mapset = G__mapset_path();
78  if (access(mapset, F_OK) != 0) {
79  perror("access");
80  G_fatal_error(_("MAPSET <%s> not available"), mapset);
81  }
82 
83  return mapset;
84 }
85 
96 char *G__mapset_path(void)
97 {
98  const char *mapset = G__mapset();
99  const char *location = G_location();
100  const char *base = G_gisdbase();
101 
102  char *mapset_path = G_malloc(strlen(base) + strlen(location) +
103  strlen(mapset) + 3);
104 
105  sprintf(mapset_path, "%s/%s/%s", base, location, mapset);
106 
107  return mapset_path;
108 }
const char * G_location(void)
Get current location name.
Definition: location.c:32
const char * G_mapset(void)
Get current mapset name.
Definition: mapset.c:33
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition: gis/error.c:159
char * G__mapset_path(void)
Get current mapset UNIX-like path (internal use only)
Definition: mapset.c:96
char * G_mapset_path(void)
Get current mapset UNIX-like path.
Definition: mapset.c:73
const char * G_getenv_nofatal(const char *name)
Get environment variable.
Definition: env.c:381
const char * G_gisdbase(void)
Get name of top level database directory.
Definition: gisdbase.c:26
const char * G__mapset(void)
Get current mapset name (internal use only)
Definition: mapset.c:51