2003-01-26 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / dbus / dbus-internals.c
index e90703e..eed91d1 100644 (file)
@@ -21,6 +21,8 @@
  *
  */
 #include "dbus-internals.h"
+#include "dbus-protocol.h"
+#include "dbus-test.h"
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
@@ -28,6 +30,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <stdlib.h>
 
 /**
  * @defgroup DBusInternals D-BUS internal implementation details
@@ -144,24 +147,32 @@ _dbus_warn (const char *format,
 /**
  * Prints a warning message to stderr
  * if the user has enabled verbose mode.
+ * This is the real function implementation,
+ * use _dbus_verbose() macro in code.
  *
  * @param format printf-style format string.
  */
 void
-_dbus_verbose (const char *format,
-               ...)
+_dbus_verbose_real (const char *format,
+                    ...)
 {
   va_list args;
   static dbus_bool_t verbose = TRUE;
   static dbus_bool_t initted = FALSE;
 
+  /* things are written a bit oddly here so that
+   * in the non-verbose case we just have the one
+   * conditional and return immediately.
+   */
   if (!verbose)
     return;
   
   if (!initted)
     {
-      verbose = getenv ("DBUS_VERBOSE") != NULL;
+      verbose = _dbus_getenv ("DBUS_VERBOSE") != NULL;
       initted = TRUE;
+      if (!verbose)
+        return;
     }
   
   va_start (args, format);
@@ -185,6 +196,9 @@ _dbus_strerror (int error_number)
 /**
  * Converts a UNIX errno into a DBusResultCode.
  *
+ * @todo should cover more errnos, specifically those
+ * from open().
+ * 
  * @param error_number the errno.
  * @returns the result code.
  */
@@ -263,7 +277,15 @@ _dbus_result_from_errno (int error_number)
 #ifdef EADDRINUSE
     case EADDRINUSE:
       return DBUS_RESULT_ADDRESS_IN_USE;
-#endif      
+#endif
+#ifdef EEXIST
+    case EEXIST:
+      return DBUS_RESULT_FILE_NOT_FOUND;
+#endif
+#ifdef ENOENT
+    case ENOENT:
+      return DBUS_RESULT_FILE_NOT_FOUND;
+#endif
     }
 
   return DBUS_RESULT_FAILED;
@@ -331,4 +353,32 @@ _dbus_set_fd_nonblocking (int             fd,
   return TRUE;
 }
 
+/**
+ * Returns a string describing the given type.
+ *
+ * @param type the type to describe
+ * @returns a constant string describing the type
+ */
+const char *
+_dbus_type_to_string (int type)
+{
+  switch (type)
+    {
+    case DBUS_TYPE_INVALID:
+      return "invalid";
+    case DBUS_TYPE_INT32:
+      return "int32";
+    case DBUS_TYPE_UINT32:
+      return "uint32";
+    case DBUS_TYPE_DOUBLE:
+      return "double";
+    case DBUS_TYPE_STRING:
+      return "string";
+    case DBUS_TYPE_BYTE_ARRAY:
+      return "byte array";
+    default:
+      return "unknown";
+    }
+}
+
 /** @} */