summaryrefslogtreecommitdiff
path: root/xdelta3
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2007-02-07 06:07:04 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2007-02-07 06:07:04 +0000
commitbae4a7e25d8384b841f4358bd8f7eba302f602c7 (patch)
tree66b542bd01dd864e106538b6c2d6dda5c657fe2f /xdelta3
parentf15380d045ade6a25a78df37d8562a27ed13e23f (diff)
Fixes print commands on Windows, the needed GetStartupInfo() and stdin/stdout handles set after the change in 112 (missing its comment) which converts the print commands to use snprintf() and the default I/O routines. Addresses issue 14.
Diffstat (limited to 'xdelta3')
-rwxr-xr-xxdelta3/xdelta3-main.h56
1 files changed, 31 insertions, 25 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index 6225cb3..e222eb4 100755
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -31,10 +31,13 @@
31 */ 31 */
32 32
33/* TODO list: 33/* TODO list:
34 * 1. do exact gzip-like filename, stdout handling. make a .xz extension, refuse 34 * 1. do exact gzip-like filename, stdout handling. make a .vcdiff extension, refuse
35 * to encode to stdout without -cf, etc. 35 * to encode to stdout without -cf, etc.
36 * 2. Allow the user to add a comment string to the app header without disturbing the default 36 * 2. Allow the user to add a comment string to the app header without disturbing the default
37 * behavior. 37 * behavior.
38 * 3. "Source file must be seekable" is not actually true for encoding, given current
39 * behavior. Allow non-seekable sources? It would in theory let you use a fifo for
40 * the source.
38 */ 41 */
39 42
40/* On error handling and printing: 43/* On error handling and printing:
@@ -116,6 +119,9 @@ const char* xd3_mainerror(int err_num);
116# define S_ISREG(m) 1 119# define S_ISREG(m) 1
117//# endif 120//# endif
118#endif /* !S_ISREG */ 121#endif /* !S_ISREG */
122
123// For standard input/output handles
124static STARTUPINFO winStartupInfo;
119#endif 125#endif
120 126
121/****************************************************************************************** 127/******************************************************************************************
@@ -252,7 +258,7 @@ static int option_use_checksum = 1;
252static int option_use_altcodetable = 0; 258static int option_use_altcodetable = 0;
253static char* option_smatch_config = NULL; 259static char* option_smatch_config = NULL;
254static int option_no_compress = 0; 260static int option_no_compress = 0;
255static int option_no_output = 0; /* go through the motions, but do not open or write output */ 261static int option_no_output = 0; /* do not open or write output */
256static const char *option_source_filename = NULL; 262static const char *option_source_filename = NULL;
257 263
258static usize_t option_iopt_size = XD3_DEFAULT_IOPT_SIZE; 264static usize_t option_iopt_size = XD3_DEFAULT_IOPT_SIZE;
@@ -638,20 +644,17 @@ main_atou (const char* arg, usize_t *xo, usize_t low, usize_t high, char which)
638#if XD3_STDIO 644#if XD3_STDIO
639#define XFNO(f) fileno(f->file) 645#define XFNO(f) fileno(f->file)
640#define XSTDOUT_XF(f) { (f)->file = stdout; (f)->filename = "/dev/stdout"; } 646#define XSTDOUT_XF(f) { (f)->file = stdout; (f)->filename = "/dev/stdout"; }
641#define XSTDERR_XF(f) { (f)->file = stderr; (f)->filename = "/dev/stderr"; }
642#define XSTDIN_XF(f) { (f)->file = stdin; (f)->filename = "/dev/stdin"; } 647#define XSTDIN_XF(f) { (f)->file = stdin; (f)->filename = "/dev/stdin"; }
643 648
644#elif XD3_POSIX 649#elif XD3_POSIX
645#define XFNO(f) f->file 650#define XFNO(f) f->file
646#define XSTDOUT_XF(f) { (f)->file = STDOUT_FILENO; (f)->filename = "/dev/stdout"; } 651#define XSTDOUT_XF(f) { (f)->file = STDOUT_FILENO; (f)->filename = "/dev/stdout"; }
647#define XSTDERR_XF(f) { (f)->file = STDERR_FILENO; (f)->filename = "/dev/stderr"; }
648#define XSTDIN_XF(f) { (f)->file = STDIN_FILENO; (f)->filename = "/dev/stdin"; } 652#define XSTDIN_XF(f) { (f)->file = STDIN_FILENO; (f)->filename = "/dev/stdin"; }
649 653
650#elif XD3_WIN32 654#elif XD3_WIN32
651#define XFNO(f) -1 655#define XFNO(f) -1
652#define XSTDOUT_XF(f) { (f)->file = INVALID_HANDLE_VALUE; (f)->filename = "/dev/stdout"; } 656#define XSTDOUT_XF(f) { (f)->file = winStartupInfo.hStdOutput; (f)->filename = "(stdout)"; }
653#define XSTDERR_XF(f) { (f)->file = INVALID_HANDLE_VALUE; (f)->filename = "/dev/stderr"; } 657#define XSTDIN_XF(f) { (f)->file = winStartupInfo.hStdInput; (f)->filename = "(stdin)"; }
654#define XSTDIN_XF(f) { (f)->file = INVALID_HANDLE_VALUE; (f)->filename = "/dev/stdin"; }
655#endif 658#endif
656 659
657static void 660static void
@@ -967,6 +970,23 @@ main_file_seek (main_file *xfile, xoff_t pos)
967 ******************************************************************************************/ 970 ******************************************************************************************/
968 971
969#if VCDIFF_TOOLS 972#if VCDIFF_TOOLS
973#ifdef WIN32
974/* According to the internet, Windows vsnprintf() differs from most Unix
975 * implementations regarding the terminating 0 when the boundary condition
976 * is met. It doesn't matter here, we don't rely on the trailing 0. */
977#include <stdarg.h>
978int
979snprintf (char *str, int n, char *fmt, ...)
980{
981 va_list a;
982 int ret;
983 va_start (a, fmt);
984 ret = vsnprintf (str, n, fmt, a);
985 va_end (a);
986 return ret;
987}
988#endif
989
970#define SNPRINTF_BUFSIZE XD3_ALLOCSIZE 990#define SNPRINTF_BUFSIZE XD3_ALLOCSIZE
971#define VC do { if (((ret = snprintf 991#define VC do { if (((ret = snprintf
972#define UT xfile->snprintf_buf, SNPRINTF_BUFSIZE, 992#define UT xfile->snprintf_buf, SNPRINTF_BUFSIZE,
@@ -2791,6 +2811,10 @@ main (int argc, char **argv)
2791 char **orig_argv = argv; 2811 char **orig_argv = argv;
2792 int ret; 2812 int ret;
2793 2813
2814#ifdef _WIN32
2815 GetStartupInfo(&winStartupInfo);
2816#endif
2817
2794 main_file_init (& ifile); 2818 main_file_init (& ifile);
2795 main_file_init (& ofile); 2819 main_file_init (& ofile);
2796 main_file_init (& sfile); 2820 main_file_init (& sfile);
@@ -3053,24 +3077,6 @@ main (int argc, char **argv)
3053 goto cleanup; 3077 goto cleanup;
3054 } 3078 }
3055 3079
3056 if (option_verbose > 1)
3057 {
3058 int l = 1;
3059 int i;
3060 char buf[1024];
3061 for (i = 0; i < orig_argc; i += 1)
3062 {
3063 l += strlen (orig_argv[i]) + 1;
3064 }
3065 buf[0] = 0;
3066 for (i = 0; i < orig_argc; i += 1)
3067 {
3068 strcat (buf, orig_argv[i]);
3069 strcat (buf, " ");
3070 }
3071 XPR(NT "command line: %s\n", buf);
3072 }
3073
3074 ifile.flags = RD_FIRST; 3080 ifile.flags = RD_FIRST;
3075 sfile.flags = RD_FIRST; 3081 sfile.flags = RD_FIRST;
3076 sfile.filename = option_source_filename; 3082 sfile.filename = option_source_filename;