-
-
Notifications
You must be signed in to change notification settings - Fork 294
/
find_etc.c
66 lines (55 loc) · 1.21 KB
/
find_etc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <grass/gis.h>
static char *G__find_etc(const char *name)
{
char path[GPATH_MAX];
const char *pathlist = getenv("GRASS_ADDON_ETC");
/*
* reject illegal names
*/
if (*name == 0 || *name == '.')
return NULL;
/*
* search paths
*/
if (pathlist) {
char **dirs = G_tokenize(pathlist, ":");
char *result = NULL;
int i;
for (i = 0; dirs[i]; i++) {
sprintf(path, "%s/%s", dirs[i], name);
if (access(path, 0) == 0) {
result = G_store(path);
break;
}
}
G_free_tokens(dirs);
if (result)
return result;
}
/*
* check application etc dir
*/
sprintf(path, "%s/etc/%s", G_gisbase(), name);
if (access(path, 0) == 0)
return G_store(path);
return NULL;
}
/*!
* \brief searches for a file from the etc search list in GRASS_ADDON_ETC
* returns the full path to where the file was found.
*
* note:
* rejects all names that begin with "."
*
* \param name file name to look for
*
* \return pointer to a string with full path to
* where file was found, or NULL if not found
*/
char *G_find_etc(const char *name)
{
return G__find_etc(name);
}