GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
Loading...
Searching...
No Matches
find_etc.c
Go to the documentation of this file.
1
#include <stdlib.h>
2
#include <string.h>
3
#include <unistd.h>
4
#include <grass/gis.h>
5
6
static
char
*G__find_etc(
const
char
*
name
)
7
{
8
char
path
[GPATH_MAX];
9
const
char
*pathlist = getenv(
"GRASS_ADDON_ETC"
);
10
11
/*
12
* reject illegal names
13
*/
14
if
(*
name
== 0 || *
name
==
'.'
)
15
return
NULL
;
16
17
/*
18
* search paths
19
*/
20
if
(pathlist) {
21
char
**dirs =
G_tokenize
(pathlist,
":"
);
22
char
*result =
NULL
;
23
int
i;
24
25
for
(i = 0; dirs[i]; i++) {
26
snprintf(
path
,
sizeof
(
path
),
"%s/%s"
, dirs[i],
name
);
27
28
if
(access(
path
, 0) == 0) {
29
result =
G_store
(
path
);
30
break
;
31
}
32
}
33
34
G_free_tokens
(dirs);
35
36
if
(result)
37
return
result;
38
}
39
40
/*
41
* check application etc dir
42
*/
43
snprintf(
path
,
sizeof
(
path
),
"%s/etc/%s"
,
G_gisbase
(),
name
);
44
if
(access(
path
, 0) == 0)
45
return
G_store
(
path
);
46
47
return
NULL
;
48
}
49
50
/*!
51
* \brief searches for a file from the etc search list in GRASS_ADDON_ETC
52
* returns the full path to where the file was found.
53
*
54
* note:
55
* rejects all names that begin with "."
56
*
57
* \param name file name to look for
58
*
59
* \return pointer to a string with full path to
60
* where file was found, or NULL if not found
61
*/
62
char
*
G_find_etc
(
const
char
*
name
)
63
{
64
return
G__find_etc(
name
);
65
}
NULL
#define NULL
Definition
ccmath.h:32
G_find_etc
char * G_find_etc(const char *name)
searches for a file from the etc search list in GRASS_ADDON_ETC returns the full path to where the fi...
Definition
find_etc.c:62
G_gisbase
const char * G_gisbase(void)
Get full path name of the top level module directory.
Definition
gisbase.c:39
name
const char * name
Definition
named_colr.c:6
G_store
char * G_store(const char *s)
Copy string to allocated memory.
Definition
strings.c:87
path
Definition
path.h:15
G_free_tokens
void G_free_tokens(char **tokens)
Free memory allocated to tokens.
Definition
token.c:197
G_tokenize
char ** G_tokenize(const char *buf, const char *delim)
Tokenize string.
Definition
token.c:47
gis
find_etc.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0