/****************************************************************************
- * Copyright (c) 1998-2013,2016 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2017,2018 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
#include <ctype.h>
-MODULE_ID("$Id: lib_trace.c,v 1.85 2016/12/31 13:50:06 tom Exp $")
+MODULE_ID("$Id: lib_trace.c,v 1.89 2018/12/16 01:05:30 tom Exp $")
NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */
#define MyFP _nc_globals.trace_fp
#define MyFD _nc_globals.trace_fd
+#define MyInit _nc_globals.trace_opened
#define MyPath _nc_globals.trace_fname
#define MyLevel _nc_globals.trace_level
#define MyNested _nc_globals.nested_tracef
trace(const unsigned int tracelevel)
{
if ((MyFP == 0) && tracelevel) {
+ MyInit = TRUE;
if (MyFD >= 0) {
MyFP = fdopen(MyFD, "wb");
} else {
#ifdef TRACE
/* verbose-trace in the command-line utilities relies on this */
- if (fp == 0 && _nc_tracing >= DEBUG_LEVEL(1))
+ if (fp == 0 && !MyInit && _nc_tracing >= DEBUG_LEVEL(1))
fp = stderr;
#endif
# if USE_WEAK_SYMBOLS
if ((pthread_self))
# endif
-#ifdef __MINGW32__
+#ifdef _WIN32
fprintf(fp, "%#lx:", (long) (intptr_t) pthread_self().p);
#else
fprintf(fp, "%#lx:", (long) (intptr_t) pthread_self());
return code;
}
+NCURSES_EXPORT(char *)
+_nc_fmt_funcptr(char *target, const char *source, size_t size)
+{
+ size_t n;
+ char *dst = target;
+ bool leading = TRUE;
+
+ union {
+ int value;
+ char bytes[sizeof(int)];
+ } byteorder;
+
+ byteorder.value = 0x1234;
+
+ *dst++ = '0';
+ *dst++ = 'x';
+
+ for (n = 0; n < size; ++n) {
+ unsigned ch = ((byteorder.bytes[0] == 0x34)
+ ? UChar(source[size - n - 1])
+ : UChar(source[n]));
+ if (ch != 0 || (n + 1) >= size)
+ leading = FALSE;
+ if (!leading) {
+ sprintf(dst, "%02x", ch & 0xff);
+ dst += 2;
+ }
+ }
+ *dst = '\0';
+ return target;
+}
+
#if USE_REENTRANT
/*
* Check if the given trace-mask is enabled.