4
\brief GIS library - environment routines (location)
6
(C) 2001-2008 by the GRASS Development Team
8
This program is free software under the
9
GNU General Public License (>=v2).
10
Read the file COPYING that comes with GRASS
13
\author Original author CERL
2
\file lib/gis/location.c
4
\brief GIS library - environment routines (location)
6
(C) 2001-2008, 2012 by the GRASS Development Team
8
This program is free software under the GNU General Public License
9
(>=v2). Read the file COPYING that comes with GRASS for details.
11
\author Original author CERL
17
15
#include <string.h>
20
18
#include <grass/gis.h>
21
19
#include <grass/glocale.h>
25
* \brief Get current location directory
27
* Returns the full UNIX path name of the current database
28
* location. For example, if the user is working in location
29
* <i>spearfish</i> in the <i>/home/user/grassdata</i> database
30
* directory, this routine will return a string which looks like
31
* <i>/home/user/grassdata/spearfish</i>.
21
#include "gis_local_proto.h"
24
\brief Get current location name
26
Returns the name of the current database location. This routine
27
should be used by modules that need to display the current location
28
to the user. See Locations for an explanation of locations.
32
const char *G_location(void)
34
return G_getenv("LOCATION_NAME");
38
\brief Get current location UNIX-like path
40
Allocated buffer should be freed by G_free(). See
43
Returns the full UNIX path name of the current database
44
location. For example, if the user is working in location
45
<i>spearfish</i> in the <i>/home/user/grassdata</i> database
46
directory, this routine will return a string which looks like
47
<i>/home/user/grassdata/spearfish</i>.
49
This function also checks if location path is readable by the
50
current user. It calls G_fatal_error() on failure.
52
\return buffer with location path
37
54
char *G_location_path(void)
41
58
location = G__location_path();
42
if (access(location, 0) != 0) {
59
if (access(location, F_OK) != 0) {
44
G_fatal_error(_("LOCATION << %s >> not available"), location);
61
G_fatal_error(_("LOCATION <%s> not available"), location);
52
* \brief Get current location name
54
* Returns the name of the current database location. This routine
55
* should be used by modules that need to display the current location
56
* to the user. See Locations for an explanation of locations.
59
* \return char* tolocation name
61
char *G_location(void)
63
return G_getenv("LOCATION_NAME");
67
* \brief Get current location path
70
* \return char* to location path
69
\brief Get current location UNIX-like path (internal use only)
71
Allocated buffer should be freed by G_free(). See also
74
\todo Support also Windows-like path (?)
76
\return buffer with location path
72
78
char *G__location_path(void)
80
location = G_malloc(strlen(base) + strlen(name) + 2);
80
const char *name = G_location();
81
const char *base = G_gisdbase();
82
char *location = G_malloc(strlen(base) + strlen(name) + 2);
82
84
sprintf(location, "%s/%s", base, name);