diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2014-03-25 20:28:20 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2014-03-25 20:28:32 +0100 |
commit | ecfb80367e891394f5bc0eaf52523b7fc71ab878 (patch) | |
tree | 3d3be1a862ddb5f6369bfa6aa813673339c555dd | |
parent | 680156458242c87bfa9f3013cc5d23308409e8de (diff) | |
download | mupdf-ecfb80367e891394f5bc0eaf52523b7fc71ab878.tar.xz |
Add va_copy/va_copy_end macros to support both C89 and C99.
-rw-r--r-- | include/mupdf/fitz/system.h | 12 | ||||
-rw-r--r-- | source/fitz/buffer.c | 16 | ||||
-rw-r--r-- | source/fitz/printf.c | 12 |
3 files changed, 15 insertions, 25 deletions
diff --git a/include/mupdf/fitz/system.h b/include/mupdf/fitz/system.h index 41f45245..bf339eb4 100644 --- a/include/mupdf/fitz/system.h +++ b/include/mupdf/fitz/system.h @@ -63,6 +63,15 @@ #ifdef _MSC_VER /* Microsoft Visual C */ +/* MSVC up to VS2012 */ +#if _MSC_VER < 1800 +#define va_copy(a, oa) do { a=oa; } while (0) +#define va_copy_end(a) do {} while(0) +#define strtof(a,b) ((float)strtod((a),(b))) +#else +#define va_copy_end(a) va_end(a) +#endif + typedef signed char int8_t; typedef short int int16_t; typedef int int32_t; @@ -110,9 +119,10 @@ void fz_free_argv(int argc, char **argv); #ifndef O_BINARY #define O_BINARY 0 - #endif +#define va_copy_end(a) va_end(a) + #endif #ifdef __ANDROID__ diff --git a/source/fitz/buffer.c b/source/fitz/buffer.c index e9295a26..4a87b4ca 100644 --- a/source/fitz/buffer.c +++ b/source/fitz/buffer.c @@ -237,15 +237,9 @@ fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list o va_list args; slack = buffer->cap - buffer->len; -#ifdef _MSC_VER /* Microsoft Visual C */ - args = old_args; -#else va_copy(args, old_args); -#endif len = fz_vsnprintf((char *)buffer->data + buffer->len, slack, fmt, args); -#ifndef _MSC_VER - va_end(args); -#endif + va_copy_end(args); /* len = number of chars written, not including the terminating * NULL, so len+1 > slack means "truncated". */ @@ -255,15 +249,9 @@ fz_buffer_vprintf(fz_context *ctx, fz_buffer *buffer, const char *fmt, va_list o fz_ensure_buffer(ctx, buffer, buffer->len + len); slack = buffer->cap - buffer->len; -#ifdef _MSC_VER /* Microsoft Visual C */ - args = old_args; -#else va_copy(args, old_args); -#endif len = fz_vsnprintf((char *)buffer->data + buffer->len, slack, fmt, args); -#ifndef _MSC_VER - va_end(args); -#endif + va_copy_end(args); } buffer->len += len; diff --git a/source/fitz/printf.c b/source/fitz/printf.c index a1af9436..bc5ee898 100644 --- a/source/fitz/printf.c +++ b/source/fitz/printf.c @@ -1,13 +1,5 @@ #include "mupdf/fitz.h" -/* Microsoft Visual C up to VS2012 */ -#if _MSC_VER < 1800 -#define va_copy(a, oa) do { a=oa; } while (0) -#undef va_end -#define va_end(a) -#define strtof(a, b) ((float)strtod((a), (b))) -#endif - struct fmtbuf { char *p; @@ -280,7 +272,7 @@ fz_vfprintf(fz_context *ctx, FILE *file, const char *fmt, va_list old_args) /* First try using our fixed size buffer */ va_copy(args, old_args); l = fz_vsnprintf(buffer, sizeof buffer, fmt, args); - va_end(args); + va_copy_end(args); /* If that failed, allocate the right size buffer dynamically */ if (l >= sizeof buffer) @@ -288,7 +280,7 @@ fz_vfprintf(fz_context *ctx, FILE *file, const char *fmt, va_list old_args) b = fz_malloc(ctx, l + 1); va_copy(args, old_args); fz_vsnprintf(buffer, l + 1, fmt, args); - va_end(args); + va_copy_end(args); } l = fwrite(b, 1, l, file); |