vfs

vfs

Synopsis




                    VFSFile;
                    VFSConstructor;
VFSFile*            vfs_fopen                           (const gchar *path,
                                                         const gchar *mode);
gint                vfs_fclose                          (VFSFile *file);
VFSFile*            vfs_dup                             (VFSFile *in);
size_t              vfs_fread                           (gpointer ptr,
                                                         size_t size,
                                                         size_t nmemb,
                                                         VFSFile *file);
size_t              vfs_fwrite                          (gconstpointer ptr,
                                                         size_t size,
                                                         size_t nmemb,
                                                         VFSFile *file);
gint                vfs_getc                            (VFSFile *stream);
gint                vfs_ungetc                          (gint c,
                                                         VFSFile *stream);
gchar*              vfs_fgets                           (gchar *s,
                                                         gint n,
                                                         VFSFile *stream);
gint                vfs_fseek                           (VFSFile *file,
                                                         glong offset,
                                                         gint whence);
void                vfs_rewind                          (VFSFile *file);
glong               vfs_ftell                           (VFSFile *file);
gboolean            vfs_feof                            (VFSFile *file);
gboolean            vfs_file_test                       (const gchar *path,
                                                         GFileTest test);
gboolean            vfs_is_writeable                    (const gchar *path);
gboolean            vfs_truncate                        (VFSFile *file,
                                                         glong length);
gchar*              vfs_get_metadata                    (VFSFile *file,
                                                         const gchar *field);
int                 vfs_fprintf                         (VFSFile *stream,
                                                         gchar const *format,
                                                         ...);
gboolean            vfs_register_transport              (VFSConstructor *vtable);
void                vfs_file_get_contents               (const gchar *filename,
                                                         gchar **buf,
                                                         gsize *size);

Description

Details

VFSFile

typedef struct {
	gchar *uri;
	gpointer handle;
	VFSConstructor *base;
	gint ref;
} VFSFile;

VFSFile objects describe a VFS stream.

gchar *uri; The URI of the stream.
gpointer handle; Opaque data used by the transport plugins.
VFSConstructor *base; The base vtable used for VFS functions.
gint ref; The amount of references that the VFSFile object has.

VFSConstructor

typedef struct {
	gchar *uri_id;
	VFSFile *(*vfs_fopen_impl)(const gchar *path,
		const gchar *mode);
	gint (*vfs_fclose_impl)(VFSFile * file);
	size_t (*vfs_fread_impl)(gpointer ptr, size_t size,
		size_t nmemb, VFSFile *file);
	size_t (*vfs_fwrite_impl)(gconstpointer ptr, size_t size,
		size_t nmemb, VFSFile *file);
	gint (*vfs_getc_impl)(VFSFile *stream);
	gint (*vfs_ungetc_impl)(gint c, VFSFile *stream);
	gint (*vfs_fseek_impl)(VFSFile *file, glong offset, gint whence);
	void (*vfs_rewind_impl)(VFSFile *file);
	glong (*vfs_ftell_impl)(VFSFile *file);
	gboolean (*vfs_feof_impl)(VFSFile *file);
	gboolean (*vfs_truncate_impl)(VFSFile *file, glong length);
	gchar *(*vfs_get_metadata_impl)(VFSFile *file, const gchar * field);
} VFSConstructor;

VFSConstructor objects contain the base vtables used for extrapolating a VFS stream. VFSConstructor objects should be considered virtual in nature. VFS base vtables are registered via vfs_register_transport().

gchar *uri_id; The uri identifier, e.g. "file" would handle "file://" streams.
vfs_fopen_impl () A function pointer which points to a fopen implementation.
vfs_fclose_impl () A function pointer which points to a fclose implementation.
vfs_fread_impl () A function pointer which points to a fread implementation.
vfs_fwrite_impl () A function pointer which points to a fwrite implementation.
vfs_getc_impl () A function pointer which points to a getc implementation.
vfs_ungetc_impl () A function pointer which points to an ungetc implementation.
vfs_fseek_impl () A function pointer which points to a fseek implementation.
vfs_rewind_impl () A function pointer which points to a rewind implementation.
vfs_ftell_impl () A function pointer which points to a ftell implementation.
vfs_feof_impl () A function pointer which points to a feof implementation.
vfs_truncate_impl () A function pointer which points to a ftruncate implementation.
vfs_get_metadata_impl ()

vfs_fopen ()

VFSFile*            vfs_fopen                           (const gchar *path,
                                                         const gchar *mode);

Opens a stream from a VFS transport using a VFSConstructor.

path : The path or URI to open.
mode : The preferred access privileges (not guaranteed).
Returns : On success, a VFSFile object representing the stream.

vfs_fclose ()

gint                vfs_fclose                          (VFSFile *file);

Closes a VFS stream and destroys a VFSFile object.

