GRASS GIS 7 Programmer's Manual  7.0.3(2016)-r00000
location.c
Go to the documentation of this file.
1 
14 #include <stdio.h>
15 #include <string.h>
16 #include <unistd.h>
17 #include <sys/types.h>
18 #include <grass/gis.h>
19 #include <grass/glocale.h>
20 
21 #include "gis_local_proto.h"
22 
32 const char *G_location(void)
33 {
34  return G_getenv("LOCATION_NAME");
35 }
36 
54 char *G_location_path(void)
55 {
56  char *location;
57 
58  location = G__location_path();
59  if (access(location, F_OK) != 0) {
60  perror("access");
61  G_fatal_error(_("LOCATION <%s> not available"), location);
62  }
63 
64  return location;
65 }
66 
67 
78 char *G__location_path(void)
79 {
80  const char *name = G_location();
81  const char *base = G_gisdbase();
82  char *location = G_malloc(strlen(base) + strlen(name) + 2);
83 
84  sprintf(location, "%s/%s", base, name);
85 
86  return location;
87 }
const char * G_location(void)
Get current location name.
Definition: location.c:32
char * G__location_path(void)
Get current location UNIX-like path (internal use only)
Definition: location.c:78
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition: gis/error.c:159
char * G_location_path(void)
Get current location UNIX-like path.
Definition: location.c:54
const char * G_gisdbase(void)
Get name of top level database directory.
Definition: gisdbase.c:26
const char * name
Definition: named_colr.c:7
const char * G_getenv(const char *name)
Get environment variable.
Definition: env.c:336