IpatchFile

IpatchFile — A file object.

Synopsis




                    IpatchFileIOFuncs;
                    IpatchFileBuf;
                    IpatchFile;
                    IpatchFileClass;
#define             IPATCH_FILE_UNUSED_FLAG_SHIFT
#define             IPATCH_FILE_IS_OPEN                 (file)
#define             IPATCH_FILE_NEED_SWAP               (file)
#define             IPATCH_FILE_BIG_ENDIAN              (file)
#define             IPATCH_FILE_SWAP16                  (file, p16)
#define             IPATCH_FILE_SWAP32                  (file, p32)
#define             IPATCH_FILE_SWAP64                  (file, p64)
IpatchFile*         ipatch_file_new                     (void);
void                ipatch_file_set_name                (IpatchFile *file,
                                                         const char *file_name);
char*               ipatch_file_get_name                (IpatchFile *file);
gboolean            ipatch_file_open                    (IpatchFile *file,
                                                         const char *file_name,
                                                         const char *mode,
                                                         GError **err);
gboolean            ipatch_file_open_with_fd            (IpatchFile *file,
                                                         int fd,
                                                         GError **err);
gboolean            ipatch_file_open_with_io_channel    (IpatchFile *file,
                                                         GIOChannel *iochan,
                                                         GError **err);
GIOChannel*         ipatch_file_ref_io_channel          (IpatchFile *file);
int                 ipatch_file_get_fd                  (IpatchFile *file);
gboolean            ipatch_file_is_open                 (IpatchFile *file);
void                ipatch_file_close                   (IpatchFile *file);
int                 ipatch_file_get_position            (IpatchFile *file);
void                ipatch_file_update_position         (IpatchFile *file,
                                                         int offset);
gboolean            ipatch_file_read                    (IpatchFile *file,
                                                         gpointer buf,
                                                         guint size,
                                                         GError **err);
GIOStatus           ipatch_file_read_eof                (IpatchFile *file,
                                                         gpointer buf,
                                                         guint size,
                                                         guint *bytes_read,
                                                         GError **err);
gboolean            ipatch_file_write                   (IpatchFile *file,
                                                         gconstpointer buf,
                                                         guint size,
                                                         GError **err);
#define             ipatch_file_skip                    (file, offset, err)
gboolean            ipatch_file_seek                    (IpatchFile *file,
                                                         int offset,
                                                         GSeekType type,
                                                         GError **err);
GIOStatus           ipatch_file_seek_eof                (IpatchFile *file,
                                                         int offset,
                                                         GSeekType type,
                                                         GError **err);
GType               ipatch_file_identify                (IpatchFile *file,
                                                         GError **err);
IpatchFile*         ipatch_file_identify_open           (const char *file_name,
                                                         const char *mode,
                                                         GError **err);
IpatchFile*         ipatch_file_convert_type            (IpatchFile *file,
                                                         GType new_type);
void                ipatch_file_set_little_endian       (IpatchFile *file);
void                ipatch_file_set_big_endian          (IpatchFile *file);
gboolean            ipatch_file_read_u8                 (IpatchFile *file,
                                                         guint8 *val,
                                                         GError **err);
gboolean            ipatch_file_read_u16                (IpatchFile *file,
                                                         guint16 *val,
                                                         GError **err);
gboolean            ipatch_file_read_u32                (IpatchFile *file,
                                                         guint32 *val,
                                                         GError **err);
gboolean            ipatch_file_read_u64                (IpatchFile *file,
                                                         guint64 *val,
                                                         GError **err);
gboolean            ipatch_file_read_s8                 (IpatchFile *file,
                                                         gint8 *val,
                                                         GError **err);
gboolean            ipatch_file_read_s16                (IpatchFile *file,
                                                         gint16 *val,
                                                         GError **err);
gboolean            ipatch_file_read_s32                (IpatchFile *file,
                                                         gint32 *val,
                                                         GError **err);
gboolean            ipatch_file_read_s64                (IpatchFile *file,
                                                         gint64 *val,
                                                         GError **err);
gboolean            ipatch_file_write_u8                (IpatchFile *file,
                                                         guint8 val,
                                                         GError **err);
gboolean            ipatch_file_write_u16               (IpatchFile *file,
                                                         guint16 val,
                                                         GError **err);
