[vlc-devel] commit: Win32: wrappers to work around %z printf (Pierre Ynard )

git version control git at videolan.org
Tue Mar 10 17:06:55 CET 2009


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Tue Mar 10 10:48:09 2009 +0100| [5b61614c29e2cc6149536ce847b7580ba1151025] | committer: Rémi Denis-Courmont 

Win32: wrappers to work around %z printf

This patch works around unsupported %z modifiers, by using a wrapper
around *printf functions that patches the format string on the fly. The
format string is duplicated, and "%z"'s are replaced by "%l"'s.

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5b61614c29e2cc6149536ce847b7580ba1151025
---

 include/vlc_fixups.h |  110 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 110 insertions(+), 0 deletions(-)

diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 87626e8..f685806 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -38,6 +38,116 @@ static inline char *strdup (const char *str)
 }
 #endif
 
+#ifdef WIN32
+/* Windows' printf doesn't support %z modifiers, thus we need to rewrite
+ * the format string in a wrapper. */
+# include <string.h>
+static inline char *vlc_fix_format_string (const char *format)
+{
+    char *fmt, *f;
+    if (strstr (format, "%z") == NULL)
+        return NULL;
+
+    fmt = strdup (format);
+    if (fmt == NULL)
+        return NULL;
+
+    while ((f = strstr (fmt, "%z")) != NULL)
+    {
+       f[1] = 'l';
+    }
+    return fmt;
+}
+
+# include <stdlib.h>
+# include <stdio.h>
+# include <stdarg.h>
+
+static inline int vlc_vprintf (const char *format, va_list ap)
+{
+    char *fmt = vlc_fix_format_string (format);
+    int ret = vprintf (fmt ? fmt : format, ap);
+    free (fmt);
+    return ret;
+}
+# define vprintf vlc_vprintf
+
+static inline int vlc_vfprintf (FILE *stream, const char *format, va_list ap)
+{
+    char *fmt = vlc_fix_format_string (format);
+    int ret = vfprintf (stream, fmt ? fmt : format, ap);
+    free (fmt);
+    return ret;
+}
+# define vfprintf vlc_vfprintf
+
+static inline int vlc_vsprintf (char *str, const char *format, va_list ap)
+{
+    char *fmt = vlc_fix_format_string (format);
+    int ret = vsprintf (str, fmt ? fmt : format, ap);
+    free (fmt);
+    return ret;
+}
+# define vsprintf vlc_vsprintf
+
+static inline int vlc_vsnprintf (char *str, size_t size, const char *format, va_list ap)
+{
+    char *fmt = vlc_fix_format_string (format);
+    int ret = vsnprintf (str, size, fmt ? fmt : format, ap);
+    free (fmt);
+    return ret;
+}
+# define vsnprintf vlc_vsnprintf
+
+static inline int vlc_printf (const char *format, ...)
+{
+    va_list ap;
+    int ret;
+    va_start (ap, format);
+    ret = vprintf (format, ap);
+    va_end (ap);
+    return ret;
+}
+# define printf(...) vlc_printf(__VA_ARGS__)
+
+static inline int vlc_fprintf (FILE *stream, const char *format, ...)
+{
+    va_list ap;
+    int ret;
+    va_start (ap, format);
+    ret = vfprintf (stream, format, ap);
+    va_end (ap);
+    return ret;
+}
+# define fprintf vlc_fprintf
+
+static inline int vlc_sprintf (char *str, const char *format, ...)
+{
+    va_list ap;
+    int ret;
+    va_start (ap, format);
+    ret = vsprintf (str, format, ap);
+    va_end (ap);
+    return ret;
+}
+# define sprintf vlc_sprintf
+
+static inline int vlc_snprintf (char *str, size_t size, const char *format, ...)
+{
+    va_list ap;
+    int ret;
+    va_start (ap, format);
+    ret = vsnprintf (str, size, format, ap);
+    va_end (ap);
+    return ret;
+}
+# define snprintf vlc_snprintf
+
+/* Make sure we don't use flawed vasprintf or asprintf either */
+# undef HAVE_VASPRINTF
+# undef HAVE_ASPRINTF
+#endif
+
 #ifndef HAVE_VASPRINTF
 # include <stdio.h>
 # include <stdlib.h>




More information about the vlc-devel mailing list