[vlc-devel] [RFC] Wrapper to work around %z limitation on Windows

Pierre Ynard linkfanel at yahoo.fr
Tue Feb 24 12:08:18 CET 2009


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


diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 87626e8..c35d2fc 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -38,6 +38,34 @@ 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 <stdio.h>
+# include <stdlib.h>
+# include <stdarg.h>
+# include <string.h>
+static inline int vlc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
+{
+    if (strstr(format, "%z"))
+    {
+        char *fmt = strdup(format), *f;
+        while ((f = strstr(fmt, "%z")) != NULL)
+        {
+           f[1] = 'l';
+        }
+        int r = vsnprintf(str, size, fmt, ap);
+        free(fmt);
+        return r;
+    }
+    else
+    {
+        return vsnprintf(str, size, format, ap);
+    }
+}
+#define vsnprintf(str, size, format, ap) vlc_vsnprintf(str, size, format, ap)
+#endif
+
 #ifndef HAVE_VASPRINTF
 # include <stdio.h>
 # include <stdlib.h>


Regards,

-- 
Pierre Ynard
"Une âme dans un corps, c'est comme un dessin sur une feuille de papier."



More information about the vlc-devel mailing list