shithub: libdvdcss

Download patch

ref: df37e6e222bcd2504b0fe7434bfd69429750d428
parent: 1b4e3f9e1c4e7b53cce59b802f95f6400ba641dd
author: Diego Biurrun <[email protected]>
date: Mon Nov 17 08:43:35 EST 2014

Convert debug print macro to a function.

This reduces library size by ~10%.
Also allow passing extra arguments to the error printing function.

--- a/src/error.c
+++ b/src/error.c
@@ -20,19 +20,47 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *****************************************************************************/
 
+#include <stdarg.h>
 #include <stdio.h>
 
 #include "libdvdcss.h"
 
+static void print_message( const char *prefix, const char *psz_string,
+                           va_list args )
+{
+    fprintf( stderr, "libdvdcss %s: ", prefix );
+    vfprintf( stderr, psz_string, args );
+    fprintf( stderr, "\n" );
+}
+
 /*****************************************************************************
  * Error messages
  *****************************************************************************/
-void print_error( dvdcss_t dvdcss, const char *psz_string )
+void print_error( dvdcss_t dvdcss, const char *psz_string, ... )
 {
     if( dvdcss->b_errors )
     {
-        fprintf( stderr, "libdvdcss error: %s\n", psz_string );
+        va_list args;
+
+        va_start( args, psz_string );
+        print_message("error", psz_string, args);
+        va_end( args );
     }
 
     dvdcss->psz_error = psz_string;
+}
+
+/*****************************************************************************
+ * Debug messages
+ *****************************************************************************/
+void print_debug( const dvdcss_t dvdcss, const char *psz_string, ... )
+{
+    if( dvdcss->b_debug )
+    {
+        va_list args;
+
+        va_start( args, psz_string );
+        print_message("debug", psz_string, args );
+        va_end( args );
+    }
 }
--- a/src/libdvdcss.h
+++ b/src/libdvdcss.h
@@ -84,14 +84,7 @@
 /*****************************************************************************
  * Functions used across the library
  *****************************************************************************/
-#define print_debug( dvdcss, ... ) \
-    if( dvdcss->b_debug ) \
-    { \
-        fprintf( stderr, "libdvdcss debug: " ); \
-        fprintf( stderr, __VA_ARGS__ ); \
-        fprintf( stderr, "\n" ); \
-    }
-
-void print_error ( dvdcss_t, const char * );
+void print_error ( dvdcss_t, const char *, ... );
+void print_debug ( const dvdcss_t, const char *, ... );
 
 #endif /* DVDCSS_LIBDVDCSS_H */