GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
is.c
Go to the documentation of this file.
1 
2 /*!
3  * \file lib/gis/is.c
4  *
5  * \brief GIS Library - Tests for file existence.
6  *
7  * (C) 2001-2014 by the GRASS Development Team
8  *
9  * This program is free software under the GNU General Public License
10  * (>=v2). Read the file COPYING that comes with GRASS for details.
11  *
12  * \author GRASS GIS Development Team
13  *
14  * \date 2001-2014
15  */
16 
17 #include <stdio.h>
18 #include <string.h>
19 #include <unistd.h>
20 #include <grass/gis.h>
21 
22 
23 static int test_path_file(const char *, const char *);
24 
25 
26 static int test_path_file(const char *path, const char *file)
27 {
28  int ret;
29  char *buf;
30 
31  buf = (char *)G_malloc(strlen(path) + strlen(file) + 2);
32  sprintf(buf, "%s/%s", path, file);
33 
34  ret = access(buf, F_OK);
35  G_free(buf);
36 
37  if (ret == 0)
38  return 1;
39 
40  return 0;
41 }
42 
43 
44 /**
45 
46  * \brief Test if specified directory is GISBASE.
47  *
48  * \param[in] path Path to directory
49  * \return 1 The directory is GISBASE
50  * \return 0 The directory is not GISBASE
51  */
52 
53 int G_is_gisbase(const char *path)
54 {
55  return test_path_file(path, "etc/element_list");
56 }
57 
58 
59 /**
60  * \brief Test if specified directory is location.
61  *
62  * \param[in] path Path to directory
63  * \return 1 The directory is location
64  * \return 0 The directory is not location
65  */
66 
67 int G_is_location(const char *path)
68 {
69  return test_path_file(path, "PERMANENT/DEFAULT_WIND");
70 }
71 
72 
73 /**
74  * \brief Test if specified directory is mapset.
75  *
76  * \param[in] path Path to directory
77  * \return 1 The directory is mapset
78  * \return 0 The directory is not mapset
79  */
80 
81 int G_is_mapset(const char *path)
82 {
83  return test_path_file(path, "WIND");
84 }
#define G_malloc(n)
Definition: defs/gis.h:112
int G_is_mapset(const char *path)
Test if specified directory is mapset.
Definition: is.c:81
int G_is_location(const char *path)
Test if specified directory is location.
Definition: is.c:67
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:149
int G_is_gisbase(const char *path)
Test if specified directory is GISBASE.
Definition: is.c:53
Definition: path.h:16
#define file