42#define MAX_RESPATH 128
55 len = vsnprintf(pathname,
PATH_MAX, format, ap);
57 if ((len < 0) || (len >=
PATH_MAX)) {
65 realpathname =
realpath(pathname, str);
69 if (realpathname != NULL) {
71 if (access(realpathname, R_OK) != 0) {
101 va_start(ap, format);
113 if ((respathv == NULL) || (respathv[0] == NULL) || (filepath == NULL))
116 while (respathv[respathc] != NULL) {
134 if ((respathv == NULL) || (respathv[0] == NULL))
138 if (filepath == NULL)
154 const char *filename,
160 if ((respathv == NULL) || (respathv[0] == NULL) || (filepath == NULL))
165 if ((ret == NULL) && (def != NULL)) {
169 snprintf(t,
PATH_MAX,
"%s/%s/%s", getenv(
"HOME"), def + 1, filename);
171 snprintf(t,
PATH_MAX,
"%s/%s", def, filename);
196 while ((respath != NULL) &&
197 (pathv[pathc] != NULL)) {
198 if ((stat(pathv[pathc], &dstat) == 0) &&
199 S_ISDIR(dstat.st_mode)) {
202 while (langv[langc] != NULL) {
203 tmppathlen = snprintf(NULL,
208 tmppath = malloc(tmppathlen + 1);
209 if (tmppath == NULL) {
218 if ((stat(tmppath, &dstat) == 0) &&
219 S_ISDIR(dstat.st_mode)) {
221 respath[respathc++] = tmppath;
228 respath[respathc++] = strdup(pathv[pathc]);
254 exp = malloc(pathlen + 1);
258 memcpy(exp,
path, pathlen);
263 while (exp[cloop] != 0) {
264 if ((exp[cloop] ==
'$') &&
265 (exp[cloop + 1] ==
'{')) {
270 if ((cstart != -1) &&
271 (exp[cloop] ==
'}')) {
272 replen = cloop - cstart;
274 envv = getenv(exp + cstart + 2);
276 memmove(exp + cstart,
282 envlen = strlen(envv);
283 tmp = realloc(exp, explen + envlen - replen);
289 memmove(exp + cstart + envlen,
292 memmove(exp + cstart, envv, envlen);
293 explen += envlen - replen;
325 estart = eend =
path;
328 while ( (*eend != 0) && (*eend !=
':') )
330 elen = eend - estart;
335 if (strvec[strc] != NULL) {
360 while (pathv[p] != NULL) {
directory traversal and entry
char ** filepath_path_to_strvec(const char *path)
Convert a colon separated list of path elements into a string vector.
char * filepath_sfind(char **respathv, char *filepath, const char *filename)
Searches an array of resource paths for a file.
char * filepath_sfindfile(char *str, const char *format,...)
Create a normalised file name.
#define MAX_RESPATH
maximum number of elements in the resource vector
char * filepath_find(char **respathv, const char *filename)
Searches an array of resource paths for a file.
char * filepath_vsfindfile(char *str, const char *format, va_list ap)
Create a normalised file name.
char * filepath_sfinddef(char **respathv, char *filepath, const char *filename, const char *def)
Searches an array of resource paths for a file optionally forcing a default.
char * filepath_findfile(const char *format,...)
Create a normalised file name.
void filepath_free_strvec(char **pathv)
Free a string vector.
static char * expand_path(const char *path, int pathlen)
expand ${} in a string into environment variables.
char ** filepath_generate(char *const *pathv, const char *const *langv)
Merge two string vectors into a resource search path vector.
Utility routines to obtain paths to file resources.
char * realpath(const char *f, char *buf)
Interface to utility string handling.
Interface to a number of general purpose functionality.
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.