Modify log functions to compile with MSVC6
authorMichael Plante <michael.plante@gmail.com>
Mon, 24 May 2010 14:57:10 +0000 (11:57 -0300)
committerDaniel Drake <dan@reactivated.net>
Mon, 24 May 2010 14:57:10 +0000 (11:57 -0300)
MSVC6 does not support variadics.

libusb/core.c
libusb/libusbi.h

index 716ca60..3e92f85 100644 (file)
@@ -1544,10 +1544,9 @@ API_EXPORTED void libusb_exit(struct libusb_context *ctx)
        free(ctx);
 }
 
-void usbi_log(struct libusb_context *ctx, enum usbi_log_level level,
-       const char *function, const char *format, ...)
+void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level,
+       const char *function, const char *format, va_list args)
 {
-       va_list args;
        FILE *stream = stdout;
        const char *prefix;
 
@@ -1585,13 +1584,21 @@ void usbi_log(struct libusb_context *ctx, enum usbi_log_level level,
 
        fprintf(stream, "libusb:%s [%s] ", prefix, function);
 
-       va_start (args, format);
        vfprintf(stream, format, args);
-       va_end (args);
 
        fprintf(stream, "\n");
 }
 
+void usbi_log(struct libusb_context *ctx, enum usbi_log_level level,
+       const char *function, const char *format, ...)
+{
+       va_list args;
+
+       va_start (args, format);
+       usbi_log_v(ctx, level, function, format, args);
+       va_end (args);
+}
+
 /** \ingroup misc
  * Returns a constant NULL-terminated string with an English short description
  * of the given error code. The caller should never free() the returned pointer
index 9a573bb..1a7731f 100644 (file)
@@ -112,24 +112,62 @@ enum usbi_log_level {
        LOG_LEVEL_ERROR,
 };
 
-void usbi_log(struct libusb_context *ctx, enum usbi_log_level,
+void usbi_log(struct libusb_context *ctx, enum usbi_log_level level,
        const char *function, const char *format, ...);
 
+#if !defined(_MSC_VER) || _MSC_VER > 1200
+
 #ifdef ENABLE_LOGGING
-#define _usbi_log(ctx, level, fmt...) usbi_log(ctx, level, __FUNCTION__, fmt)
+#define _usbi_log(ctx, level, ...) usbi_log(ctx, level, __FUNCTION__, __VA_ARGS__)
+#else
+#define _usbi_log(ctx, level, ...)
+#endif
+
+#ifdef ENABLE_DEBUG_LOGGING
+#define usbi_dbg(...) _usbi_log(NULL, LOG_LEVEL_DEBUG, __VA_ARGS__)
+#else
+#define usbi_dbg(...)
+#endif
+
+#define usbi_info(ctx, ...) _usbi_log(ctx, LOG_LEVEL_INFO, __VA_ARGS__)
+#define usbi_warn(ctx, ...) _usbi_log(ctx, LOG_LEVEL_WARNING, __VA_ARGS__)
+#define usbi_err(ctx, ...) _usbi_log(ctx, LOG_LEVEL_ERROR, __VA_ARGS__)
+
+#else /* !defined(_MSC_VER) || _MSC_VER > 1200 */
+
+void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level,
+       const char *function, const char *format, va_list args);
+
+#ifdef ENABLE_LOGGING
+#define LOG_BODY(ctxt, level) \
+{                             \
+       va_list args;             \
+       va_start (args, format);  \
+       usbi_log_v(ctxt, level, "", format, args); \
+       va_end(args);             \
+}
 #else
-#define _usbi_log(ctx, level, fmt...)
+#define LOG_BODY(ctxt, level) { }
 #endif
 
+static inline void usbi_info(struct libusb_context *ctx, const char *format,
+       ...)
+       LOG_BODY(ctx,LOG_LEVEL_INFO)
+static inline void usbi_warn(struct libusb_context *ctx, const char *format,
+       ...)
+       LOG_BODY(ctx,LOG_LEVEL_WARNING)
+static inline void usbi_err( struct libusb_context *ctx, const char *format,
+       ...)
+       LOG_BODY(ctx,LOG_LEVEL_ERROR)
+
+static inline void usbi_dbg(const char *format, ...)
 #ifdef ENABLE_DEBUG_LOGGING
-#define usbi_dbg(fmt...) _usbi_log(NULL, LOG_LEVEL_DEBUG, fmt)
+       LOG_BODY(NULL,LOG_LEVEL_DEBUG)
 #else
-#define usbi_dbg(fmt...)
+{ }
 #endif
 
-#define usbi_info(ctx, fmt...) _usbi_log(ctx, LOG_LEVEL_INFO, fmt)
-#define usbi_warn(ctx, fmt...) _usbi_log(ctx, LOG_LEVEL_WARNING, fmt)
-#define usbi_err(ctx, fmt...) _usbi_log(ctx, LOG_LEVEL_ERROR, fmt)
+#endif /* !defined(_MSC_VER) || _MSC_VER > 1200 */
 
 #define USBI_GET_CONTEXT(ctx) if (!(ctx)) (ctx) = usbi_default_context
 #define DEVICE_CTX(dev) ((dev)->ctx)