GRASS 8 Programmer's Manual 8.6.0dev(2026)-c83afef6d3
Loading...
Searching...
No Matches
is.c
Go to the documentation of this file.
1/*!
2 * \file lib/gis/is.c
3 *
4 * \brief GIS Library - Tests for file existence.
5 *
6 * SPDX-FileCopyrightText: 2001-2014 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author GRASS Development Team
10 *
11 * \date 2001-2014
12 */
13
14#include <stdio.h>
15#include <string.h>
16#include <unistd.h>
17#include <grass/gis.h>
18
19static int test_path_file(const char *, const char *);
20
21static int test_path_file(const char *path, const char *file)
22{
23 int ret;
24 char *buf;
25
26 size_t len = strlen(path) + strlen(file) + 2;
27 buf = (char *)G_malloc(len);
28 snprintf(buf, len, "%s/%s", path, file);
29
30 ret = access(buf, F_OK);
31 G_free(buf);
32
33 if (ret == 0)
34 return 1;
35
36 return 0;
37}
38
39/**
40
41 * \brief Test if specified directory is GISBASE.
42 *
43 * \param[in] path Path to directory
44 * \return 1 The directory is GISBASE
45 * \return 0 The directory is not GISBASE
46 */
47int G_is_gisbase(const char *path)
48{
49 return test_path_file(path, "etc/element_list");
50}
51
52/**
53 * \brief Test if specified directory is location.
54 *
55 * \param[in] path Path to directory
56 * \return 1 The directory is location
57 * \return 0 The directory is not location
58 */
59int G_is_location(const char *path)
60{
61 return test_path_file(path, "PERMANENT/DEFAULT_WIND");
62}
63
64/**
65 * \brief Test if specified directory is mapset.
66 *
67 * \param[in] path Path to directory
68 * \return 1 The directory is mapset
69 * \return 0 The directory is not mapset
70 */
71int G_is_mapset(const char *path)
72{
73 return test_path_file(path, "WIND");
74}
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:145
#define G_malloc(n)
Definition defs/gis.h:136
int G_is_mapset(const char *path)
Test if specified directory is mapset.
Definition is.c:71
int G_is_gisbase(const char *path)
Test if specified directory is GISBASE.
Definition is.c:47
int G_is_location(const char *path)
Test if specified directory is location.
Definition is.c:59
#define file
Definition path.h:15
#define access
Definition unistd.h:7
#define F_OK
Definition unistd.h:22