gboolean            ipatch_file_write_u32               (IpatchFile *file,
                                                         guint32 val,
                                                         GError **err);
gboolean            ipatch_file_write_u64               (IpatchFile *file,
                                                         guint64 val,
                                                         GError **err);
gboolean            ipatch_file_write_s8                (IpatchFile *file,
                                                         gint8 val,
                                                         GError **err);
gboolean            ipatch_file_write_s16               (IpatchFile *file,
                                                         gint16 val,
                                                         GError **err);
gboolean            ipatch_file_write_s32               (IpatchFile *file,
                                                         gint32 val,
                                                         GError **err);
gboolean            ipatch_file_write_s64               (IpatchFile *file,
                                                         gint64 val,
                                                         GError **err);
void                ipatch_file_buf_init                (IpatchFile *file,
                                                         IpatchFileBuf *filebuf,
                                                         gpointer buf,
                                                         guint size);
void                ipatch_file_buf_free                (IpatchFileBuf *filebuf);
gboolean            ipatch_file_buf_load                (IpatchFileBuf *filebuf,
                                                         guint size,
                                                         GError **err);
void                ipatch_file_buf_read                (IpatchFileBuf *filebuf,
                                                         gpointer buf,
                                                         guint size);
void                ipatch_file_buf_write               (IpatchFileBuf *filebuf,
                                                         gconstpointer buf,
                                                         guint size);
#define             ipatch_file_buf_zero                (filebuf, size)
gboolean            ipatch_file_buf_commit              (IpatchFileBuf *filebuf,
                                                         GError **err);
#define             ipatch_file_buf_skip                (filebuf, offset)
void                ipatch_file_buf_seek                (IpatchFileBuf *filebuf,
                                                         int offset,
                                                         GSeekType type);
guint8              ipatch_file_buf_read_u8             (IpatchFileBuf *filebuf);
guint16             ipatch_file_buf_read_u16            (IpatchFileBuf *filebuf);
guint32             ipatch_file_buf_read_u32            (IpatchFileBuf *filebuf);
guint64             ipatch_file_buf_read_u64            (IpatchFileBuf *filebuf);
gint8               ipatch_file_buf_read_s8             (IpatchFileBuf *filebuf);
gint16              ipatch_file_buf_read_s16            (IpatchFileBuf *filebuf);
gint32              ipatch_file_buf_read_s32            (IpatchFileBuf *filebuf);
gint64              ipatch_file_buf_read_s64            (IpatchFileBuf *filebuf);
void                ipatch_file_buf_write_u8            (IpatchFileBuf *filebuf,
                                                         guint8 val);
void                ipatch_file_buf_write_u16           (IpatchFileBuf *filebuf,
                                                         guint16 val);
void                ipatch_file_buf_write_u32           (IpatchFileBuf *filebuf,
                                                         guint32 val);
void                ipatch_file_buf_write_u64           (IpatchFileBuf *filebuf,
                                                         guint64 val);
void                ipatch_file_buf_write_s8            (IpatchFileBuf *filebuf,
                                                         gint8 val);
void                ipatch_file_buf_write_s16           (IpatchFileBuf *filebuf,
                                                         gint16 val);
void                ipatch_file_buf_write_s32           (IpatchFileBuf *filebuf,
                                                         gint32 val);
void                ipatch_file_buf_write_s64           (IpatchFileBuf *filebuf,
                                                         gint64 val);
void                ipatch_file_set_iofuncs_static      (IpatchFile *file,
                                                         IpatchFileIOFuncs *funcs);
void                ipatch_file_set_iofuncs             (IpatchFile *file,
                                                         const IpatchFileIOFuncs *funcs);
void                ipatch_file_get_iofuncs             (IpatchFile *file,
                                                         IpatchFileIOFuncs *out_funcs);
void                ipatch_file_set_iofuncs_null        (IpatchFile *file);
gboolean            ipatch_file_default_open_method     (IpatchFile *file,
                                                         const char *mode,
                                                         GError **err);
void                ipatch_file_default_close_method    (IpatchFile *file);
GIOStatus           ipatch_file_default_read_method     (IpatchFile *file,
                                                         gpointer buf,
                                                         guint size,
                                                         guint *bytes_read,
                                                         GError **err);
GIOStatus           ipatch_file_default_write_method    (IpatchFile *file,
                                                         gconstpointer buf,
                                                         guint size,
                                                         GError **err);
GIOStatus           ipatch_file_default_seek_method     (IpatchFile *file,
                                                         int offset,
                                                         GSeekType type,
                                                         GError **err);
int                 ipatch_file_default_getfd_method    (IpatchFile *file);

Object Hierarchy


  GObject
   +----IpatchItem
         +----IpatchFile
               +----IpatchSampleFile
               +----IpatchDLSFile
               +----IpatchSF2File
               +----IpatchCramFile

Properties


  "close-on-finalize"        gboolean              : Read / Write
  "file-name"                gchararray            : Read / Write
  "open"                     gboolean              : Read

Signals


  "pos-change"                                     : Run First

Description

An object for sharing open files and also a base class for specific file types. This object provides file reference counting, multi-thread friendly IO functions, endian byte swapping, and file identification using actual file data and file extensions.

Details

IpatchFileIOFuncs

typedef struct {
  gboolean (*open)(IpatchFile *file, const char *mode, GError **err);
  void (*close)(IpatchFile *file);
  GIOStatus (*read)(IpatchFile *file, gpointer buf, guint size,
		    guint *bytes_read, GError **err);
  GIOStatus (*write)(IpatchFile *file, gconstpointer buf, guint size,
		     GError **err);
  GIOStatus (*seek)(IpatchFile *file, int offset, GSeekType type,
		    GError **err);
  int (*getfd)(IpatchFile *file); /* optional get file descriptor method */
  int (*get_size)(IpatchFile *file, GError **err);  /* optional get size method */
} IpatchFileIOFuncs;


IpatchFileBuf

typedef struct {
  IpatchFile *file;		/* the file loading/saving from/to */
  gpointer buf;			/* the data buffer */
  int pos;			/* current position in buffer */
  int buf_size;			/* total buffer size */
  int data_size;		/* data size */
  gboolean allocated;		/* set if buffer was allocated */
} IpatchFileBuf;


IpatchFile

typedef struct _IpatchFile IpatchFile;


IpatchFileClass

typedef struct {
  IpatchItemClass parent_class;


  /* signals */
  void (*pos_change)(IpatchFile *file, gint32 offset);

  /* methods */
  gboolean (*identify)(IpatchFile *file);
} IpatchFileClass;


IPATCH_FILE_UNUSED_FLAG_SHIFT

#define IPATCH_FILE_UNUSED_FLAG_SHIFT  (IPATCH_ITEM_UNUSED_FLAG_SHIFT + 8)


IPATCH_FILE_IS_OPEN()

#define             IPATCH_FILE_IS_OPEN(file)

file :

IPATCH_FILE_NEED_SWAP()

#define             IPATCH_FILE_NEED_SWAP(file)

file :

IPATCH_FILE_BIG_ENDIAN()

#define             IPATCH_FILE_BIG_ENDIAN(file)

file :

IPATCH_FILE_SWAP16()

#define             IPATCH_FILE_SWAP16(file, p16)

file :
p16 :

IPATCH_FILE_SWAP32()

#define             IPATCH_FILE_SWAP32(file, p32)

file :
p32 :

IPATCH_FILE_SWAP64()

#define             IPATCH_FILE_SWAP64(file, p64)

file :
p64 :

ipatch_file_new ()

IpatchFile*         ipatch_file_new                     (void);

Create a new file object

Returns : The new file object

ipatch_file_set_name ()

void                ipatch_file_set_name                (IpatchFile *file,
                                                         const char *file_name);

Sets the file name of a file object. The file name of a file object should not be relied apon as referencing the same file as the file object itself. It is used for information purposes only and with the ipatch_file_open() and ipatch_file_identify() functions.

file : File object to assign file name to
file_name : File name or NULL to unset the file name

ipatch_file_get_name ()

char*               ipatch_file_get_name                (IpatchFile *file);

Gets the assigned file name from a file object.

file : File object to get file name from
Returns : The file name of the file object or NULL if not set. String should be freed when finished with it.

ipatch_file_open ()

gboolean            ipatch_file_open                    (IpatchFile *file,
                                                         const char *file_name,
                                                         const char *mode,
                                                         GError **err);

Opens a file and assigns it to a file object. The file will be closed when the IpatchFile object is destroyed, unless the "close-on-finalize" flag is cleared.

file : File object to open from a file name.
file_name : Name of file to open or NULL to use the file object's assigned file name (in which case should not be NULL).
mode : File open mode ("r", "w", etc) see g_io_channel_new_file() or fopen() for more info
err : Error information
Returns : TRUE on success, FALSE otherwise in which case error information should be found in err provided its not NULL.

ipatch_file_open_with_fd ()

gboolean            ipatch_file_open_with_fd            (IpatchFile *file,
                                                         int fd,
                                                         GError **err);

An alternative to ipatch_file_open() to use an existing open file descriptor. The "close-on-finalize" flag is not set, so the file will remain open after the IpatchFile object is destroyed.

file : File object to open using an open file descriptor
fd : File descriptor to assign to file object.
err : Location to store error information or NULL.
Returns : TRUE on success, FALSE otherwise

ipatch_file_open_with_io_channel ()

gboolean            ipatch_file_open_with_io_channel    (IpatchFile *file,
                                                         GIOChannel *iochan,
                                                         GError **err);

Sets a file object's io channel directly and increments its reference count. An alternative to ipatch_file_open() and ipatch_file_open_with_fd() when using a custom or existing io channel. The "close-on-finalize" flag is not set, so the io channel will remain open even after the IpatchFile is destroyed.

file : File object to open using an open io channel
iochan : IO channel to assign to file
err : Location to store error information or NULL
Returns : TRUE on success, FALSE otherwise

ipatch_file_ref_io_channel ()

GIOChannel*         ipatch_file_ref_io_channel          (IpatchFile *file);

Get the glib IO channel object from a file object. The caller owns a reference to the returned io channel, and should be unreferenced with g_io_channel_unref() when finished with it.

MT-NOTE: Use of the io channel directly subverts multi-thread locking. Caller is responsible for locking the file item during any operations using the io channel, if necessary.

file : File object to get io channel object from
Returns : GIOChannel assigned to the file object or NULL if none (some derived IpatchFile types might not use io channels). Remember to unref it with g_io_channel_unref() when finished.

ipatch_file_get_fd ()

int                 ipatch_file_get_fd                  (IpatchFile *file);

Get the unix file descriptor associated with a file object. Not all file objects have a file descriptor.

file : File object
Returns : File descriptor or -1 if not open or failed to get descriptor.

ipatch_file_is_open ()

gboolean            ipatch_file_is_open                 (IpatchFile *file);

Checks if a file object is open.

file : File object to check state of
Returns : TRUE if file is open, FALSE otherwise.

ipatch_file_close ()

void                ipatch_file_close                   (IpatchFile *file);

Close a file object.

file : File to close

ipatch_file_get_position ()

int                 ipatch_file_get_position            (IpatchFile *file);

Gets the value of the position counter in a file object. Note that this might not be the actual position in the file if the file object was attached to an already open file or if ipatch_file_update_position() is used to set virtual positions.

file : File object
Returns : Value of position counter in file object.

ipatch_file_update_position ()

void                ipatch_file_update_position         (IpatchFile *file,
                                                         int offset);

Adds an offset value to the position counter in a file object. This can be used if one is operating directly on the underlying file object (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).

file : File object
offset : Offset to add to the position counter (can be negative)

ipatch_file_read ()

gboolean            ipatch_file_read                    (IpatchFile *file,
                                                         gpointer buf,
                                                         guint size,
                                                         GError **err);

Reads data from a file object. 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.

file : File object
buf : Buffer to read data into
size : Amount of data to read, in bytes.
err : A location to return an error of type GIOChannelError or NULL.
Returns : TRUE on success (the requested size of data was read), FALSE otherwise

ipatch_file_read_eof ()

GIOStatus           ipatch_file_read_eof                (IpatchFile *file,
                                                         gpointer buf,
                                                         guint size,
                                                         guint *bytes_read,
                                                         GError **err);

Reads data from a file object. 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.

file : File object
buf : Buffer to read data into
size : Amount of data to read, in bytes.
bytes_read : Pointer to store number of bytes actually read or NULL.
err : A location to return an error of type GIOChannelError or NULL.
Returns : The status of the operation

