libmobi
C library for handling MOBI format ebook documents
common.h
Go to the documentation of this file.
1 
10 #ifndef common_h
11 #define common_h
12 
13 #include <stdio.h>
14 #include <sys/stat.h>
15 
16 #ifdef HAVE_CONFIG_H
17 # include "../config.h"
18 #endif
19 
20 #ifdef HAVE_GETOPT
21 # include <unistd.h>
22 #else
23 # include "win32/getopt.h"
24 #endif
25 
26 /* return codes */
27 #define ERROR 1
28 #define SUCCESS 0
29 
30 #define STR_HELPER(x) #x
31 #define STR(x) STR_HELPER(x)
32 
33 #define ARRAYSIZE(arr) (sizeof(arr) / sizeof(arr[0]))
34 
35 #if defined(__clang__)
36 # define COMPILER "clang " __VERSION__
37 #elif defined(__SUNPRO_C)
38 # define COMPILER "suncc " STR(__SUNPRO_C)
39 #elif defined(__GNUC__)
40 # if (defined(__MINGW32__) || defined(__MINGW64__))
41 # define COMPILER "gcc (MinGW) " __VERSION__
42 # else
43 # define COMPILER "gcc " __VERSION__
44 # endif
45 #elif defined(_MSC_VER)
46 # define COMPILER "MSVC++ " STR(_MSC_VER)
47 #else
48 # define COMPILER "unknown"
49 #endif
50 
51 #if !defined S_ISDIR && defined S_IFDIR
52 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
53 #endif
54 #ifndef S_ISDIR
55 # error "At least one of S_ISDIR or S_IFDIR macros is required"
56 #endif
57 
58 #define FULLNAME_MAX 1024
59 
60 extern const char separator;
61 extern bool outdir_opt;
62 extern char outdir[FILENAME_MAX];
63 
64 const char * libmobi_msg(const MOBI_RET ret);
65 void split_fullpath(const char *fullpath, char *dirname, char *basename, const size_t buf_len);
66 int make_directory(const char *path);
67 int create_subdir(char *newdir, const size_t buf_len, const char *parent_dir, const char *subdir_name);
68 int write_file(const unsigned char *buffer, const size_t len, const char *path);
69 int write_to_dir(const char *dir, const char *name, const unsigned char *buffer, const size_t len);
70 bool dir_exists(const char *path);
71 void normalize_path(char *path);
72 void print_summary(const MOBIData *m);
73 void print_exth(const MOBIData *m);
74 int set_decryption_key(MOBIData *m, const char *serial, const char *pid);
75 int set_decryption_pid(MOBIData *m, const char *pid);
76 int set_decryption_serial(MOBIData *m, const char *serial);
77 int save_mobi(MOBIData *m, const char *fullpath, const char *suffix);
78 #endif /* common_h */
void print_exth(const MOBIData *m)
Print all loaded EXTH record tags.
Definition: common.c:433
int write_to_dir(const char *dir, const char *name, const unsigned char *buffer, const size_t len)
Write content to file in directory.
Definition: common.c:188
int set_decryption_key(MOBIData *m, const char *serial, const char *pid)
Set key for decryption. Use user supplied pid or device serial number.
Definition: common.c:554
const char * libmobi_msg(const MOBI_RET ret)
Return message for given libmobi return code.
Definition: common.c:68
bool dir_exists(const char *path)
Check whether given path exists and is a directory.
Definition: common.c:207
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.
Definition: common.c:84
void print_summary(const MOBIData *m)
Print summary meta information.
Definition: common.c:244
int create_subdir(char *newdir, const size_t buf_len, const char *parent_dir, const char *subdir_name)
Create subfolder in directory.
Definition: common.c:141
int write_file(const unsigned char *buffer, const size_t len, const char *path)
Open file descriptor and write buffer to it.
Definition: common.c:161
int set_decryption_serial(MOBIData *m, const char *serial)
Set device serial number for decryption.
Definition: common.c:536
int save_mobi(MOBIData *m, const char *fullpath, const char *suffix)
Save mobi file.
Definition: common.c:585
int make_directory(const char *path)
Make directory.
Definition: common.c:123
int set_decryption_pid(MOBIData *m, const char *pid)
Set PID for decryption.
Definition: common.c:519
void normalize_path(char *path)
Make sure we use consistent separators on Windows builds.
Definition: common.c:225
MOBI_RET
Error codes returned by functions.
Definition: mobi.h:59
Main structure holding all metadata and unparsed records data.
Definition: mobi.h:381