Procházet zdrojové kódy

DEBUG: add BDSM_perror

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
Thomas Guillem před 10 roky
rodič
revize
e38bdc5fd2
3 změnil soubory, kde provedl 35 přidání a 12 odebrání
  1. 26 3
      src/bdsm_debug.h
  2. 5 5
      src/netbios_ns.c
  3. 4 4
      src/netbios_session.c

+ 26 - 3
src/bdsm_debug.h

@@ -21,13 +21,36 @@
 
 # include "config.h"
 
+# ifdef __ANDROID__
+#  define LOG_TAG "libdsm"
+#  include <android/log.h>
+#  include <stdio.h>
+#  include <errno.h>
+#  include <stdarg.h>
+   static inline void BDSM_perror(const char *format, ...)
+   {
+       va_list ap;
+       char *buf;
+
+       va_start(ap, format);
+       if (vasprintf(&buf, format, ap) == -1) {
+           va_end(ap);
+           return -1;
+       }
+       va_end(ap);
+       __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "%s%s",
+                           buf, strerror(errno));
+       free(buf);
+   }
+# else
+#   include <stdio.h>
+#   define BDSM_perror(...) perror(__VA_ARGS__)
+# endif
+
 # ifdef BDSM_DEBUG
 #  ifdef __ANDROID__
-#   define LOG_TAG "libdsm"
-#   include <android/log.h>
 #   define BDSM_dbg(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
 #  else
-#   include <stdio.h>
 #   define BDSM_dbg(...) fprintf(stderr, __VA_ARGS__)
 #  endif
 # else

+ 5 - 5
src/netbios_ns.c

@@ -61,7 +61,7 @@ static int    ns_open_socket(netbios_ns *ns)
     return (1);
 
 error:
-    perror("netbios_ns_new, open_socket: ");
+    BDSM_perror("netbios_ns_new, open_socket: ");
     return (0);
 }
 
@@ -118,7 +118,7 @@ int               netbios_ns_send_query(netbios_ns *ns, netbios_query *q,
 
     if (sent < 0)
     {
-        perror("netbios_ns_send_query: ");
+        BDSM_perror("netbios_ns_send_query: ");
         return (0);
     }
 
@@ -155,7 +155,7 @@ ssize_t           netbios_ns_recv(int sock, void *buf, size_t buf_size,
         return (0);
 
 error:
-    perror("netbios_ns_recv: ");
+    BDSM_perror("netbios_ns_recv: ");
     return (-1);
 }
 
@@ -212,7 +212,7 @@ int      netbios_ns_resolve(netbios_ns *ns, const char *name, char type, uint32_
     recv = netbios_ns_recv(ns->socket, (void *)recv_buffer, 512, &timeout, 0, 0);
 
     if (recv <= 0)
-        perror("netbios_ns_resolve:");
+        BDSM_perror("netbios_ns_resolve:");
     else if (recv == 0)
         BDSM_dbg("netbios_ns_resolve, received NO reply for '%s' !\n", name);
     else
@@ -371,7 +371,7 @@ const char        *netbios_ns_inverse(netbios_ns *ns, uint32_t ip)
         return (NULL);
 
 error:
-    perror("netbios_ns_inverse: ");
+    BDSM_perror("netbios_ns_inverse: ");
     return (NULL);
 }
 

+ 4 - 4
src/netbios_session.c

@@ -40,7 +40,7 @@ static int        open_socket_and_connect(netbios_session *s)
     return (1);
 
 error:
-    perror("netbios_session_new, open_socket: ");
+    BDSM_perror("netbios_session_new, open_socket: ");
     return (0);
 }
 
@@ -186,7 +186,7 @@ int               netbios_session_packet_send(netbios_session *s)
 
     if (sent != to_send)
     {
-        perror("netbios_session_packet_send: Unable to send (full?) packet");
+        BDSM_perror("netbios_session_packet_send: Unable to send (full?) packet");
         return (0);
     }
 
@@ -203,7 +203,7 @@ ssize_t           netbios_session_packet_recv(netbios_session *s, void **data)
     res = recv(s->socket, (void *)(s->packet), s->packet_payload_size, 0);
     if (res < 0)
     {
-        perror("netbios_session_packet_recv: ");
+        BDSM_perror("netbios_session_packet_recv: ");
         return (-1);
     }
     if ((size_t)res < sizeof(netbios_session_packet))
@@ -235,7 +235,7 @@ ssize_t           netbios_session_packet_recv(netbios_session *s, void **data)
 
         if (res < 0)
         {
-            perror("netbios_session_packet_recv: ");
+            BDSM_perror("netbios_session_packet_recv: ");
             return (-1);
         }
         sofar += res;