NetSurf
Functions | Variables
file.c File Reference

Windows file operation table implementation. More...

#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <windows.h>
#include "utils/errors.h"
#include "utils/nsurl.h"
#include "utils/log.h"
#include "utils/utils.h"
#include "utils/corestrings.h"
#include "utils/url.h"
#include "utils/file.h"
#include "utils/string.h"
#include "netsurf/browser_window.h"
#include "windows/file.h"
Include dependency graph for file.c:

Go to the source code of this file.

Functions

static nserror windows_mkpath (char **str, size_t *size, size_t nelm, va_list ap)
 Generate a windows path from one or more component elemnts. More...
 
static nserror windows_basename (const char *path, char **str, size_t *size)
 Get the basename of a file using windows path handling. More...
 
static nserror windows_nsurl_to_path (struct nsurl *url, char **path_out)
 Create a path from a nsurl using windows file handling. More...
 
static nserror windows_path_to_nsurl (const char *path, struct nsurl **url_out)
 Create a nsurl from a path using windows file handling. More...
 
static nserror windows_mkdir_all (const char *fname)
 Ensure that all directory elements needed to store a filename exist. More...
 

Variables

static struct gui_file_table file_table
 
struct gui_file_tablewin32_file_table = &file_table
 

Detailed Description

Windows file operation table implementation.

Definition in file file.c.

Function Documentation

◆ windows_basename()

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

Get the basename of a file using windows 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 77 of file file.c.

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

Here is the call graph for this function:

◆ windows_mkdir_all()

static nserror windows_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 239 of file file.c.

References NSERROR_NOT_DIRECTORY, NSERROR_NOT_FOUND, NSERROR_OK, and nsmkdir.

◆ windows_mkpath()

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

Generate a windows 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 57 of file file.c.

References vsnstrjoin().

Here is the call graph for this function:

◆ windows_nsurl_to_path()

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

Create a path from a nsurl using windows 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.
Todo:
Need to check returning the unaltered path in this case is correct

Definition at line 115 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:

◆ windows_path_to_nsurl()

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

Create a nsurl from a path using windows 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.
Todo:
check if this should be url escaping the path.

Definition at line 194 of file file.c.

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

Here is the call graph for this function:

Variable Documentation

◆ file_table

struct gui_file_table file_table
static
Initial value:
= {
.mkpath = windows_mkpath,
.basename = windows_basename,
.nsurl_to_path = windows_nsurl_to_path,
.path_to_nsurl = windows_path_to_nsurl,
.mkdir_all = windows_mkdir_all,
}
static nserror windows_nsurl_to_path(struct nsurl *url, char **path_out)
Create a path from a nsurl using windows file handling.
Definition: file.c:115
static nserror windows_basename(const char *path, char **str, size_t *size)
Get the basename of a file using windows path handling.
Definition: file.c:77
static nserror windows_mkpath(char **str, size_t *size, size_t nelm, va_list ap)
Generate a windows path from one or more component elemnts.
Definition: file.c:57
static nserror windows_path_to_nsurl(const char *path, struct nsurl **url_out)
Create a nsurl from a path using windows file handling.
Definition: file.c:194
static nserror windows_mkdir_all(const char *fname)
Ensure that all directory elements needed to store a filename exist.
Definition: file.c:239

Definition at line 297 of file file.c.

◆ win32_file_table

struct gui_file_table* win32_file_table = &file_table

Definition at line 305 of file file.c.

Referenced by WinMain().