Top | ![]() |
![]() |
![]() |
![]() |
struct | IpatchFileIOFuncs |
enum | IpatchFileFlags |
enum | IpatchFileIdentifyOrder |
#define | IPATCH_FILE_UNUSED_FLAG_SHIFT |
struct | IpatchFileHandle |
GBoxed ╰── IpatchFileHandle GObject ╰── IpatchItem ╰── IpatchFile ├── IpatchDLSFile ├── IpatchSF2File ├── IpatchSLIFile ╰── IpatchSndFile
IpatchFile * ipatch_file_pool_new (const char *file_name
,gboolean *created
);
Lookup existing file object from file pool by file name or create a new one if not open.
file_name |
File name (converted to an absolute file name if it isn't already) |
|
created |
Location to store |
[out][optional] |
Since: 1.1.0
IpatchFile *
ipatch_file_pool_lookup (const char *file_name
);
Lookup an existing file object in the file pool, by file name. Does not
create a new object, if not found, like ipatch_file_pool_new()
does.
Matching file object with a reference that the caller owns
or NULL
if not found.
[transfer full]
Since: 1.1.0
void ipatch_file_ref_from_object (IpatchFile *file
,GObject *object
);
Reference a file object from another object and keep track of the
external reference (using a GWeakRef). References can be obtained with
ipatch_file_get_refs()
. Use ipatch_file_unref_from_object()
to remove
the reference, although the registration will be removed regardless at some
point if object
gets destroyed and ipatch_file_get_refs()
or
ipatch_file_get_refs_by_type()
is called.
file |
File object to add a reference to ( |
|
object |
Object which is referencing the |
Since: 1.1.0
void ipatch_file_unref_from_object (IpatchFile *file
,GObject *object
);
Remove a reference previously registered with ipatch_file_ref_from_object()
.
This will get done eventually if object
gets destroyed and ipatch_file_get_refs()
or ipatch_file_get_refs_by_type()
is called, however.
file |
File object to remove a reference from ( |
|
object |
Object which is unreferencing the |
Since: 1.1.0
gboolean ipatch_file_test_ref_object (IpatchFile *file
,GObject *object
);
Check if a given object
is referencing file
. Must have been
referenced with ipatch_file_ref_from_object()
.
Since: 1.1.0
IpatchList *
ipatch_file_get_refs (IpatchFile *file
);
Get list of objects referencing a file object.
NOTE: A side effect of calling this function is that any references from
destroyed objects are removed (if ipatch_file_unref_from_object()
was not used).
New object list which caller owns a reference to, unreference when finished using it.
[transfer full]
Since: 1.1.0
IpatchList * ipatch_file_get_refs_by_type (IpatchFile *file
,GType type
);
Like ipatch_file_get_refs()
but only returns objects matching a given type
or a descendant thereof.
file |
File object to get external references of |
|
type |
Object type to match (or a descendant thereof) or G_TYPE_NONE to match any type |
New object list which caller owns a reference to, unreference when finished using it.
[transfer full]
Since: 1.1.0
void ipatch_file_set_name (IpatchFile *file
,const char *file_name
);
Sets the file name of a file object. Assigning the file name of an IpatchFile object is optional, since a file descriptor could be assigned instead, but some subsystems depend on it.
char *
ipatch_file_get_name (IpatchFile *file
);
Gets the assigned file name from a file object.
gboolean ipatch_file_rename (IpatchFile *file
,const char *new_name
,GError **err
);
Physically rename the file referenced by a file
object. The given file
object must have a file name assigned and no file descriptor or I/O channel.
On Windows, the file must also not have any open handles. If a file with
new_name
already exists, it will be replaced and should not be referenced by
any file object.
file |
File object to rename |
|
new_name |
New file name (can be a full path to move the file) |
|
err |
Location to store error info or |
Since: 1.1.0
gboolean ipatch_file_unlink (IpatchFile *file
,GError **err
);
Physically delete the file referenced by a file
object. The given file
object must have a file name assigned and no file descriptor or I/O channel.
On Windows, the file must also not have any open handles.
The file object will remain alive, but the underlying file will be unlinked.
Since: 1.1.0
gboolean ipatch_file_replace (IpatchFile *newfile
,IpatchFile *oldfile
,GError **err
);
Replace one file object with another. After successful execution of this function
oldfile
will have an unset file name, newfile
will be assigned what was the oldfile name,
and the file data of the old file on the filesystem will have been replaced by new file.
NOTE: On Windows both files must not have any open file handles.
NOTE: In the event an error occurs, recovery will be attempted, but may also fail, resulting in
loss of oldfile
data.
newfile |
New file to replace the |
|
oldfile |
The old file to replace (must have an assigned “file-name” property) |
|
err |
Location to store error info or |
Since: 1.1.0
IpatchFileHandle * ipatch_file_open (IpatchFile *file
,const char *file_name
,const char *mode
,GError **err
);
Opens a handle to a file object. If a I/O channel or file descriptor is
already assigned (with ipatch_file_assign_fd()
or
ipatch_file_assign_io_channel()
) then it is used instead of opening a file
using file_name
or the already assigned “file-name” property.
void ipatch_file_assign_fd (IpatchFile *file
,int fd
,gboolean close_on_finalize
);
Assigns a file descriptor to a file, which gets used for calls to
ipatch_file_open()
. Note that this means multiple opens will use the same
file descriptor and will therefore conflict, so it should only be used in the
case where the file object is used by a single exclusive handle.
void ipatch_file_assign_io_channel (IpatchFile *file
,GIOChannel *iochan
);
Assigns an I/O channel to a file, which gets used for calls to
ipatch_file_open()
. Note that this means multiple opens will use the same
file descriptor and will therefore conflict, so it should only be used in the
case where the file object is used by a single exclusive handle.
GIOChannel *
ipatch_file_get_io_channel (IpatchFileHandle *handle
);
Get the glib IO channel object from a file handle. The caller owns a
reference to the returned io channel, and it should be unreferenced with
g_io_channel_unref()
when finished with it.
GIOChannel assigned to the handle
or NULL
if none (some
derived IpatchFile types might not use io channels). Remember to unref it
with g_io_channel_unref()
when finished.
int
ipatch_file_get_fd (IpatchFileHandle *handle
);
Get the unix file descriptor associated with a file handle. Not all file handles have a real OS file descriptor.
void
ipatch_file_close (IpatchFileHandle *handle
);
Close a file handle and free it.
guint
ipatch_file_get_position (IpatchFileHandle *handle
);
Gets the current position in a file handle. Note that this
might not be the actual position in the file if the file handle was
attached to an already open file or if ipatch_file_update_position()
is
used to set virtual positions.
void ipatch_file_update_position (IpatchFileHandle *handle
,guint offset
);
Adds an offset value to the position counter in a file handle. This can be used if one is operating directly on the underlying file descriptor (i.e., not using the IpatchFile functions) or to add virtual space to the counter. Adding virtual space is useful when a system uses the position counter to write data (such as the RIFF parser) to act as a place holder for data that isn't actually written (sample data for example).
gboolean ipatch_file_read (IpatchFileHandle *handle
,gpointer buf
,guint size
,GError **err
);
Reads data from a file handle. An end of file encountered while
trying to read the specified size
of data is treated as an error.
If this is undesirable use ipatch_file_read_eof()
instead.
GIOStatus ipatch_file_read_eof (IpatchFileHandle *handle
,gpointer buf
,guint size
,guint *bytes_read
,GError **err
);
Reads data from a file handle. This function does not treat end of file
as an error and will return G_IO_STATUS_EOF with the number of bytes
actually read in bytes_read
. Use ipatch_file_read()
for convenience to
ensure actual number of requested bytes is read.
gboolean ipatch_file_write (IpatchFileHandle *handle
,gconstpointer buf
,guint size
,GError **err
);
Writes data to a file object.
gboolean ipatch_file_seek (IpatchFileHandle *handle
,int offset
,GSeekType type
,GError **err
);
Seek in a file handle. An end of file condition is treated as an error, use
ipatch_file_seek_eof()
if this is undesirable.
GIOStatus ipatch_file_seek_eof (IpatchFileHandle *handle
,int offset
,GSeekType type
,GError **err
);
Seek in a file object. Does not treat end of file as an error, use
ipatch_file_seek()
for convenience if this is desirable.
int ipatch_file_get_size (IpatchFile *file
,GError **err
);
Get the size of a file object.
GType ipatch_file_identify (IpatchFile *file
,GError **err
);
Attempts to identify the type of a file using the "identify" method of registered types derived from IpatchFile. The “file-name” property should already be assigned.
The first IpatchFile derived type that had an "identify" method
which returned TRUE
, or 0 if unknown file type or error, in which
case error information will be stored in err
provided its not NULL
.
GType ipatch_file_identify_name (const char *filename
,GError **err
);
Like ipatch_file_identify()
but uses a file name for convenience.
The first IpatchFile derived type that had an "identify" method
which returned TRUE
, or 0 if unknown file type or error, in which
case error information will be stored in err
provided its not NULL
.
Since: 1.1.0
GType
ipatch_file_identify_by_ext (IpatchFile *file
);
Attempts to identify the type of a file using the "identify" method of
registered types derived from IpatchFile. The “file-name” property
should already be assigned. Like ipatch_file_identify()
but identifies a
file by its file name extension only.
The first IpatchFile derived type that had an "identify" method
which returned TRUE
, or 0 if unknown file type or error, in which
case error information will be stored in err
provided its not NULL
.
IpatchFileHandle * ipatch_file_identify_open (const char *file_name
,GError **err
);
A convenience function which calls ipatch_file_identify()
to determine the
file type of file_name
. If the type is identified a new file object, of the
identified type, is created and the file is opened with
ipatch_file_open()
in read mode.
file_name |
File name to identify and open |
|
err |
Location to store error of type GIOChannelError |
The new opened handle of the identified type or NULL
if unable to
identify. Caller should free the handle with ipatch_file_close()
when done
using it, at which point the parent IpatchFile will be destroyed if no other
reference is held.
IpatchFile * ipatch_file_identify_new (const char *file_name
,GError **err
);
A convenience function which calls ipatch_file_identify()
to determine the
file type of file_name
. If the type is identified a new file object, of the
identified type, is created and returned.
file_name |
File name to identify and create file object for |
|
err |
Location to store error of type GIOChannelError |
The new file of the identified type or NULL
if unable to
identify. Caller owns a reference and should remove it when done using it.
Since: 1.1.0
void
ipatch_file_set_little_endian (IpatchFile *file
);
Sets the file object to little endian mode (the default mode). If the system is big endian, byte swapping will be enabled (see IPATCH_FILE_SWAPxx macros). The endian mode affects buffered read and write functions that operate on multi-byte integers.
void
ipatch_file_set_big_endian (IpatchFile *file
);
Sets the file object to big endian mode (the default is little endian). If the system is little endian, byte swapping will be enabled (see IPATCH_FILE_SWAPxx macros). The endian mode affects buffered read and write functions that operate on multi-byte integers.
gboolean ipatch_file_read_u8 (IpatchFileHandle *handle
,guint8 *val
,GError **err
);
Read an unsigned 8 bit integer from a file.
gboolean ipatch_file_read_u16 (IpatchFileHandle *handle
,guint16 *val
,GError **err
);
Read an unsigned 16 bit integer from a file and performs endian byte swapping if necessary.
gboolean ipatch_file_read_u32 (IpatchFileHandle *handle
,guint32 *val
,GError **err
);
Read an unsigned 32 bit integer from a file and performs endian byte swapping if necessary.
gboolean ipatch_file_read_u64 (IpatchFileHandle *handle
,guint64 *val
,GError **err
);
Read an unsigned 64 bit integer from a file and performs endian byte swapping if necessary.
gboolean ipatch_file_read_s8 (IpatchFileHandle *handle
,gint8 *val
,GError **err
);
Read a signed 8 bit integer from a file.
gboolean ipatch_file_read_s16 (IpatchFileHandle *handle
,gint16 *val
,GError **err
);
Read a signed 16 bit integer from a file and performs endian byte swapping if necessary.
gboolean ipatch_file_read_s32 (IpatchFileHandle *handle
,gint32 *val
,GError **err
);
Read a signed 32 bit integer from a file and performs endian byte swapping if necessary.
gboolean ipatch_file_read_s64 (IpatchFileHandle *handle
,gint64 *val
,GError **err
);
Read a signed 64 bit integer from a file and performs endian byte swapping if necessary.
gboolean ipatch_file_write_u8 (IpatchFileHandle *handle
,guint8 val
,GError **err
);
Write an unsigned 8 bit integer to a file.
gboolean ipatch_file_write_u16 (IpatchFileHandle *handle
,guint16 val
,GError **err
);
Write an unsigned 16 bit integer to a file and performs endian byte swapping if necessary.
gboolean ipatch_file_write_u32 (IpatchFileHandle *handle
,guint32 val
,GError **err
);
Write an unsigned 32 bit integer to a file and performs endian byte swapping if necessary.
gboolean ipatch_file_write_u64 (IpatchFileHandle *handle
,guint64 val
,GError **err
);
Write an unsigned 64 bit integer to a file and performs endian byte swapping if necessary.
gboolean ipatch_file_write_s8 (IpatchFileHandle *handle
,gint8 val
,GError **err
);
Write a signed 8 bit integer to a file.
gboolean ipatch_file_write_s16 (IpatchFileHandle *handle
,gint16 val
,GError **err
);
Write a signed 16 bit integer to a file and performs endian byte swapping if necessary.
gboolean ipatch_file_write_s32 (IpatchFileHandle *handle
,gint32 val
,GError **err
);
Write a signed 32 bit integer to a file and performs endian byte swapping if necessary.
gboolean ipatch_file_write_s64 (IpatchFileHandle *handle
,gint64 val
,GError **err
);
Write a signed 64 bit integer to a file and performs endian byte swapping if necessary.
gboolean ipatch_file_buf_load (IpatchFileHandle *handle
,guint size
,GError **err
);
Load data from a file into a buffer for error checking convenience. I/O errors need only be checked on this function and not on the subsequent buffered read function calls. It is an error if an end of file is encountered before all the requested data is read.
void ipatch_file_buf_read (IpatchFileHandle *handle
,gpointer buf
,guint size
);
Read data from a file handle's buffer and advance the buffer's current
position. A call to ipatch_file_buf_load()
must have been previously
executed and there must be enough remaining data in the buffer for the read.
void ipatch_file_buf_write (IpatchFileHandle *handle
,gconstpointer buf
,guint size
);
Write data to a file handle's buffer and advance the buffer's current
position. Buffer is expanded if necessary (since version 1.1.0).
Data will not actually be written to file till ipatch_file_buf_commit()
is
called.
void ipatch_file_buf_memset (IpatchFileHandle *handle
,unsigned char c
,guint size
);
Sets the given size
in bytes to the character c
and advances the
current position. Buffer is expanded if necessary.
void ipatch_file_buf_set_size (IpatchFileHandle *handle
,guint size
);
Sets the size of the buffer of handle
to size
bytes. The buffer is
expanded without initializing the newly allocated part or truncated
as necessary discarding any content over the new size. The current position
is updated to point to the end of the buffer if it would point outside the
new size of the buffer after truncating it.
Since: 1.1.0
gboolean ipatch_file_buf_commit (IpatchFileHandle *handle
,GError **err
);
Writes all data in a file handle's buffer to the file and resets the buffer to empty.
void ipatch_file_buf_seek (IpatchFileHandle *handle
,int offset
,GSeekType type
);
Seeks the current position in a file handle's buffer specified by an offset
and seek type
. It is an error to seek outside of the current size of
buffered data (loaded or written). The offset
is relative to the buffer,
not the file position.
guint8
ipatch_file_buf_read_u8 (IpatchFileHandle *handle
);
Reads an unsigned byte from a file buffer and advances the buffer's current position.
guint16
ipatch_file_buf_read_u16 (IpatchFileHandle *handle
);
Reads an unsigned 16 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.
guint32
ipatch_file_buf_read_u32 (IpatchFileHandle *handle
);
Reads an unsigned 32 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.
guint64
ipatch_file_buf_read_u64 (IpatchFileHandle *handle
);
Reads an unsigned 64 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.
gint8
ipatch_file_buf_read_s8 (IpatchFileHandle *handle
);
Reads a signed byte from a file buffer and advances the buffer's current position.
gint16
ipatch_file_buf_read_s16 (IpatchFileHandle *handle
);
Reads a signed 16 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.
gint32
ipatch_file_buf_read_s32 (IpatchFileHandle *handle
);
Reads a signed 32 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.
gint64
ipatch_file_buf_read_s64 (IpatchFileHandle *handle
);
Reads a signed 64 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.
void ipatch_file_buf_write_u8 (IpatchFileHandle *handle
,guint8 val
);
Writes an unsigned byte to a file buffer and advances the buffer's current position. The file buffer is expanded if needed.
void ipatch_file_buf_write_u16 (IpatchFileHandle *handle
,guint16 val
);
Writes an unsigned 16 bit word to a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary. The file buffer is expanded if needed.
void ipatch_file_buf_write_u32 (IpatchFileHandle *handle
,guint32 val
);
Writes an unsigned 32 bit word to a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary. The file buffer is expanded if needed.
void ipatch_file_buf_write_u64 (IpatchFileHandle *handle
,guint64 val
);
Writes an unsigned 64 bit word to a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary. The file buffer is expanded if needed.
void ipatch_file_buf_write_s8 (IpatchFileHandle *handle
,gint8 val
);
Writes a signed byte to a file buffer and advances the buffer's current position. The file buffer is expanded if needed.
void ipatch_file_buf_write_s16 (IpatchFileHandle *handle
,gint16 val
);
Writes a signed 16 bit word to a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary. The file buffer is expanded if needed.
void ipatch_file_buf_write_s32 (IpatchFileHandle *handle
,gint32 val
);
Writes a signed 32 bit word to a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary. The file buffer is expanded if needed.
void ipatch_file_buf_write_s64 (IpatchFileHandle *handle
,gint64 val
);
Writes a signed 64 bit word to a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary. The file buffer is expanded if needed.
void ipatch_file_set_iofuncs_static (IpatchFile *file
,IpatchFileIOFuncs *funcs
);
Sets the input/output functions of a file object using a statically
allocated (guaranteed to exist for lifetime of file
) functions structure.
Setting these functions allows one to write custom data sources or hook
into other file functions.
void ipatch_file_set_iofuncs (IpatchFile *file
,const IpatchFileIOFuncs *funcs
);
Sets the input/output functions of a file object. The funcs
structure is duplicated so as not to use the original, see
ipatch_file_set_iofuncs_static()
for using a static structure.
Setting these functions allows one to write custom data sources or
hook into other file functions.
void ipatch_file_get_iofuncs (IpatchFile *file
,IpatchFileIOFuncs *out_funcs
);
Get the current IO functions from a file object. The function pointers
are stored in a user supplied structure pointed to by out_funcs
.
void
ipatch_file_set_iofuncs_null (IpatchFile *file
);
Sets the I/O functions of a file object to /dev/null like methods. Reading from the file will return 0s, writing/seeking will do nothing.
gboolean ipatch_file_default_open_method (IpatchFileHandle *handle
,const char *mode
,GError **err
);
Default "open" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions.
[skip]
void
ipatch_file_default_close_method (IpatchFileHandle *handle
);
Default "close" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions.
[skip]
GIOStatus ipatch_file_default_read_method (IpatchFileHandle *handle
,gpointer buf
,guint size
,guint *bytes_read
,GError **err
);
Default "read" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions.
[skip]
GIOStatus ipatch_file_default_write_method (IpatchFileHandle *handle
,gconstpointer buf
,guint size
,GError **err
);
Default "write" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions.
[skip]
GIOStatus ipatch_file_default_seek_method (IpatchFileHandle *handle
,int offset
,GSeekType type
,GError **err
);
Default "seek" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions.
[skip]
int
ipatch_file_default_getfd_method (IpatchFileHandle *handle
);
Default "getfd" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions. This method gets a unix file descriptor for the given file object, it is an optional method.
[skip]
int ipatch_file_default_get_size_method (IpatchFile *file
,GError **err
);
Default get file size method, which is optional.
[skip]
struct IpatchFileIOFuncs { gboolean(*open)(IpatchFileHandle *handle, const char *mode, GError **err); void (*close)(IpatchFileHandle *handle); GIOStatus(*read)(IpatchFileHandle *handle, gpointer buf, guint size, guint *bytes_read, GError **err); GIOStatus(*write)(IpatchFileHandle *handle, gconstpointer buf, guint size, GError **err); GIOStatus(*seek)(IpatchFileHandle *handle, int offset, GSeekType type, GError **err); int (*getfd)(IpatchFileHandle *handle); /* optional get file descriptor method */ int (*get_size)(IpatchFile *file, GError **err); /* optional get size method */ };
Some helpful constants for the identify_order IpatchFileClass field. Note that any value can be used and this enum just provides some helpful values. This value determines in what order file identification methods are called. Higher values are executed first.
#define IPATCH_FILE_UNUSED_FLAG_SHIFT (IPATCH_ITEM_UNUSED_FLAG_SHIFT + 6)
struct IpatchFileHandle { IpatchFile *file; /* Parent file object */ guint position; /* Current file position */ GByteArray *buf; /* For buffered reads/writes */ guint buf_position; /* Current position in buffer */ GIOChannel *iochan; /* glib IO channel (default methods) */ gpointer data; /* iofuncs defined data */ };
IpatchFile handle for opening a file and reading/writing from/to it.