NetSurf
Functions
filepath.h File Reference

Utility routines to obtain paths to file resources. More...

#include <stdarg.h>
#include "utils/errors.h"
Include dependency graph for filepath.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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...
 
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...
 

Detailed Description

Utility routines to obtain paths to file resources.

Definition in file filepath.h.

Function Documentation

◆ filepath_find()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filepath_findfile()

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().

Here is the call graph for this function:

◆ filepath_free_strvec()

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().

Here is the caller graph for this function:

◆ filepath_generate()

char ** filepath_generate ( char *const *  pathv,
const char *const *  langv 
)

Merge two string vectors into a resource search path vector.

Parameters
pathvA string vector containing path elemets to scan.
langvA string vector containing language names to enumerate.
Returns
A pointer to a NULL terminated string vector of valid resource directories.

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().

Here is the caller graph for this function:

◆ filepath_path_to_strvec()

char ** filepath_path_to_strvec ( const char *  path)

Convert a colon separated list of path elements into a string vector.

Parameters
pathA colon separated path.
Returns
A pointer to a NULL terminated string vector of valid resource directories.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filepath_sfind()

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.

Parameters
respathvThe resource path vector to iterate.
filepathThe buffer to place the result in.
filenameThe filename of the resource to search for.
Returns
A pointer to filepath if a target is found or NULL if not.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filepath_sfinddef()

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.

Parameters
respathvThe resource path vector to iterate.
filepathThe buffer to place the result in. Must have space for PATH_MAX bytes.
filenameThe filename of the resource to search for.
defThe default path to use
Returns
A pointer to filepath if a target is found or the default if not

Definition at line 152 of file filepath.c.

References filepath_sfind(), PATH_MAX, and realpath().

Referenced by main(), and nsgtk_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filepath_sfindfile()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ filepath_vsfindfile()

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.

Parameters
strA buffer to contain the normalised file name must be at least PATH_MAX bytes long.
formatA printf format for the filename.
apThe list of arguments for the format.
Returns
A pointer to the expanded filename or NULL if the file is not present or accessible.

Definition at line 45 of file filepath.c.

References PATH_MAX, and realpath().

Referenced by filepath_findfile(), and filepath_sfindfile().

Here is the call graph for this function:
Here is the caller graph for this function: