libmobi
C library for handling MOBI format ebook documents
|
Functions to read/write raw big endian data. More...
Functions | |
MOBIBuffer * | mobi_buffer_init (const size_t len) |
Initializer for MOBIBuffer structure. More... | |
MOBIBuffer * | mobi_buffer_init_null (unsigned char *data, const size_t len) |
Initializer for MOBIBuffer structure. More... | |
void | mobi_buffer_resize (MOBIBuffer *buf, const size_t newlen) |
Resize buffer. More... | |
void | mobi_buffer_add8 (MOBIBuffer *buf, const uint8_t data) |
Adds 8-bit value to MOBIBuffer. More... | |
void | mobi_buffer_add16 (MOBIBuffer *buf, const uint16_t data) |
Adds 16-bit value to MOBIBuffer. More... | |
void | mobi_buffer_add32 (MOBIBuffer *buf, const uint32_t data) |
Adds 32-bit value to MOBIBuffer. More... | |
void | mobi_buffer_addraw (MOBIBuffer *buf, const unsigned char *data, const size_t len) |
Adds raw data to MOBIBuffer. More... | |
void | mobi_buffer_addstring (MOBIBuffer *buf, const char *str) |
Adds string to MOBIBuffer without null terminator. More... | |
void | mobi_buffer_addzeros (MOBIBuffer *buf, const size_t count) |
Adds count of zeroes to MOBIBuffer. More... | |
uint8_t | mobi_buffer_get8 (MOBIBuffer *buf) |
Reads 8-bit value from MOBIBuffer. More... | |
uint16_t | mobi_buffer_get16 (MOBIBuffer *buf) |
Reads 16-bit value from MOBIBuffer. More... | |
uint32_t | mobi_buffer_get32 (MOBIBuffer *buf) |
Reads 32-bit value from MOBIBuffer. More... | |
uint32_t | mobi_buffer_get_varlen (MOBIBuffer *buf, size_t *len) |
Reads variable length value from MOBIBuffer. More... | |
uint32_t | mobi_buffer_get_varlen_dec (MOBIBuffer *buf, size_t *len) |
Reads variable length value from MOBIBuffer going backwards. More... | |
void | mobi_buffer_getstring (char *str, MOBIBuffer *buf, const size_t len) |
Reads raw data from MOBIBuffer and pads it with zero character. More... | |
void | mobi_buffer_appendstring (char *str, MOBIBuffer *buf, const size_t len) |
Reads raw data from MOBIBuffer, appends it to a string and pads it with zero character. More... | |
void | mobi_buffer_getraw (void *data, MOBIBuffer *buf, const size_t len) |
Reads raw data from MOBIBuffer. More... | |
unsigned char * | mobi_buffer_getpointer (MOBIBuffer *buf, const size_t len) |
Get pointer to MOBIBuffer data at offset. More... | |
void | mobi_buffer_dup8 (uint8_t **val, MOBIBuffer *buf) |
Read 8-bit value from MOBIBuffer into allocated memory. More... | |
void | mobi_buffer_dup16 (uint16_t **val, MOBIBuffer *buf) |
Read 16-bit value from MOBIBuffer into allocated memory. More... | |
void | mobi_buffer_dup32 (uint32_t **val, MOBIBuffer *buf) |
Read 32-bit value from MOBIBuffer into allocated memory. More... | |
void | mobi_buffer_copy8 (MOBIBuffer *dest, MOBIBuffer *source) |
Copy 8-bit value from one MOBIBuffer into another. More... | |
void | mobi_buffer_copy (MOBIBuffer *dest, MOBIBuffer *source, const size_t len) |
Copy raw value from one MOBIBuffer into another. More... | |
void | mobi_buffer_move (MOBIBuffer *buf, const int offset, const size_t len) |
Copy raw value within one MOBIBuffer. More... | |
bool | mobi_buffer_match_magic (MOBIBuffer *buf, const char *magic) |
Check if buffer data header contains magic signature. More... | |
bool | mobi_buffer_match_magic_offset (MOBIBuffer *buf, const char *magic, const size_t offset) |
Check if buffer contains magic signature at given offset. More... | |
void | mobi_buffer_seek (MOBIBuffer *buf, const int diff) |
Move current buffer offset by diff bytes. More... | |
void | mobi_buffer_setpos (MOBIBuffer *buf, const size_t pos) |
Set buffer offset to pos position. More... | |
void | mobi_buffer_free (MOBIBuffer *buf) |
Free pointer to MOBIBuffer structure and pointer to data. More... | |
void | mobi_buffer_free_null (MOBIBuffer *buf) |
Free pointer to MOBIBuffer structure. More... | |
Functions to read/write raw big endian data.
Copyright (c) 2014 Bartek Fabiszewski http://www.fabiszewski.net
This file is part of libmobi. Licensed under LGPL, either version 3, or any later. See http://www.gnu.org/licenses/
void mobi_buffer_add16 | ( | MOBIBuffer * | buf, |
const uint16_t | data | ||
) |
Adds 16-bit value to MOBIBuffer.
[in,out] | buf | MOBIBuffer structure to be filled with data |
[in] | data | Integer to be put into the buffer |
void mobi_buffer_add32 | ( | MOBIBuffer * | buf, |
const uint32_t | data | ||
) |
Adds 32-bit value to MOBIBuffer.
[in,out] | buf | MOBIBuffer structure to be filled with data |
[in] | data | Integer to be put into the buffer |
void mobi_buffer_add8 | ( | MOBIBuffer * | buf, |
const uint8_t | data | ||
) |
Adds 8-bit value to MOBIBuffer.
[in,out] | buf | MOBIBuffer structure to be filled with data |
[in] | data | Integer to be put into the buffer |
void mobi_buffer_addraw | ( | MOBIBuffer * | buf, |
const unsigned char * | data, | ||
const size_t | len | ||
) |
Adds raw data to MOBIBuffer.
[in,out] | buf | MOBIBuffer structure to be filled with data |
[in] | data | Pointer to read data |
[in] | len | Size of the read data |
void mobi_buffer_addstring | ( | MOBIBuffer * | buf, |
const char * | str | ||
) |
Adds string to MOBIBuffer without null terminator.
[in,out] | buf | MOBIBuffer structure to be filled with data |
[in] | str | Pointer to string |
void mobi_buffer_addzeros | ( | MOBIBuffer * | buf, |
const size_t | count | ||
) |
Adds count of zeroes to MOBIBuffer.
[in,out] | buf | MOBIBuffer structure to be filled with data |
[in] | count | Number of zeroes to be put into the buffer |
void mobi_buffer_appendstring | ( | char * | str, |
MOBIBuffer * | buf, | ||
const size_t | len | ||
) |
Reads raw data from MOBIBuffer, appends it to a string and pads it with zero character.
[in,out] | str | A string to which data will be appended |
[in] | buf | MOBIBuffer structure containing data |
[in] | len | Length of the data to be read from buffer |
void mobi_buffer_copy | ( | MOBIBuffer * | dest, |
MOBIBuffer * | source, | ||
const size_t | len | ||
) |
Copy raw value from one MOBIBuffer into another.
[out] | dest | Destination buffer |
[in] | source | Source buffer |
[in] | len | Number of bytes to copy |
void mobi_buffer_copy8 | ( | MOBIBuffer * | dest, |
MOBIBuffer * | source | ||
) |
Copy 8-bit value from one MOBIBuffer into another.
[out] | dest | Destination buffer |
[in] | source | Source buffer |
void mobi_buffer_dup16 | ( | uint16_t ** | val, |
MOBIBuffer * | buf | ||
) |
Read 16-bit value from MOBIBuffer into allocated memory.
Read 16-bit value from buffer into allocated memory. Returns pointer to the value, which must be freed later. If the data is not accessible function will return null pointer.
[out] | val | Pointer to value or null pointer on failure |
[in] | buf | MOBIBuffer structure containing data |
void mobi_buffer_dup32 | ( | uint32_t ** | val, |
MOBIBuffer * | buf | ||
) |
Read 32-bit value from MOBIBuffer into allocated memory.
Read 32-bit value from buffer into allocated memory. Returns pointer to the value, which must be freed later. If the data is not accessible function will return null pointer.
[out] | val | Pointer to value |
[in] | buf | MOBIBuffer structure containing data |
void mobi_buffer_dup8 | ( | uint8_t ** | val, |
MOBIBuffer * | buf | ||
) |
Read 8-bit value from MOBIBuffer into allocated memory.
Read 8-bit value from buffer into memory allocated by the function. Returns pointer to the value, which must be freed later. If the data is not accessible function will return null pointer.
[out] | val | Pointer to value or null pointer on failure |
[in] | buf | MOBIBuffer structure containing data |
void mobi_buffer_free | ( | MOBIBuffer * | buf | ) |
Free pointer to MOBIBuffer structure and pointer to data.
Free data initialized with mobi_buffer_init();
[in] | buf | MOBIBuffer structure |
void mobi_buffer_free_null | ( | MOBIBuffer * | buf | ) |
Free pointer to MOBIBuffer structure.
Free data initialized with mobi_buffer_init_null(); Unlike mobi_buffer_free() it will not free pointer to buf->data
[in] | buf | MOBIBuffer structure |
uint16_t mobi_buffer_get16 | ( | MOBIBuffer * | buf | ) |
Reads 16-bit value from MOBIBuffer.
[in] | buf | MOBIBuffer structure containing data |
uint32_t mobi_buffer_get32 | ( | MOBIBuffer * | buf | ) |
Reads 32-bit value from MOBIBuffer.
[in] | buf | MOBIBuffer structure containing data |
uint8_t mobi_buffer_get8 | ( | MOBIBuffer * | buf | ) |
Reads 8-bit value from MOBIBuffer.
[in] | buf | MOBIBuffer structure containing data |
uint32_t mobi_buffer_get_varlen | ( | MOBIBuffer * | buf, |
size_t * | len | ||
) |
Reads variable length value from MOBIBuffer.
Reads maximum 4 bytes from the buffer. Stops when byte has bit 7 set.
[in] | buf | MOBIBuffer structure containing data |
[out] | len | Value will be increased by number of bytes read |
uint32_t mobi_buffer_get_varlen_dec | ( | MOBIBuffer * | buf, |
size_t * | len | ||
) |
Reads variable length value from MOBIBuffer going backwards.
Reads maximum 4 bytes from the buffer. Stops when byte has bit 7 set.
This function has a limitation. It will not read first byte in a buffer, as it would cause buffer offset to underflow. That means that it cannot read variable length values that are placed at the beginning of a buffer. This will result in an error.
[in] | buf | MOBIBuffer structure containing data |
[out] | len | Value will be increased by number of bytes read |
unsigned char* mobi_buffer_getpointer | ( | MOBIBuffer * | buf, |
const size_t | len | ||
) |
Get pointer to MOBIBuffer data at offset.
[in] | buf | MOBIBuffer structure containing data |
[in] | len | Check if requested length is available in buffer |
void mobi_buffer_getraw | ( | void * | data, |
MOBIBuffer * | buf, | ||
const size_t | len | ||
) |
Reads raw data from MOBIBuffer.
[out] | data | Destination to which data will be appended |
[in] | buf | MOBIBuffer structure containing data |
[in] | len | Length of the data to be read from buffer |
void mobi_buffer_getstring | ( | char * | str, |
MOBIBuffer * | buf, | ||
const size_t | len | ||
) |
Reads raw data from MOBIBuffer and pads it with zero character.
[out] | str | Destination for string read from buffer. Length must be (len + 1) |
[in] | buf | MOBIBuffer structure containing data |
[in] | len | Length of the data to be read from buffer |
MOBIBuffer* mobi_buffer_init | ( | const size_t | len | ) |
Initializer for MOBIBuffer structure.
It allocates memory for structure and for data. Memory should be freed with mobi_buffer_free().
[in] | len | Size of data to be allocated for the buffer |
MOBIBuffer* mobi_buffer_init_null | ( | unsigned char * | data, |
const size_t | len | ||
) |
Initializer for MOBIBuffer structure.
It allocates memory for structure but, unlike mobi_buffer_init(), it does not allocate memory for data. Instead it works on external data. Memory should be freed with mobi_buffer_free_null() (buf->data will not be deallocated).
[in,out] | data | Set data as buffer data |
[in] | len | Size of data held by the buffer |
bool mobi_buffer_match_magic | ( | MOBIBuffer * | buf, |
const char * | magic | ||
) |
Check if buffer data header contains magic signature.
[in] | buf | MOBIBuffer buffer containing data |
[in] | magic | Magic signature |
bool mobi_buffer_match_magic_offset | ( | MOBIBuffer * | buf, |
const char * | magic, | ||
const size_t | offset | ||
) |
Check if buffer contains magic signature at given offset.
[in] | buf | MOBIBuffer buffer containing data |
[in] | magic | Magic signature |
[in] | offset | Offset |
void mobi_buffer_move | ( | MOBIBuffer * | buf, |
const int | offset, | ||
const size_t | len | ||
) |
Copy raw value within one MOBIBuffer.
Memmove len bytes from offset (relative to current position) to current position in buffer and advance buffer position. Data may overlap.
[out] | buf | Buffer |
[in] | offset | Offset to read from |
[in] | len | Number of bytes to copy |
void mobi_buffer_resize | ( | MOBIBuffer * | buf, |
const size_t | newlen | ||
) |
Resize buffer.
Smaller size than offset will cause data truncation.
[in,out] | buf | MOBIBuffer structure to be filled with data |
[in] | newlen | New buffer size |
void mobi_buffer_seek | ( | MOBIBuffer * | buf, |
const int | diff | ||
) |
Move current buffer offset by diff bytes.
[in,out] | buf | MOBIBuffer buffer containing data |
[in] | diff | Number of bytes by which the offset is adjusted |
void mobi_buffer_setpos | ( | MOBIBuffer * | buf, |
const size_t | pos | ||
) |
Set buffer offset to pos position.
[in,out] | buf | MOBIBuffer buffer containing data |
[in] | pos | New position |