Loading...
Searching...
No Matches
find_etc.c
Go to the documentation of this file.
#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++) {
snprintf(path, sizeof(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
*/
snprintf(path, sizeof(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);
}
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