/****************************************************************************
- * Copyright (c) 1998-2013,2016 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2016,2017 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.84 2016/11/27 02:35:17 tom Exp $")
+MODULE_ID("$Id: lib_trace.c,v 1.86 2017/01/14 17:53:42 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 {
bool after = FALSE;
unsigned doit = _nc_tracing;
int save_err = errno;
+ FILE *fp = MyFP;
+
+#ifdef TRACE
+ /* verbose-trace in the command-line utilities relies on this */
+ if (fp == 0 && !MyInit && _nc_tracing >= DEBUG_LEVEL(1))
+ fp = stderr;
+#endif
if (strlen(fmt) >= sizeof(Called) - 1) {
if (!strncmp(fmt, Called, sizeof(Called) - 1)) {
}
}
- if (doit != 0 && MyFP != 0) {
+ if (doit != 0 && fp != 0) {
#ifdef USE_PTHREADS
/*
* TRACE_ICALLS is "really" needed to show normal use with threaded
if ((pthread_self))
# endif
#ifdef __MINGW32__
- fprintf(MyFP, "%#lx:", (long) (intptr_t) pthread_self().p);
+ fprintf(fp, "%#lx:", (long) (intptr_t) pthread_self().p);
#else
- fprintf(MyFP, "%#lx:", (long) (intptr_t) pthread_self());
+ fprintf(fp, "%#lx:", (long) (intptr_t) pthread_self());
#endif
#endif
if (before || after) {
int n;
for (n = 1; n < MyLevel; n++)
- fputs("+ ", MyFP);
+ fputs("+ ", fp);
}
- vfprintf(MyFP, fmt, ap);
- fputc('\n', MyFP);
- fflush(MyFP);
+ vfprintf(fp, fmt, ap);
+ fputc('\n', fp);
+ fflush(fp);
}
if (after && MyLevel)