NetSurf
Functions | Variables
file.c File Reference

Table operations for files with posix compliant path separator. More...

#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "desktop/gui_internal.h"
#include "utils/utils.h"
#include "utils/corestrings.h"
#include "utils/url.h"
#include "utils/nsurl.h"
#include "utils/file.h"
#include "utils/dirent.h"
Include dependency graph for file.c:

Go to the source code of this file.

Functions

static nserror posix_vmkpath (char **str, size_t *size, size_t nelm, va_list ap)
 Generate a posix path from one or more component elemnts. More...
 
static nserror posix_basename (const char *path, char **str, size_t *size)
 Get the basename of a file using posix path handling. More...
 
static nserror posix_nsurl_to_path (struct nsurl *url, char **path_out)
 Create a path from a nsurl using posix file handling. More...
 
static nserror posix_path_to_nsurl (const char *path, struct nsurl **url_out)
 Create a nsurl from a path using posix file handling. More...
 
static nserror posix_mkdir_all (const char *fname)
 Ensure that all directory elements needed to store a filename exist. More...
 
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

static struct gui_file_table file_table
 default to using the posix file handling More...
 
struct gui_file_tabledefault_file_table = &file_table
 Default (posix) file operation table. More...
 

Detailed Description

Table operations for files with posix compliant path separator.

Definition in file file.c.

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:

◆ posix_basename()

static nserror posix_basename ( const char *  path,
char **  str,
size_t *  size 
)
static

Get the basename of a file using posix path handling.

This gets the last element of a path and returns it.

Parameters
[in]pathThe path to extract the name from.
[in,out]strPointer to string pointer if this is NULL enough storage will be allocated for the path element.
[in,out]sizeThe size of the space available if str not NULL on input and set to the total output length on output.
Returns
NSERROR_OK and the complete path is written to str or error code on faliure.

Definition at line 80 of file file.c.

References NSERROR_BAD_PARAMETER, NSERROR_NOMEM, NSERROR_OK, and path().

Here is the call graph for this function:

◆ posix_mkdir_all()

static nserror posix_mkdir_all ( const char *  fname)
static

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 217 of file file.c.

References NSERROR_NOT_DIRECTORY, NSERROR_NOT_FOUND, NSERROR_OK, and nsmkdir.

◆ posix_nsurl_to_path()

static nserror posix_nsurl_to_path ( struct nsurl url,
char **  path_out 
)
static

Create a path from a nsurl using posix file handling.

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

Definition at line 117 of file file.c.

References NSERROR_BAD_PARAMETER, NSERROR_OK, nsurl_get_component(), NSURL_PATH, NSURL_SCHEME, path(), and url_unescape().

Here is the call graph for this function:

◆ posix_path_to_nsurl()

static nserror posix_path_to_nsurl ( const char *  path,
struct nsurl **  url_out 
)
static

Create a nsurl from a path using posix file handling.

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

Parameters
[in]pathThe path to convert.
[out]url_outpointer 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 171 of file file.c.

References FILE_SCHEME_PREFIX, FILE_SCHEME_PREFIX_LEN, NSERROR_BAD_PARAMETER, NSERROR_NOMEM, NSERROR_OK, nsurl_create(), path(), and url_escape().

Here is the call graph for this function:

◆ posix_vmkpath()

static nserror posix_vmkpath ( char **  str,
size_t *  size,
size_t  nelm,
va_list  ap 
)
static

Generate a posix path from one or more component elemnts.

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

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]apThe 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 61 of file file.c.

References vsnstrjoin().

Here is the call graph for this function:

Variable Documentation

◆ default_file_table

struct gui_file_table* default_file_table = &file_table

Default (posix) file operation table.

Definition at line 285 of file file.c.

Referenced by netsurf_register().

◆ file_table

struct gui_file_table file_table
static
Initial value:
= {
.mkpath = posix_vmkpath,
.basename = posix_basename,
.nsurl_to_path = posix_nsurl_to_path,
.path_to_nsurl = posix_path_to_nsurl,
.mkdir_all = posix_mkdir_all,
}
static nserror posix_nsurl_to_path(struct nsurl *url, char **path_out)
Create a path from a nsurl using posix file handling.
Definition: file.c:117
static nserror posix_path_to_nsurl(const char *path, struct nsurl **url_out)
Create a nsurl from a path using posix file handling.
Definition: file.c:171
static nserror posix_mkdir_all(const char *fname)
Ensure that all directory elements needed to store a filename exist.
Definition: file.c:217
static nserror posix_basename(const char *path, char **str, size_t *size)
Get the basename of a file using posix path handling.
Definition: file.c:80
static nserror posix_vmkpath(char **str, size_t *size, size_t nelm, va_list ap)
Generate a posix path from one or more component elemnts.
Definition: file.c:61

default to using the posix file handling

Definition at line 277 of file file.c.