NetSurf
|
Provides utility functions for finding readable files. More...
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "utils/dirent.h"
#include "utils/utils.h"
#include "utils/config.h"
#include "utils/filepath.h"
Go to the source code of this file.
Macros | |
#define | MAX_RESPATH 128 |
maximum number of elements in the resource vector More... | |
Functions | |
char * | filepath_vsfindfile (char *str, const char *format, va_list ap) |
Create a normalised file name. More... | |
char * | filepath_sfindfile (char *str, const char *format,...) |
Create a normalised file name. More... | |
char * | filepath_findfile (const char *format,...) |
Create a normalised file name. More... | |
char * | filepath_sfind (char **respathv, char *filepath, const char *filename) |
Searches an array of resource paths for a file. More... | |
char * | filepath_find (char **respathv, const char *filename) |
Searches an array of resource paths for a file. More... | |
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. More... | |
char ** | filepath_generate (char *const *pathv, const char *const *langv) |
Merge two string vectors into a resource search path vector. More... | |
static char * | expand_path (const char *path, int pathlen) |
expand ${} in a string into environment variables. More... | |
char ** | filepath_path_to_strvec (const char *path) |
Convert a colon separated list of path elements into a string vector. More... | |
void | filepath_free_strvec (char **pathv) |
Free a string vector. More... | |
Provides utility functions for finding readable files.
These functions are intended to make finding resource files more straightforward.
Definition in file filepath.c.
#define MAX_RESPATH 128 |
maximum number of elements in the resource vector
Definition at line 42 of file filepath.c.
|
static |
expand ${} in a string into environment variables.
path | The pathname to expand. |
pathlen | The length of the path element. |
Definition at line 244 of file filepath.c.
References path().
Referenced by filepath_path_to_strvec().
char * filepath_find | ( | char ** | respathv, |
const char * | filename | ||
) |
Searches an array of resource paths for a file.
Similar to filepath_sfind except it allocates its own storage for the returned string. The caller must free this sorage.
Definition at line 129 of file filepath.c.
References filepath_sfind(), and PATH_MAX.
Referenced by init_resource(), main(), nsgtk_setup(), and nsw32_messages_init().
char * filepath_findfile | ( | const char * | format, |
... | |||
) |
Create a normalised file name.
Similar to sfindfile but allocates its own storage for the returned string. The caller must free this sorage.
Definition at line 96 of file filepath.c.
References filepath_vsfindfile().
void filepath_free_strvec | ( | char ** | pathv | ) |
Free a string vector.
Free a string vector allocated by filepath_path_to_strvec
Definition at line 356 of file filepath.c.
Referenced by editor_init_fname(), fb_init_resource_path(), nsgtk_init_resource_path(), nsmonkey_init_resource(), and nsws_init_resource().
char ** filepath_generate | ( | char *const * | pathv, |
const char *const * | langv | ||
) |
Merge two string vectors into a resource search path vector.
pathv | A string vector containing path elemets to scan. |
langv | A string vector containing language names to enumerate. |
Definition at line 184 of file filepath.c.
References MAX_RESPATH.
Referenced by fb_init_resource_path(), nsgtk_init_resource_path(), nsmonkey_init_resource(), and nsws_init_resource().
char ** filepath_path_to_strvec | ( | const char * | path | ) |
Convert a colon separated list of path elements into a string vector.
path | A colon separated path. |
Definition at line 313 of file filepath.c.
References expand_path(), MAX_RESPATH, and path().
Referenced by fb_init_resource_path(), nsgtk_init_resource_path(), nsmonkey_init_resource(), nsws_init_resource(), and xdg_data_strvec().
char * filepath_sfind | ( | char ** | respathv, |
char * | filepath, | ||
const char * | filename | ||
) |
Searches an array of resource paths for a file.
Iterates through a vector of resource paths and returns the normalised file name of the first acessible file or NULL if no file can be found in any of the resource paths.
respathv | The resource path vector to iterate. |
filepath | The buffer to place the result in. |
filename | The filename of the resource to search for. |
Definition at line 109 of file filepath.c.
References filepath_sfindfile().
Referenced by fb_new_face(), filepath_find(), filepath_sfinddef(), get_resource_url(), gui_get_resource_url(), nsgtk_get_resource_url(), nsw32_get_resource_url(), and set_defaults().
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.
Similar to filepath_sfind except if no resource is found the default is used as an additional path element to search, if that still fails the returned path is set to the concatination of the default path and the filename.
respathv | The resource path vector to iterate. |
filepath | The buffer to place the result in. Must have space for PATH_MAX bytes. |
filename | The filename of the resource to search for. |
def | The default path to use |
Definition at line 152 of file filepath.c.
References filepath_sfind(), PATH_MAX, and realpath().
Referenced by main(), and nsgtk_setup().
char * filepath_sfindfile | ( | char * | str, |
const char * | format, | ||
... | |||
) |
Create a normalised file name.
Similar to vsfindfile but takes variadic (printf like) parameters
Definition at line 82 of file filepath.c.
References filepath_vsfindfile().
Referenced by filepath_sfind().
char * filepath_vsfindfile | ( | char * | str, |
const char * | format, | ||
va_list | ap | ||
) |
Create a normalised file name.
If the file described by the format exists and is accessible the normalised path is placed in str and a pointer to str returned otherwise NULL is returned. The string in str is always modified.
str | A buffer to contain the normalised file name must be at least PATH_MAX bytes long. |
format | A printf format for the filename. |
ap | The list of arguments for the format. |
Definition at line 45 of file filepath.c.
References PATH_MAX, and realpath().
Referenced by filepath_findfile(), and filepath_sfindfile().