-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon.h
65 lines (52 loc) · 1.94 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef COMMON_H
#define COMMON_H
#include <stdint.h>
#include <stdio.h>
#if defined(WIN32)
#define SIZE_T "%I64d"
#define MKDIR(filename, mode) mkdir(filename)
#else
#define SIZE_T "%ld"
#define MKDIR(filename, mode) mkdir(filename, mode)
#endif
#define UNUSED __attribute__((unused))
#define VERSION_MAX_SIZE 12 // "255.255.255"
#define MIN(A, B) A < B ? A : B
#define TRACE(format, ...) \
do { \
if (trace != NULL) { \
trace(stderr, "%s:%d:\t" format "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
} \
} while (0)
extern int (*trace)(FILE* stream, const char* format, ...);
int trace_silent(FILE* stream, const char* format, ...);
/**
* @brief Initialize trace function
*
* @param[in] verbose Verbosity level (0 for no output in TRACE call, other values: maximum verbosity)
*/
void trace_init(int verbose);
/**
* @brief Read file contents from path into memory buffer
*
* @param[in] path File path to read.
* @param file_data The file data.
* @param file_size The file size.
*
* @return 0 on success, -1 otherwise.
*/
int read_file(const char* path, uint8_t** file_data, size_t* file_size);
/**
* @brief Save memory buffer content to file
*
* @param[in] source_filename File path to save.
* @param[in] data The file data.
* @param[in] data_size The file size.
* @param[in] in_place If true, override original target image. Otherwise, save new image under
* {target_image}.out name.
*
* @return 0 on success, -1 otherwise.
*/
int save_image(const char* source_filename, uint8_t* data, size_t data_size, int in_place);
const char* get_basename(const char* path);
#endif // COMMON_H