NetSurf
Data Structures | Functions | Variables
file.h File Reference

Default operations table for files. More...

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

Go to the source code of this file.

Data Structures

struct  gui_file_table
 /brief function table for file and filename operations. More...
 

Functions

nserror netsurf_mkpath (char **str, size_t *size, size_t nelm,...)
 Generate a path from one or more component elemnts. More...
 
nserror netsurf_nsurl_to_path (struct nsurl *url, char **path_out)
 Create a path from a nsurl. More...
 
nserror netsurf_path_to_nsurl (const char *path, struct nsurl **url)
 Create a nsurl from a path. More...
 
nserror netsurf_mkdir_all (const char *fname)
 Ensure that all directory elements needed to store a filename exist. More...
 
nserror netsurf_recursive_rm (const char *path)
 Recursively remove a directory. More...
 

Variables

struct gui_file_tabledefault_file_table
 Default (posix) file operation table. More...
 

Detailed Description

Default operations table for files.

These are file operations that depend upon the filesystem the browser is operating on. These allow the core browser functionality to be filesystem agnostic.

The provided defaults operate on POSIX path names with / as a directory separator in a single hieracy from a root directory.

Other path conventions require the default operations to be overridden. For example windows frontend runs on a filesystem with drive letter and a \ as a separator.

Definition in file file.h.

Function Documentation

◆ netsurf_mkdir_all()

nserror netsurf_mkdir_all ( const char *  fname)

Ensure that all directory elements needed to store a filename exist.

Parameters
fnameThe filename to ensure the path to exists.
Returns
NSERROR_OK on success or error code on failure.

Definition at line 313 of file file.c.

References netsurf_table::file, guit, and gui_file_table::mkdir_all.

Referenced by create_cache_home(), create_config_home(), ro_gui_create_dirs(), store_open(), and write_control().

Here is the caller graph for this function:

◆ netsurf_mkpath()

nserror netsurf_mkpath ( char **  str,
size_t *  size,
size_t  nelm,
  ... 
)

Generate a path from one or more component elemnts.

If a string is allocated it must be freed by the caller.

Warning
If this is called before the gui operation tables are initialised the behaviour defaults to posix paths. Ensure this is the required behaviour.
Parameters
[in,out]strpointer to string pointer if this is NULL enough storage will be allocated for the complete path.
[in,out]sizeThe size of the space available if str not NULL on input and if not NULL set to the total output length on output.
[in]nelmThe number of elements.
[in]...The elements of the path as string pointers.
Returns
NSERROR_OK and the complete path is written to str or error code on faliure.

Definition at line 288 of file file.c.

References netsurf_table::file, guit, and gui_file_table::mkpath.

Referenced by ami_gui_check_resource(), ami_gui_map_filename(), ami_locate_resource(), check_dirname(), create_cache_home(), create_config_home(), get_cachepath(), netsurf_recursive_rm(), nsgtk_option_init(), nsgtk_preferences_dialogPreferences_deleteevent(), nsgtk_preferences_dialogPreferences_destroy(), nsgtk_preferences_dialogPreferences_response(), nsgtk_toolbar_customisation_save(), nsw32_option_init(), nsws_prefs_save(), print_button_clicked_cb(), process_dir_ent(), read_blocks(), read_control(), read_entries(), save_complete_inventory(), save_complete_save_buffer(), save_complete_save_html_document(), savewindowsize_button_clicked_cb(), set_defaults(), store_fname(), unlink_entries(), write_blocks(), write_cache_tag(), write_control(), and write_entries().

Here is the caller graph for this function:

◆ netsurf_nsurl_to_path()

nserror netsurf_nsurl_to_path ( struct nsurl url,
char **  path_out 
)

Create a path from a nsurl.

Parameters
[in]urlThe url to encode.
[out]path_outA string containing the result path which must be freed by the caller.
Returns
NSERROR_OK and the path is written to path_out or error code on faliure.

Definition at line 301 of file file.c.

References netsurf_table::file, guit, and gui_file_table::nsurl_to_path.

Referenced by ro_gui_view_source(), and ro_gui_window_close().

Here is the caller graph for this function:

◆ netsurf_path_to_nsurl()

nserror netsurf_path_to_nsurl ( const char *  path,
struct nsurl **  url 
)

Create a nsurl from a path.

Perform the necessary operations on a path to generate a nsurl.

Parameters
[in]pathThe path to convert.
[out]urlpointer to recive the nsurl, The returned url should be unreferenced by the caller.
Returns
NSERROR_OK and the url is placed in url or error code on faliure.

Definition at line 307 of file file.c.

References netsurf_table::file, guit, path(), and gui_file_table::path_to_nsurl.

Referenced by ami_file_open(), ami_handle_applib(), ami_handle_appmsg(), get_resource_url(), gui_get_resource_url(), gui_init(), gui_init2(), nsgtk_get_resource_url(), nsw32_get_resource_url(), ro_msg_dataload(), ro_msg_dataopen(), and tab_init_fname().

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

◆ netsurf_recursive_rm()

nserror netsurf_recursive_rm ( const char *  path)

Recursively remove a directory.

If this returns a failure code, there's an unpredictable amount left unremoved.

Parameters
pathThe path to recursively remove
Returns
NSERROR_OK on success, or an error code on failure.

Definition at line 320 of file file.c.

References netsurf_mkpath(), netsurf_recursive_rm(), NSERROR_NOT_FOUND, NSERROR_OK, NSERROR_UNKNOWN, parent, and path().

Referenced by filename_flush_directory(), initialise(), and netsurf_recursive_rm().

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

Variable Documentation

◆ default_file_table

struct gui_file_table* default_file_table
extern

Default (posix) file operation table.

Definition at line 285 of file file.c.

Referenced by netsurf_register().