summaryrefslogtreecommitdiff
path: root/xdelta3/xdelta3-main.h
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/xdelta3-main.h')
-rw-r--r--xdelta3/xdelta3-main.h48
1 files changed, 31 insertions, 17 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index 71c8541..6fcd423 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -250,7 +250,7 @@ static const char *option_source_filename = NULL;
250static int option_level = XD3_DEFAULT_LEVEL; 250static int option_level = XD3_DEFAULT_LEVEL;
251static usize_t option_iopt_size = XD3_DEFAULT_IOPT_SIZE; 251static usize_t option_iopt_size = XD3_DEFAULT_IOPT_SIZE;
252static usize_t option_winsize = XD3_DEFAULT_WINSIZE; 252static usize_t option_winsize = XD3_DEFAULT_WINSIZE;
253static usize_t option_srcwinsz = XD3_DEFAULT_SRCWINSZ; 253static size_t option_srcwinsz = XD3_DEFAULT_SRCWINSZ;
254static usize_t option_sprevsz = XD3_DEFAULT_SPREVSZ; 254static usize_t option_sprevsz = XD3_DEFAULT_SPREVSZ;
255 255
256/* These variables are supressed to avoid their use w/o support. main() warns 256/* These variables are supressed to avoid their use w/o support. main() warns
@@ -309,7 +309,7 @@ static int main_getblk_func (xd3_stream *stream,
309 xd3_source *source, 309 xd3_source *source,
310 xoff_t blkno); 310 xoff_t blkno);
311static void main_free (void *ptr); 311static void main_free (void *ptr);
312static void* main_malloc (usize_t size); 312static void* main_malloc (size_t size);
313 313
314static int main_file_stat (main_file *xfile, xoff_t *size); 314static int main_file_stat (main_file *xfile, xoff_t *size);
315static int main_file_seek (main_file *xfile, xoff_t pos); 315static int main_file_seek (main_file *xfile, xoff_t pos);
@@ -443,15 +443,14 @@ reset_defaults(void)
443} 443}
444 444
445static void* 445static void*
446main_malloc1 (usize_t size) 446main_malloc1 (size_t size)
447{ 447{
448 void* r = malloc (size); 448 void* r = malloc (size);
449 if (r == NULL) { XPR(NT "malloc: %s\n", xd3_mainerror (ENOMEM)); } 449 if (r == NULL) { XPR(NT "malloc: %s\n", xd3_mainerror (ENOMEM)); }
450 else if (option_verbose > 4) { XPR(NT "malloc: %u: %p\n", size, r); }
451 return r; 450 return r;
452} 451}
453 452
454void* main_bufalloc (usize_t size) { 453void* main_bufalloc (size_t size) {
455#if XD3_WIN32 454#if XD3_WIN32
456 return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); 455 return VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
457#else 456#else
@@ -460,7 +459,7 @@ void* main_bufalloc (usize_t size) {
460} 459}
461 460
462static void* 461static void*
463main_malloc (usize_t size) 462main_malloc (size_t size)
464{ 463{
465 void *r = main_malloc1 (size); 464 void *r = main_malloc1 (size);
466 if (r) { IF_DEBUG (main_mallocs += 1); } 465 if (r) { IF_DEBUG (main_mallocs += 1); }
@@ -469,7 +468,7 @@ main_malloc (usize_t size)
469 468
470static void* 469static void*
471main_alloc (void *opaque, 470main_alloc (void *opaque,
472 usize_t items, 471 size_t items,
473 usize_t size) 472 usize_t size)
474{ 473{
475 return main_malloc1 (items * size); 474 return main_malloc1 (items * size);
@@ -478,7 +477,6 @@ main_alloc (void *opaque,
478static void 477static void
479main_free1 (void *opaque, void *ptr) 478main_free1 (void *opaque, void *ptr)
480{ 479{
481 if (option_verbose > 4) { XPR(NT "free: %p\n", ptr); }
482 free (ptr); 480 free (ptr);
483} 481}
484 482
@@ -703,8 +701,8 @@ main_strtoxoff (const char* s, xoff_t *xo, char which)
703} 701}
704 702
705static int 703static int
706main_atou (const char* arg, usize_t *xo, usize_t low, 704main_atoux (const char* arg, xoff_t *xo, xoff_t low,
707 usize_t high, char which) 705 xoff_t high, char which)
708{ 706{
709 xoff_t x; 707 xoff_t x;
710 int ret; 708 int ret;
@@ -713,7 +711,7 @@ main_atou (const char* arg, usize_t *xo, usize_t low,
713 711
714 if (x < low) 712 if (x < low)
715 { 713 {
716 XPR(NT "-%c: minimum value: %u\n", which, low); 714 XPR(NT "-%c: minimum value: %"Q"u\n", which, low);
717 return EXIT_FAILURE; 715 return EXIT_FAILURE;
718 } 716 }
719 if (high == 0) 717 if (high == 0)
@@ -722,10 +720,24 @@ main_atou (const char* arg, usize_t *xo, usize_t low,
722 } 720 }
723 if (x > high) 721 if (x > high)
724 { 722 {
725 XPR(NT "-%c: maximum value: %u\n", which, high); 723 XPR(NT "-%c: maximum value: %"Q"u\n", which, high);
726 return EXIT_FAILURE; 724 return EXIT_FAILURE;
727 } 725 }
728 (*xo) = (usize_t)x; 726 (*xo) = x;
727 return 0;
728}
729
730static int
731main_atou (const char* arg, usize_t *uo, usize_t low,
732 usize_t high, char which)
733{
734 int ret;
735 xoff_t xo;
736 if ((ret = main_atoux (arg, &xo, low, high, which)))
737 {
738 return ret;
739 }
740 *uo = (usize_t)xo;
729 return 0; 741 return 0;
730} 742}
731 743
@@ -3102,7 +3114,6 @@ main_input (xd3_cmd cmd,
3102 } 3114 }
3103 3115
3104 config.winsize = winsize; 3116 config.winsize = winsize;
3105 config.srcwin_maxsz = option_srcwinsz;
3106 config.getblk = main_getblk_func; 3117 config.getblk = main_getblk_func;
3107 config.flags = stream_flags; 3118 config.flags = stream_flags;
3108 3119
@@ -3760,13 +3771,16 @@ int main (int argc, char **argv)
3760 break; 3771 break;
3761 case 'A': if (my_optarg == NULL) { option_use_appheader = 0; } 3772 case 'A': if (my_optarg == NULL) { option_use_appheader = 0; }
3762 else { option_appheader = (uint8_t*) my_optarg; } break; 3773 else { option_appheader = (uint8_t*) my_optarg; } break;
3763 case 'B': 3774 case 'B': {
3764 if ((ret = main_atou (my_optarg, & option_srcwinsz, XD3_MINSRCWINSZ, 3775 xoff_t bsize;
3765 0, 'B'))) 3776 if ((ret = main_atoux (my_optarg, & bsize,
3777 XD3_MINSRCWINSZ, 0, 'B')))
3766 { 3778 {
3767 goto exit; 3779 goto exit;
3768 } 3780 }
3781 option_srcwinsz = bsize;
3769 break; 3782 break;
3783 }
3770 case 'I': 3784 case 'I':
3771 if ((ret = main_atou (my_optarg, & option_iopt_size, 0, 3785 if ((ret = main_atou (my_optarg, & option_iopt_size, 0,
3772 0, 'I'))) 3786 0, 'I')))