20
20
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
25
#include "dbus-internals.h"
24
26
#include "dbus-protocol.h"
25
27
#include "dbus-marshal-basic.h"
189
195
* making up a different string every time and wasting
192
const char _dbus_no_memory_message[] = "Not enough memory";
198
const char *_dbus_no_memory_message = "Not enough memory";
194
200
static dbus_bool_t warn_initted = FALSE;
195
201
static dbus_bool_t fatal_warnings = FALSE;
295
301
#include <pthread.h>
307
#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
308
static char module_name[1024];
302
311
static inline void
303
312
_dbus_verbose_init (void)
305
314
if (!verbose_initted)
307
const char *p = _dbus_getenv ("DBUS_VERBOSE");
316
const char *p = _dbus_getenv ("DBUS_VERBOSE");
308
317
verbose = p != NULL && *p == '1';
309
318
verbose_initted = TRUE;
319
#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
321
char *last_period, *last_slash;
322
GetModuleFileName(0,module_name,sizeof(module_name)-1);
323
last_period = _mbsrchr(module_name,'.');
326
last_slash = _mbsrchr(module_name,'\\');
328
strcpy(module_name,last_slash+1);
329
strcat(module_name,": ");
335
/** @def DBUS_IS_DIR_SEPARATOR(c)
336
* macro for checking if character c is a patch separator
338
* @todo move to a header file so that others can use this too
341
#define DBUS_IS_DIR_SEPARATOR(c) (c == '\\' || c == '/')
343
#define DBUS_IS_DIR_SEPARATOR(c) (c == '/')
347
remove source root from file path
348
the source root is determined by
350
static char *_dbus_file_path_extract_elements_from_tail(const char *file,int level)
352
static int prefix = -1;
357
char *p = (char *)file + strlen(file);
362
if (DBUS_IS_DIR_SEPARATOR(*p))
372
return (char *)file+prefix;
331
393
* @param format printf-style format string.
396
#ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
397
_dbus_verbose_real (const char *file,
399
const char *function,
334
402
_dbus_verbose_real (const char *format,
364
434
need_pid = FALSE;
366
436
va_start (args, format);
437
#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
440
strcpy(buf,module_name);
441
#ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
442
sprintf (buf+strlen(buf), "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function);
444
vsprintf (buf+strlen(buf),format, args);
446
OutputDebugStringA(buf);
449
#ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
450
fprintf (stderr, "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function);
367
453
vfprintf (stderr, format, args);
635
/* FIXME this is racy; we need a save_file_exclusively
636
* function. But in practice this should be fine for now.
638
* - first be sure we can create the file and it
639
* doesn't exist by creating it empty with O_EXCL
640
* - then create it by creating a temporary file and
641
* overwriting atomically with rename()
643
if (!_dbus_create_file_exclusively (filename, error))
646
722
if (!_dbus_string_append_byte (&encoded, '\n'))
648
724
_DBUS_SET_OOM (error);
652
if (!_dbus_string_save_to_file (&encoded, filename, error))
655
if (!_dbus_make_file_world_readable (filename, error))
728
if (!_dbus_string_save_to_file (&encoded, filename, TRUE, error))
658
731
_dbus_string_free (&encoded);
798
871
#ifndef DBUS_DISABLE_CHECKS
799
872
/** String used in _dbus_return_if_fail macro */
800
const char _dbus_return_if_fail_warning_format[] =
873
const char *_dbus_return_if_fail_warning_format =
801
874
"arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
802
875
"This is normally a bug in some application using the D-Bus library.\n";