libmobi
C library for handling MOBI format ebook documents
Macros | Functions | Variables
common.h File Reference
#include <stdio.h>
#include <sys/stat.h>
#include "win32/getopt.h"

Go to the source code of this file.

Macros

#define ERROR   1
 
#define SUCCESS   0
 
#define STR_HELPER(x)   #x
 
#define STR(x)   STR_HELPER(x)
 
#define ARRAYSIZE(arr)   (sizeof(arr) / sizeof(arr[0]))
 
#define COMPILER   "unknown"
 
#define FULLNAME_MAX   1024
 

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_key (MOBIData *m, const char *serial, const char *pid)
 Set key for decryption. Use user supplied pid or device serial number. 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 save_mobi (MOBIData *m, const char *fullpath, const char *suffix)
 Save mobi file. More...
 

Variables

const char separator
 
bool outdir_opt
 
char outdir [FILENAME_MAX]
 

Detailed Description

Copyright (c) 2020 Bartek Fabiszewski http://www.fabiszewski.net

Licensed under LGPL, either version 3, or any later. See http://www.gnu.org/licenses/

Function Documentation

◆ create_subdir()

int create_subdir ( char *  newdir,
const size_t  buf_len,
const char *  parent_dir,
const char *  subdir_name 
)

Create subfolder in directory.

Parameters
[in,out]newdirPath to created subfolder
[in]buf_lenBuffer size fo created subfolder
[in]parent_dirDirectory path
[in]subdir_nameSubfolder name
Returns
SUCCESS or ERROR

◆ dir_exists()

bool dir_exists ( const char *  path)

Check whether given path exists and is a directory.

Parameters
[in]pathPath to be tested
Returns
True if directory exists, false otherwise

◆ libmobi_msg()

const char* libmobi_msg ( const MOBI_RET  ret)

Return message for given libmobi return code.

Parameters
[in]retLibmobi return code
Returns
Message string

◆ make_directory()

int make_directory ( const char *  path)

Make directory.

Parameters
[in]pathPath
Returns
SUCCESS or ERROR

◆ normalize_path()

void normalize_path ( char *  path)

Make sure we use consistent separators on Windows builds.

Parameters
[in,out]pathPath to be fixed

◆ print_exth()

void print_exth ( const MOBIData m)

Print all loaded EXTH record tags.

Parameters
[in]mMOBIData structure

◆ print_summary()

void print_summary ( const MOBIData m)

Print summary meta information.

Parameters
[in]mMOBIData structure

◆ save_mobi()

int save_mobi ( MOBIData m,
const char *  fullpath,
const char *  suffix 
)

Save mobi file.

Parameters
[in,out]mMOBIData struicture
[in]fullpathFull file path
[in]suffixSuffix appended to file name
Returns
SUCCESS or ERROR

◆ set_decryption_key()

int set_decryption_key ( MOBIData m,
const char *  serial,
const char *  pid 
)

Set key for decryption. Use user supplied pid or device serial number.

Parameters
[in,out]mMOBIData structure
[in]serialSerial number
[in]pidPid
Returns
SUCCESS or error code

◆ set_decryption_pid()

int set_decryption_pid ( MOBIData m,
const char *  pid 
)

Set PID for decryption.

Parameters
[in,out]mMOBIData structure
[in]pidSerial number
Returns
SUCCESS or error code

◆ set_decryption_serial()

int set_decryption_serial ( MOBIData m,
const char *  serial 
)

Set device serial number for decryption.

Parameters
[in,out]mMOBIData structure
[in]serialSerial number
Returns
SUCCESS or error code

◆ split_fullpath()

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.

Parameters
[in]fullpathFull file path
[in,out]dirnameWill be set to full dirname
[in,out]basenameWill be set to file basename
[in]buf_lenSize of each ouput buffer: dirname and basename

◆ write_file()

int write_file ( const unsigned char *  buffer,
const size_t  len,
const char *  path 
)

Open file descriptor and write buffer to it.

Parameters
[in]bufferBuffer
[in]lenBuffer length
[in]pathFile path
Returns
SUCCESS or ERROR

◆ write_to_dir()

int write_to_dir ( const char *  dir,
const char *  name,
const unsigned char *  buffer,
const size_t  len 
)

Write content to file in directory.

Parameters
[in]dirDirectory path
[in]nameFile name
[in]bufferBuffer
[in]lenBuffer length
Returns
SUCCESS or ERROR