summaryrefslogtreecommitdiff
path: root/xdelta3
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2007-12-14 09:12:08 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2007-12-14 09:12:08 +0000
commit0334aeb5a83eb3f3aaf34e0e483785d046d54abc (patch)
tree52d983ded3b7dd93f4263d59dff57e7efe9e7363 /xdelta3
parent24ee8c8b37389770330cd7b90c202d0ee3732c1a (diff)
Fixes for Win32 and vsnprintf.
Diffstat (limited to 'xdelta3')
-rw-r--r--xdelta3/xdelta3-main.h59
1 files changed, 38 insertions, 21 deletions
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index 1e30e27..fc0d92b 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -1115,38 +1115,52 @@ main_set_secondary_flags (xd3_config *config)
1115 1115
1116#if VCDIFF_TOOLS 1116#if VCDIFF_TOOLS
1117 1117
1118/* The following macros let VCDIFF printing something printf-like with 1118#if defined(_WIN32) || defined(__DJGPP__)
1119 * main_file_write(), e.g.,:
1120 *
1121 * VC(UT "trying to be portable: %d\n", x)VE;
1122 */
1123#define SNPRINTF_BUFSIZE 1024
1124#define VC do { if (((ret = snprintf
1125#define UT (char*)xfile->snprintf_buf, SNPRINTF_BUFSIZE,
1126#define VE ) >= SNPRINTF_BUFSIZE \
1127 && (ret = main_print_overflow(ret)) != 0) \
1128 || (ret = main_file_write(xfile, xfile->snprintf_buf, \
1129 ret, "print")) != 0) \
1130 { return ret; } } while (0)
1131
1132#ifdef WIN32
1133/* According to the internet, Windows vsnprintf() differs from most 1119/* According to the internet, Windows vsnprintf() differs from most
1134 * Unix implementations regarding the terminating 0 when the boundary 1120 * Unix implementations regarding the terminating 0 when the boundary
1135 * condition is met. It doesn't matter here, we don't rely on the 1121 * condition is met. It doesn't matter here, we don't rely on the
1136 * trailing 0. */ 1122 * trailing 0. Besides, both Windows and DJGPP vsnprintf return -1
1123 * upon truncation, which isn't C99 compliant. To overcome this,
1124 * recent MinGW runtimes provided their own vsnprintf (notice the
1125 * absence of the '_' prefix) but they were initially buggy. So,
1126 * always use the native '_'-prefixed version with Win32. */
1137#include <stdarg.h> 1127#include <stdarg.h>
1128#ifdef _WIN32
1129#define vsnprintf_func _vsnprintf
1130#else
1131#define vsnprintf_func vsnprintf
1132#endif
1133
1138int 1134int
1139snprintf (char *str, int n, char *fmt, ...) 1135snprintf_func (char *str, int n, char *fmt, ...)
1140{ 1136{
1141 va_list a; 1137 va_list a;
1142 int ret; 1138 int ret;
1143 va_start (a, fmt); 1139 va_start (a, fmt);
1144 ret = vsnprintf (str, n, fmt, a); 1140 ret = vsnprintf_func (str, n, fmt, a);
1145 va_end (a); 1141 va_end (a);
1142 if (ret < 0)
1143 ret = n;
1146 return ret; 1144 return ret;
1147} 1145}
1146#else
1147#define snprintf_func snprintf
1148#endif 1148#endif
1149 1149
1150/* The following macros let VCDIFF printing something printf-like with
1151 * main_file_write(), e.g.,:
1152 *
1153 * VC(UT "trying to be portable: %d\n", x)VE;
1154 */
1155#define SNPRINTF_BUFSIZE 1024
1156#define VC do { if (((ret = snprintf
1157#define UT (char*)xfile->snprintf_buf, SNPRINTF_BUFSIZE,
1158#define VE ) >= SNPRINTF_BUFSIZE \
1159 && (ret = main_print_overflow(ret)) != 0) \
1160 || (ret = main_file_write(xfile, xfile->snprintf_buf, \
1161 ret, "print")) != 0) \
1162 { return ret; } } while (0)
1163
1150static int 1164static int
1151main_print_overflow (int x) 1165main_print_overflow (int x)
1152{ 1166{
@@ -3369,7 +3383,8 @@ main (int argc, char **argv)
3369 if (*my_optarg == 0) 3383 if (*my_optarg == 0)
3370 { 3384 {
3371 /* Condition 4-5 */ 3385 /* Condition 4-5 */
3372 int have_arg = my_optind < (argc - 1) && *argv[my_optind+1] != '-'; 3386 int have_arg = (my_optind < (argc - 1) &&
3387 *argv[my_optind+1] != '-');
3373 3388
3374 if (! have_arg) 3389 if (! have_arg)
3375 { 3390 {
@@ -3424,8 +3439,10 @@ main (int argc, char **argv)
3424#endif 3439#endif
3425#if VCDIFF_TOOLS 3440#if VCDIFF_TOOLS
3426 else if (strcmp (my_optstr, "printhdr") == 0) { cmd = CMD_PRINTHDR; } 3441 else if (strcmp (my_optstr, "printhdr") == 0) { cmd = CMD_PRINTHDR; }
3427 else if (strcmp (my_optstr, "printhdrs") == 0) { cmd = CMD_PRINTHDRS; } 3442 else if (strcmp (my_optstr, "printhdrs") == 0)
3428 else if (strcmp (my_optstr, "printdelta") == 0) { cmd = CMD_PRINTDELTA; } 3443 { cmd = CMD_PRINTHDRS; }
3444 else if (strcmp (my_optstr, "printdelta") == 0)
3445 { cmd = CMD_PRINTDELTA; }
3429 else if (strcmp (my_optstr, "recode") == 0) { cmd = CMD_RECODE; } 3446 else if (strcmp (my_optstr, "recode") == 0) { cmd = CMD_RECODE; }
3430#endif 3447#endif
3431 3448