1 /* xdelta3 - delta compression tools and library
2 * Copyright (C) 2011, 2012 Joshua P. MacDonald
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #ifndef XDELTA3_INTERNAL_H__
19 #define XDELTA3_INTERNAL_H__
23 typedef struct _main_file main_file;
24 typedef struct _main_extcomp main_extcomp;
26 void main_buffree (void *ptr);
27 void* main_bufalloc (size_t size);
28 void main_file_init (main_file *xfile);
29 int main_file_close (main_file *xfile);
30 void main_file_cleanup (main_file *xfile);
31 int main_file_isopen (main_file *xfile);
32 int main_file_open (main_file *xfile, const char* name, int mode);
33 int main_file_exists (main_file *xfile);
34 int xd3_whole_append_window (xd3_stream *stream);
35 int xd3_main_cmdline (int argc, char **argv);
36 int main_file_read (main_file *ifile,
41 int main_file_write (main_file *ofile, uint8_t *buf,
42 usize_t size, const char *msg);
43 int test_compare_files (const char* f0, const char* f1);
44 usize_t xd3_bytes_on_srcblk (xd3_source *src, xoff_t blkno);
45 xoff_t xd3_source_eof(const xd3_source *src);
46 uint32_t xd3_large_cksum_update (uint32_t cksum,
49 int xd3_encode_init_full (xd3_stream *stream);
50 size_t xd3_pow2_roundup (size_t x);
51 int xd3_process_stream (int is_encode,
53 int (*func) (xd3_stream *),
59 usize_t output_size_max);
61 #if PYTHON_MODULE || SWIG_MODULE || NOT_MAIN
62 int xd3_main_cmdline (int argc, char **argv);
65 /* main_file->mode values */
82 int mode; /* XO_READ and XO_WRITE */
83 const char *filename; /* File name or /dev/stdin,
84 * /dev/stdout, /dev/stderr. */
85 char *filename_copy; /* File name or /dev/stdin,
86 * /dev/stdout, /dev/stderr. */
87 const char *realname; /* File name or /dev/stdin,
88 * /dev/stdout, /dev/stderr. */
89 const main_extcomp *compressor; /* External compression struct. */
90 int flags; /* RD_FIRST, RD_NONEXTERNAL, ... */
91 xoff_t nread; /* for input position */
92 xoff_t nwrite; /* for output position */
93 uint8_t *snprintf_buf; /* internal snprintf() use */
94 int size_known; /* Set by main_set_souze */
95 xoff_t source_position; /* for avoiding seek in getblk_func */
96 int seek_failed; /* after seek fails once, try FIFO */
99 /* According to the internet, Windows vsnprintf() differs from most
100 * Unix implementations regarding the terminating 0 when the boundary
101 * condition is met. It doesn't matter here, we don't rely on the
102 * trailing 0. Besides, both Windows and DJGPP vsnprintf return -1
103 * upon truncation, which isn't C99 compliant. To overcome this,
104 * recent MinGW runtimes provided their own vsnprintf (notice the
105 * absence of the '_' prefix) but they were initially buggy. So,
106 * always use the native '_'-prefixed version with Win32. */
108 #define vsnprintf_func(str,size,fmt,args) \
109 _vsnprintf_s(str,size,size-1,fmt,args)
110 #define snprintf_func(str,size,fmt,...) \
111 _snprintf_s(str,size,size-1,fmt,__VA_ARGS__)
113 #define vsnprintf_func vsnprintf
114 #define snprintf_func snprintf
116 #define short_sprintf(sb,fmt,...) \
117 snprintf_func((sb).buf,sizeof((sb).buf),fmt,__VA_ARGS__)
119 /* Type used for short snprintf calls. */
124 /* Prior to SVN 303 this function was only defined in DJGPP and WIN32
125 * environments and other platforms would use the builtin snprintf()
126 * with an arrangement of macros below. In OS X 10.6, Apply made
127 * snprintf() a macro, which defeated those macros (since snprintf
128 * would be evaluated before its argument macros were expanded,
129 * therefore always define xsnprintf_func. */
130 #undef PRINTF_ATTRIBUTE
132 /* Let's just assume no one uses gcc 2.x! */
133 #define PRINTF_ATTRIBUTE(x,y) __attribute__ ((__format__ (__printf__, x, y)))
135 #define PRINTF_ATTRIBUTE(x,y)
138 /* Underlying xprintf() */
139 int xsnprintf_func (char *str, int n, const char *fmt, ...)
140 PRINTF_ATTRIBUTE(3,4);
142 /* XPR(NT "", ...) (used by main) prefixes an "xdelta3: " to the output. */
143 void xprintf(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
145 #define NT "xdelta3: "
149 #define UINT32_MAX 4294967295U
153 #define UINT64_MAX 18446744073709551615ULL
156 #endif // XDELTA3_INTERNAL_H__