libmobi
C library for handling MOBI format ebook documents
|
common tools functions More...
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <mobi.h>
#include "common.h"
Macros | |
#define | UNUSED(x) (void)(x) |
#define | min(a, b) ((a) < (b) ? (a) : (b)) |
#define | LIBMOBI_MSG_COUNT ARRAYSIZE(libmobi_messages) |
Functions | |
const char * | libmobi_msg (const MOBI_RET ret) |
Return message for given libmobi return code. More... | |
void | split_fullpath (const char *fullpath, char *dirname, char *basename, const size_t buf_len) |
Parse file name into file path and base name. Dirname or basename can be skipped by setting to null. More... | |
int | make_directory (const char *path) |
Make directory. More... | |
int | create_subdir (char *newdir, const size_t buf_len, const char *parent_dir, const char *subdir_name) |
Create subfolder in directory. More... | |
int | write_file (const unsigned char *buffer, const size_t len, const char *path) |
Open file descriptor and write buffer to it. More... | |
int | write_to_dir (const char *dir, const char *name, const unsigned char *buffer, const size_t len) |
Write content to file in directory. More... | |
bool | dir_exists (const char *path) |
Check whether given path exists and is a directory. More... | |
void | normalize_path (char *path) |
Make sure we use consistent separators on Windows builds. More... | |
void | print_summary (const MOBIData *m) |
Print summary meta information. More... | |
void | print_exth (const MOBIData *m) |
Print all loaded EXTH record tags. More... | |
int | set_decryption_pid (MOBIData *m, const char *pid) |
Set PID for decryption. More... | |
int | set_decryption_serial (MOBIData *m, const char *serial) |
Set device serial number for decryption. More... | |
int | set_decryption_key (MOBIData *m, const char *serial, const char *pid) |
Set key for decryption. Use user supplied pid or device serial number. More... | |
int | save_mobi (MOBIData *m, const char *fullpath, const char *suffix) |
Save mobi file. More... | |
Variables | |
const char | separator = '/' |
bool | outdir_opt = false |
char | outdir [FILENAME_MAX] |
const char * | libmobi_messages [] |
Messages for libmobi return codes For reference see enum MOBI_RET in mobi.h. More... | |
common tools functions
int create_subdir | ( | char * | newdir, |
const size_t | buf_len, | ||
const char * | parent_dir, | ||
const char * | subdir_name | ||
) |
Create subfolder in directory.
[in,out] | newdir | Path to created subfolder |
[in] | buf_len | Buffer size fo created subfolder |
[in] | parent_dir | Directory path |
[in] | subdir_name | Subfolder name |
bool dir_exists | ( | const char * | path | ) |
Check whether given path exists and is a directory.
[in] | path | Path to be tested |
const char* libmobi_msg | ( | const MOBI_RET | ret | ) |
Return message for given libmobi return code.
[in] | ret | Libmobi return code |
int make_directory | ( | const char * | path | ) |
void normalize_path | ( | char * | path | ) |
Make sure we use consistent separators on Windows builds.
[in,out] | path | Path to be fixed |
void print_exth | ( | const MOBIData * | m | ) |
Print all loaded EXTH record tags.
[in] | m | MOBIData structure |
void print_summary | ( | const MOBIData * | m | ) |
Print summary meta information.
[in] | m | MOBIData structure |
int save_mobi | ( | MOBIData * | m, |
const char * | fullpath, | ||
const char * | suffix | ||
) |
Save mobi file.
[in,out] | m | MOBIData struicture |
[in] | fullpath | Full file path |
[in] | suffix | Suffix appended to file name |
int set_decryption_key | ( | MOBIData * | m, |
const char * | serial, | ||
const char * | pid | ||
) |
Set key for decryption. Use user supplied pid or device serial number.
[in,out] | m | MOBIData structure |
[in] | serial | Serial number |
[in] | pid | Pid |
int set_decryption_pid | ( | MOBIData * | m, |
const char * | pid | ||
) |
int set_decryption_serial | ( | MOBIData * | m, |
const char * | serial | ||
) |
void split_fullpath | ( | const char * | fullpath, |
char * | dirname, | ||
char * | basename, | ||
const size_t | buf_len | ||
) |
Parse file name into file path and base name. Dirname or basename can be skipped by setting to null.
[in] | fullpath | Full file path |
[in,out] | dirname | Will be set to full dirname |
[in,out] | basename | Will be set to file basename |
[in] | buf_len | Size of each ouput buffer: dirname and basename |
int write_file | ( | const unsigned char * | buffer, |
const size_t | len, | ||
const char * | path | ||
) |
Open file descriptor and write buffer to it.
[in] | buffer | Buffer |
[in] | len | Buffer length |
[in] | path | File path |
int write_to_dir | ( | const char * | dir, |
const char * | name, | ||
const unsigned char * | buffer, | ||
const size_t | len | ||
) |
Write content to file in directory.
[in] | dir | Directory path |
[in] | name | File name |
[in] | buffer | Buffer |
[in] | len | Buffer length |
const char* libmobi_messages[] |
Messages for libmobi return codes For reference see enum MOBI_RET in mobi.h.