file : A VFSFile object to destroy.
Returns : -1 on failure, 0 on success.

vfs_dup ()

VFSFile*            vfs_dup                             (VFSFile *in);

Increments the amount of references that are using this FD. References are removed by calling vfs_fclose on the handle returned from this function. If the amount of references reaches zero, then the file will be closed.

in : The VFSFile handle to mark as duplicated.
Returns :

vfs_fread ()

size_t              vfs_fread                           (gpointer ptr,
                                                         size_t size,
                                                         size_t nmemb,
                                                         VFSFile *file);

Reads from a VFS stream.

ptr : A pointer to the destination buffer.
size : The size of each element to read.
nmemb : The number of elements to read.
file : VFSFile object that represents the VFS stream.
Returns : The amount of elements succesfully read.

vfs_fwrite ()

size_t              vfs_fwrite                          (gconstpointer ptr,
                                                         size_t size,
                                                         size_t nmemb,
                                                         VFSFile *file);

Writes to a VFS stream.

ptr : A const pointer to the source buffer.
size : The size of each element to write.
nmemb : The number of elements to write.
file : VFSFile object that represents the VFS stream.
Returns : The amount of elements succesfully written.

vfs_getc ()

gint                vfs_getc                            (VFSFile *stream);

Reads a character from a VFS stream.

stream : VFSFile object that represents the VFS stream.
Returns : On success, a character. Otherwise, -1.

vfs_ungetc ()

gint                vfs_ungetc                          (gint c,
                                                         VFSFile *stream);

Pushes a character back to the VFS stream.

c : The character to push back.
stream : VFSFile object that represents the VFS stream.
Returns : On success, 0. Otherwise, -1.

vfs_fgets ()

gchar*              vfs_fgets                           (gchar *s,
                                                         gint n,
                                                         VFSFile *stream);

Reads a set of characters from a stream.

s : A buffer to put the string in.
n : The amount of characters to read.
stream : A VFSFile object representing the stream.
Returns : The string on success, or NULL.

vfs_fseek ()

gint                vfs_fseek                           (VFSFile *file,
                                                         glong offset,
                                                         gint whence);

Seeks through a VFS stream.

file : VFSFile object that represents the VFS stream.
offset : The offset to seek to.
whence : Whether or not the seek is absolute or not.
Returns : On success, 1. Otherwise, 0.

vfs_rewind ()

void                vfs_rewind                          (VFSFile *file);

Rewinds a VFS stream.

file : VFSFile object that represents the VFS stream.

vfs_ftell ()

glong               vfs_ftell                           (VFSFile *file);

Returns the current position in the VFS stream's buffer.

file : VFSFile object that represents the VFS stream.
Returns : On success, the current position. Otherwise, -1.

vfs_feof ()

gboolean            vfs_feof                            (VFSFile *file);

Returns whether or not the VFS stream has reached EOF.

file : VFSFile object that represents the VFS stream.
Returns : On success, whether or not the VFS stream is at EOF. Otherwise, FALSE.

vfs_file_test ()

gboolean            vfs_file_test                       (const gchar *path,
                                                         GFileTest test);

Wrapper for g_file_test().

path : A path to test.
test : A GFileTest to run.
Returns : The result of g_file_test().

vfs_is_writeable ()

gboolean            vfs_is_writeable                    (const gchar *path);

Tests if a file is writeable.

path : A path to test.
Returns : TRUE if the file is writeable, otherwise FALSE.

vfs_truncate ()

gboolean            vfs_truncate                        (VFSFile *file,
                                                         glong length);

Truncates a VFS stream to a certain size.

file : VFSFile object that represents the VFS stream.
length : The length to truncate at.
Returns : On success, 0. Otherwise, -1.

vfs_get_metadata ()

gchar*              vfs_get_metadata                    (VFSFile *file,
                                                         const gchar *field);

Returns metadata about the stream.

file : VFSFile object that represents the VFS stream.
field : The string constant field name to get.
Returns : On success, a copy of the value of the field. Otherwise, NULL.

vfs_fprintf ()

int                 vfs_fprintf                         (VFSFile *stream,
                                                         gchar const *format,
                                                         ...);

Writes a formatted string to a VFS stream.

stream : A VFSFile object representing the stream.
format : A printf-style format string.
... : A list of args to use.
Returns : The amount of bytes written.

vfs_register_transport ()

gboolean            vfs_register_transport              (VFSConstructor *vtable);

Registers a VFSConstructor vtable with the VFS system.

vtable : The VFSConstructor vtable to register.
Returns : TRUE on success, FALSE on failure.

vfs_file_get_contents ()

void                vfs_file_get_contents               (const gchar *filename,
                                                         gchar **buf,
                                                         gsize *size);

filename : the filename to read in
buf : pointer to pointer of buffer
size :