ipatch_file_write ()

gboolean            ipatch_file_write                   (IpatchFile *file,
                                                         gconstpointer buf,
                                                         guint size,
                                                         GError **err);

Writes data to a file object.

file : File object
buf : Buffer of data to write
size : Amount of data to write, in bytes.
err : A location to return an error of type GIOChannelError or NULL.
Returns : The status of the operation

ipatch_file_skip()

#define             ipatch_file_skip(file, offset, err)

file :
offset :
err :

ipatch_file_seek ()

gboolean            ipatch_file_seek                    (IpatchFile *file,
                                                         int offset,
                                                         GSeekType type,
                                                         GError **err);

Seek in a file object. An end of file condition is treated as an error, use ipatch_file_seek_eof() if this is undesirable.

file : File object to seek in
offset : Offset in bytes to seek from the position specified by type
type : Position in file to seek from (see g_io_channel_seek_position for more details, only G_SEEK_CUR and G_SEEK_SET allowed).
err : A location to return error info or NULL.
Returns : TRUE on success, FALSE otherwise

ipatch_file_seek_eof ()

GIOStatus           ipatch_file_seek_eof                (IpatchFile *file,
                                                         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.

file : File object to seek in
offset : Offset in bytes to seek from the position specified by type
type : Position in file to seek from (see g_io_channel_seek_position for more details, only G_SEEK_CUR and G_SEEK_SET allowed).
err : A location to return error info or NULL.
Returns : The status of the operation

ipatch_file_identify ()

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. If the file object is open then the "identify" methods may check the content of the file itself, otherwise the extension of the file object's assigned file name is used. In the latter case the assigned file name should not be NULL.

file : File object to identify type of
err : Location to store error information
Returns : 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.

ipatch_file_identify_open ()

IpatchFile*         ipatch_file_identify_open           (const char *file_name,
                                                         const char *mode,
                                                         GError **err);

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() using mode. A convenience function really.

file_name : File name to identify and open
mode : Mode to open file with (if it is identified)
err : Location to store error of type GIOChannelError
Returns : The new file object of the identified type or NULL if unable to identify.

ipatch_file_convert_type ()

IpatchFile*         ipatch_file_convert_type            (IpatchFile *file,
                                                         GType new_type);

Converts an open file to another IpatchFile type. After a successful call to this function the original file will be unset (won't reference the actual file descriptor anymore) and the returned file will have taken it over.

file : File to convert to a new file type
new_type : New IpatchFile derived type
Returns : a new file with a refcount of 1.

ipatch_file_set_little_endian ()

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.

file : File object

ipatch_file_set_big_endian ()

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.

file : File object

ipatch_file_read_u8 ()

gboolean            ipatch_file_read_u8                 (IpatchFile *file,
                                                         guint8 *val,
                                                         GError **err);

Read an unsigned 8 bit integer from a file.

file : File to read from
val : Location to store value
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_read_u16 ()

gboolean            ipatch_file_read_u16                (IpatchFile *file,
                                                         guint16 *val,
                                                         GError **err);

Read an unsigned 16 bit integer from a file and performs endian byte swapping if necessary.

file : File to read from
val : Location to store value
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_read_u32 ()

gboolean            ipatch_file_read_u32                (IpatchFile *file,
                                                         guint32 *val,
                                                         GError **err);

Read an unsigned 32 bit integer from a file and performs endian byte swapping if necessary.

file : File to read from
val : Location to store value
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_read_u64 ()

gboolean            ipatch_file_read_u64                (IpatchFile *file,
                                                         guint64 *val,
                                                         GError **err);

Read an unsigned 64 bit integer from a file and performs endian byte swapping if necessary.

file : File to read from
val : Location to store value
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_read_s8 ()

gboolean            ipatch_file_read_s8                 (IpatchFile *file,
                                                         gint8 *val,
                                                         GError **err);

Read a signed 8 bit integer from a file.

file : File to read from
val : Location to store value
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_read_s16 ()

gboolean            ipatch_file_read_s16                (IpatchFile *file,
                                                         gint16 *val,
                                                         GError **err);

Read a signed 16 bit integer from a file and performs endian byte swapping if necessary.

file : File to read from
val : Location to store value
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_read_s32 ()

gboolean            ipatch_file_read_s32                (IpatchFile *file,
                                                         gint32 *val,
                                                         GError **err);

Read a signed 32 bit integer from a file and performs endian byte swapping if necessary.

file : File to read from
val : Location to store value
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_read_s64 ()

gboolean            ipatch_file_read_s64                (IpatchFile *file,
                                                         gint64 *val,
                                                         GError **err);

Read a signed 64 bit integer from a file and performs endian byte swapping if necessary.

file : File to read from
val : Location to store value
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_write_u8 ()

gboolean            ipatch_file_write_u8                (IpatchFile *file,
                                                         guint8 val,
                                                         GError **err);

Write an unsigned 8 bit integer to a file.

file : File to write to
val : Value to store
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_write_u16 ()

gboolean            ipatch_file_write_u16               (IpatchFile *file,
                                                         guint16 val,
                                                         GError **err);

Write an unsigned 16 bit integer to a file and performs endian byte swapping if necessary.

file : File to write to
val : Value to store
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_write_u32 ()

gboolean            ipatch_file_write_u32               (IpatchFile *file,
                                                         guint32 val,
                                                         GError **err);

Write an unsigned 32 bit integer to a file and performs endian byte swapping if necessary.

file : File to write to
val : Value to store
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_write_u64 ()

gboolean            ipatch_file_write_u64               (IpatchFile *file,
                                                         guint64 val,
                                                         GError **err);

Write an unsigned 64 bit integer to a file and performs endian byte swapping if necessary.

file : File to write to
val : Value to store
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_write_s8 ()

gboolean            ipatch_file_write_s8                (IpatchFile *file,
                                                         gint8 val,
                                                         GError **err);

Write a signed 8 bit integer to a file.

file : File to write to
val : Value to store
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_write_s16 ()

gboolean            ipatch_file_write_s16               (IpatchFile *file,
                                                         gint16 val,
                                                         GError **err);

Write a signed 16 bit integer to a file and performs endian byte swapping if necessary.

file : File to write to
val : Value to store
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_write_s32 ()

gboolean            ipatch_file_write_s32               (IpatchFile *file,
                                                         gint32 val,
                                                         GError **err);

Write a signed 32 bit integer to a file and performs endian byte swapping if necessary.

file : File to write to
val : Value to store
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_write_s64 ()

gboolean            ipatch_file_write_s64               (IpatchFile *file,
                                                         gint64 val,
                                                         GError **err);

Write a signed 64 bit integer to a file and performs endian byte swapping if necessary.

file : File to write to
val : Value to store
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise (in which case err may be set).

ipatch_file_buf_init ()

void                ipatch_file_buf_init                (IpatchFile *file,
                                                         IpatchFileBuf *filebuf,
                                                         gpointer buf,
                                                         guint size);

Initializes a file buffer structure for use in buffered read and write operations. If this function is called with filebuf set to NULL the buffer will be allocated and should be freed at a later time with ipatch_file_buf_free().

file : File object
filebuf : Pointer to a user supplied buffer structure (usually on the stack)
buf : Pointer to data buffer to use or NULL to allocate one
size : Size of buf or size to allocate if buf is NULL

ipatch_file_buf_free ()

void                ipatch_file_buf_free                (IpatchFileBuf *filebuf);

Frees the data buffer of a file buffer structure. Not necessary to call this function if the file buffer was initialized with a user supplied data buffer, but won't break if you do.

filebuf : File buffer structure

ipatch_file_buf_load ()

gboolean            ipatch_file_buf_load                (IpatchFileBuf *filebuf,
                                                         guint size,
                                                         GError **err);

Load data from a file file into a buffer for convenient parsing.

filebuf : Initialized file buffer structure
size : Size of data to load
err : Location to store error info or NULL
Returns : TRUE on success, FALSE on error.

ipatch_file_buf_read ()

void                ipatch_file_buf_read                (IpatchFileBuf *filebuf,
                                                         gpointer buf,
                                                         guint size);

Read data from a file buffer and advance the buffer's current position.

filebuf : Initialized file buffer structure with loaded data
buf : Buffer to copy data to
size : Amount of data to copy in bytes

ipatch_file_buf_write ()

void                ipatch_file_buf_write               (IpatchFileBuf *filebuf,
                                                         gconstpointer buf,
                                                         guint size);

Write data to a file buffer and advance the buffer's current position. Caller is responsible for ensuring there is enough space in the file buffer.

filebuf : Initialized file buffer structure to write data to
buf : Buffer to copy data from
size : Amount of data to copy in bytes

ipatch_file_buf_zero()

#define             ipatch_file_buf_zero(filebuf, size)

filebuf :
size :

ipatch_file_buf_commit ()

gboolean            ipatch_file_buf_commit              (IpatchFileBuf *filebuf,
                                                         GError **err);

Writes all data in a file buffer to its file object and resets the position back to the beginning of the buffer.

filebuf : Initialized file buffer with data to save
err : Location to store error info or NULL
Returns : TRUE on success, FALSE otherwise

ipatch_file_buf_skip()

#define             ipatch_file_buf_skip(filebuf, offset)

filebuf :
offset :

ipatch_file_buf_seek ()

void                ipatch_file_buf_seek                (IpatchFileBuf *filebuf,
                                                         int offset,
                                                         GSeekType type);

Seeks the current position in a file buffer specified by an offset and seek type.

filebuf : Initialized file buffer structure with loaded data
offset : Offset to seek
type : Seek type

ipatch_file_buf_read_u8 ()

guint8              ipatch_file_buf_read_u8             (IpatchFileBuf *filebuf);

Reads an unsigned byte from a file buffer and advances the buffer's current position.

filebuf : Initialized file buffer structure with loaded data
Returns : The value.

ipatch_file_buf_read_u16 ()

guint16             ipatch_file_buf_read_u16            (IpatchFileBuf *filebuf);

Reads an unsigned 16 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.

filebuf : Initialized file buffer structure with loaded data
Returns : The value.

ipatch_file_buf_read_u32 ()

guint32             ipatch_file_buf_read_u32            (IpatchFileBuf *filebuf);

Reads an unsigned 32 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.

filebuf : Initialized file buffer structure with loaded data
Returns : The value.

ipatch_file_buf_read_u64 ()

guint64             ipatch_file_buf_read_u64            (IpatchFileBuf *filebuf);

Reads an unsigned 64 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.

filebuf : Initialized file buffer structure with loaded data
Returns : The value.

ipatch_file_buf_read_s8 ()

gint8               ipatch_file_buf_read_s8             (IpatchFileBuf *filebuf);

Reads a signed byte from a file buffer and advances the buffer's current position.

filebuf : Initialized file buffer structure with loaded data
Returns : The value.

ipatch_file_buf_read_s16 ()

gint16              ipatch_file_buf_read_s16            (IpatchFileBuf *filebuf);

Reads a signed 16 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.

filebuf : Initialized file buffer structure with loaded data
Returns : The value.

ipatch_file_buf_read_s32 ()

gint32              ipatch_file_buf_read_s32            (IpatchFileBuf *filebuf);

Reads a signed 32 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.

filebuf : Initialized file buffer structure with loaded data
Returns : The value.

ipatch_file_buf_read_s64 ()

gint64              ipatch_file_buf_read_s64            (IpatchFileBuf *filebuf);

Reads a signed 64 bit word from a file buffer and advances the buffer's current position. Performs endian byte swapping if necessary.

filebuf : Initialized file buffer structure with loaded data
Returns : The value.

ipatch_file_buf_write_u8 ()

void                ipatch_file_buf_write_u8            (IpatchFileBuf *filebuf,
                                                         guint8 val);

Writes an unsigned byte to a file buffer and advances the buffer's current position. The file buffer's size should not be exceeded.

filebuf : Initialized file buffer structure
val : Value to write into file buffer

ipatch_file_buf_write_u16 ()

void                ipatch_file_buf_write_u16           (IpatchFileBuf *filebuf,
                                                         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's size should not be exceeded.

filebuf : Initialized file buffer structure
val : Value to write into file buffer

ipatch_file_buf_write_u32 ()

void                ipatch_file_buf_write_u32           (IpatchFileBuf *filebuf,
                                                         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's size should not be exceeded.

filebuf : Initialized file buffer structure
val : Value to write into file buffer

ipatch_file_buf_write_u64 ()

void                ipatch_file_buf_write_u64           (IpatchFileBuf *filebuf,
                                                         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's size should not be exceeded.

filebuf : Initialized file buffer structure
val : Value to write into file buffer

ipatch_file_buf_write_s8 ()

void                ipatch_file_buf_write_s8            (IpatchFileBuf *filebuf,
                                                         gint8 val);

Writes a signed byte to a file buffer and advances the buffer's current position. The file buffer's size should not be exceeded.

filebuf : Initialized file buffer structure
val : Value to write into file buffer

ipatch_file_buf_write_s16 ()

void                ipatch_file_buf_write_s16           (IpatchFileBuf *filebuf,
                                                         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's size should not be exceeded.

filebuf : Initialized file buffer structure
val : Value to write into file buffer

ipatch_file_buf_write_s32 ()

void                ipatch_file_buf_write_s32           (IpatchFileBuf *filebuf,
                                                         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's size should not be exceeded.

filebuf : Initialized file buffer structure
val : Value to write into file buffer

ipatch_file_buf_write_s64 ()

void                ipatch_file_buf_write_s64           (IpatchFileBuf *filebuf,
                                                         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's size should not be exceeded.

filebuf : Initialized file buffer structure
val : Value to write into file buffer

ipatch_file_set_iofuncs_static ()

void                ipatch_file_set_iofuncs_static      (IpatchFile *file,
                                                         IpatchFileIOFuncs *funcs);

Sets the input/output functions of a file object using a statically allocated (or guaranteed exist for lifetime of file) functions structure. Setting these functions allows one to write custom data sources or hook into other file functions.

file : File object
funcs : Static IO functions structure or NULL to set to defaults

ipatch_file_set_iofuncs ()

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.

file : File object
funcs : IO functions structure or NULL to set to defaults

ipatch_file_get_iofuncs ()

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.

file : File object
out_funcs : Location to store current IO functions to

ipatch_file_set_iofuncs_null ()

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.

file : File object

ipatch_file_default_open_method ()

gboolean            ipatch_file_default_open_method     (IpatchFile *file,
                                                         const char *mode,
                                                         GError **err);

Default "open" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions.

file : File object
mode : File open mode
err : Error info
Returns : TRUE on success, FALSE otherwise

ipatch_file_default_close_method ()

void                ipatch_file_default_close_method    (IpatchFile *file);

Default "close" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions.

file : File object

ipatch_file_default_read_method ()

GIOStatus           ipatch_file_default_read_method     (IpatchFile *file,
                                                         gpointer buf,
                                                         guint size,
                                                         guint *bytes_read,
                                                         GError **err);

Default "read" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions.

file : File object
buf : Buffer to store data to
size : Size of data
bytes_read : Number of bytes actually read
err : Error info
Returns : The status of the operation.

ipatch_file_default_write_method ()

GIOStatus           ipatch_file_default_write_method    (IpatchFile *file,
                                                         gconstpointer buf,
                                                         guint size,
                                                         GError **err);

Default "write" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions.

file : File object
buf : Buffer to read data from
size : Size of data
err : Error info
Returns : The status of the operation.

ipatch_file_default_seek_method ()

GIOStatus           ipatch_file_default_seek_method     (IpatchFile *file,
                                                         int offset,
                                                         GSeekType type,
                                                         GError **err);

Default "seek" method for IpatchFileIOFuncs. Useful when overriding only some I/O functions.

file : File object
offset : Offset (depends on seek type)
type : Seek type
err : Error info
Returns : The status of the operation.

ipatch_file_default_getfd_method ()

int                 ipatch_file_default_getfd_method    (IpatchFile *file);

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.

file : File object
Returns : Unix file descriptor or -1 if no file descriptor or error.

Property Details

The "close-on-finalize" property

  "close-on-finalize"        gboolean              : Read / Write

Close on finalize.

Default value: FALSE


The "file-name" property

  "file-name"                gchararray            : Read / Write

Name and path of file.

Default value: NULL


The "open" property

  "open"                     gboolean              : Read

The file is open.

Default value: FALSE

Signal Details

The "pos-change" signal

void                user_function                      (IpatchFile *ipatchfile,
                                                        gint        arg1,
                                                        gpointer    user_data)       : Run First

ipatchfile : the object which received the signal.
arg1 :
user_data : user data set when the signal handler was connected.