1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs)
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "log.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/string.h"
38 #include "wx/window.h"
39 #include "wx/msgdlg.h"
41 #include "wx/msw/private.h"
47 #include "wx/textfile.h"
49 #include "wx/wxchar.h"
51 #include "wx/thread.h"
55 // other standard headers
60 #if defined(__WXMSW__)
61 #include "wx/msw/private.h" // includes windows.h for OutputDebugString
64 #if defined(__WXMAC__)
65 #include "wx/mac/private.h" // includes mac headers
68 // ----------------------------------------------------------------------------
69 // non member functions
70 // ----------------------------------------------------------------------------
72 // define this to enable wrapping of log messages
73 //#define LOG_PRETTY_WRAP
75 #ifdef LOG_PRETTY_WRAP
76 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
);
79 // ============================================================================
81 // ============================================================================
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // log functions can't allocate memory (LogError("out of memory...") should
88 // work!), so we use a static buffer for all log messages
89 #define LOG_BUFFER_SIZE (4096)
91 // static buffer for error messages
92 static wxChar s_szBufStatic
[LOG_BUFFER_SIZE
];
94 static wxChar
*s_szBuf
= s_szBufStatic
;
95 static size_t s_szBufSize
= WXSIZEOF( s_szBufStatic
);
99 // the critical section protecting the static buffer
100 static wxCriticalSection gs_csLogBuf
;
102 #endif // wxUSE_THREADS
104 // return true if we have a non NULL non disabled log target
105 static inline bool IsLoggingEnabled()
107 return wxLog::IsEnabled() && (wxLog::GetActiveTarget() != NULL
);
110 // ----------------------------------------------------------------------------
111 // implementation of Log functions
113 // NB: unfortunately we need all these distinct functions, we can't make them
114 // macros and not all compilers inline vararg functions.
115 // ----------------------------------------------------------------------------
117 // generic log function
118 void wxVLogGeneric(wxLogLevel level
, const wxChar
*szFormat
, va_list argptr
)
120 if ( IsLoggingEnabled() ) {
121 wxCRIT_SECT_LOCKER(locker
, gs_csLogBuf
);
123 wxVsnprintf(s_szBuf
, s_szBufSize
, szFormat
, argptr
);
125 wxLog::OnLog(level
, s_szBuf
, time(NULL
));
129 void wxLogGeneric(wxLogLevel level
, const wxChar
*szFormat
, ...)
132 va_start(argptr
, szFormat
);
133 wxVLogGeneric(level
, szFormat
, argptr
);
137 #define IMPLEMENT_LOG_FUNCTION(level) \
138 void wxVLog##level(const wxChar *szFormat, va_list argptr) \
140 if ( IsLoggingEnabled() ) { \
141 wxCRIT_SECT_LOCKER(locker, gs_csLogBuf); \
143 wxVsnprintf(s_szBuf, s_szBufSize, szFormat, argptr); \
145 wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
148 void wxLog##level(const wxChar *szFormat, ...) \
151 va_start(argptr, szFormat); \
152 wxVLog##level(szFormat, argptr); \
156 IMPLEMENT_LOG_FUNCTION(Error
)
157 IMPLEMENT_LOG_FUNCTION(Warning
)
158 IMPLEMENT_LOG_FUNCTION(Message
)
159 IMPLEMENT_LOG_FUNCTION(Info
)
160 IMPLEMENT_LOG_FUNCTION(Status
)
162 // fatal errors can't be suppressed nor handled by the custom log target and
163 // always terminate the program
164 void wxVLogFatalError(const wxChar
*szFormat
, va_list argptr
)
166 wxVsnprintf(s_szBuf
, s_szBufSize
, szFormat
, argptr
);
169 wxMessageBox(s_szBuf
, _("Fatal Error"), wxID_OK
| wxICON_STOP
);
171 wxFprintf(stderr
, _("Fatal error: %s\n"), s_szBuf
);
177 void wxLogFatalError(const wxChar
*szFormat
, ...)
180 va_start(argptr
, szFormat
);
181 wxVLogFatalError(szFormat
, argptr
);
185 // same as info, but only if 'verbose' mode is on
186 void wxVLogVerbose(const wxChar
*szFormat
, va_list argptr
)
188 if ( IsLoggingEnabled() ) {
189 wxLog
*pLog
= wxLog::GetActiveTarget();
190 if ( pLog
!= NULL
&& pLog
->GetVerbose() ) {
191 wxCRIT_SECT_LOCKER(locker
, gs_csLogBuf
);
193 wxVsnprintf(s_szBuf
, s_szBufSize
, szFormat
, argptr
);
195 wxLog::OnLog(wxLOG_Info
, s_szBuf
, time(NULL
));
200 void wxLogVerbose(const wxChar
*szFormat
, ...)
203 va_start(argptr
, szFormat
);
204 wxVLogVerbose(szFormat
, argptr
);
210 #define IMPLEMENT_LOG_DEBUG_FUNCTION(level) \
211 void wxVLog##level(const wxChar *szFormat, va_list argptr) \
213 if ( IsLoggingEnabled() ) { \
214 wxCRIT_SECT_LOCKER(locker, gs_csLogBuf); \
216 wxVsnprintf(s_szBuf, s_szBufSize, szFormat, argptr); \
218 wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
221 void wxLog##level(const wxChar *szFormat, ...) \
224 va_start(argptr, szFormat); \
225 wxVLog##level(szFormat, argptr); \
229 void wxVLogTrace(const wxChar
*mask
, const wxChar
*szFormat
, va_list argptr
)
231 if ( IsLoggingEnabled() && wxLog::IsAllowedTraceMask(mask
) ) {
232 wxCRIT_SECT_LOCKER(locker
, gs_csLogBuf
);
235 size_t len
= s_szBufSize
;
236 wxStrncpy(s_szBuf
, _T("("), len
);
237 len
-= 1; // strlen("(")
239 wxStrncat(p
, mask
, len
);
240 size_t lenMask
= wxStrlen(mask
);
244 wxStrncat(p
, _T(") "), len
);
248 wxVsnprintf(p
, len
, szFormat
, argptr
);
250 wxLog::OnLog(wxLOG_Trace
, s_szBuf
, time(NULL
));
254 void wxLogTrace(const wxChar
*mask
, const wxChar
*szFormat
, ...)
257 va_start(argptr
, szFormat
);
258 wxVLogTrace(mask
, szFormat
, argptr
);
262 void wxVLogTrace(wxTraceMask mask
, const wxChar
*szFormat
, va_list argptr
)
264 // we check that all of mask bits are set in the current mask, so
265 // that wxLogTrace(wxTraceRefCount | wxTraceOle) will only do something
266 // if both bits are set.
267 if ( IsLoggingEnabled() && ((wxLog::GetTraceMask() & mask
) == mask
) ) {
268 wxCRIT_SECT_LOCKER(locker
, gs_csLogBuf
);
270 wxVsnprintf(s_szBuf
, s_szBufSize
, szFormat
, argptr
);
272 wxLog::OnLog(wxLOG_Trace
, s_szBuf
, time(NULL
));
276 void wxLogTrace(wxTraceMask mask
, const wxChar
*szFormat
, ...)
279 va_start(argptr
, szFormat
);
280 wxVLogTrace(mask
, szFormat
, argptr
);
285 #define IMPLEMENT_LOG_DEBUG_FUNCTION(level)
288 IMPLEMENT_LOG_DEBUG_FUNCTION(Debug
)
289 IMPLEMENT_LOG_DEBUG_FUNCTION(Trace
)
291 // wxLogSysError: one uses the last error code, for other you must give it
294 // common part of both wxLogSysError
295 void wxLogSysErrorHelper(long lErrCode
)
297 wxChar szErrMsg
[LOG_BUFFER_SIZE
/ 2];
298 wxSnprintf(szErrMsg
, WXSIZEOF(szErrMsg
),
299 _(" (error %ld: %s)"), lErrCode
, wxSysErrorMsg(lErrCode
));
300 wxStrncat(s_szBuf
, szErrMsg
, s_szBufSize
- wxStrlen(s_szBuf
));
302 wxLog::OnLog(wxLOG_Error
, s_szBuf
, time(NULL
));
305 void WXDLLEXPORT
wxVLogSysError(const wxChar
*szFormat
, va_list argptr
)
307 if ( IsLoggingEnabled() ) {
308 wxCRIT_SECT_LOCKER(locker
, gs_csLogBuf
);
310 wxVsnprintf(s_szBuf
, s_szBufSize
, szFormat
, argptr
);
312 wxLogSysErrorHelper(wxSysErrorCode());
316 void WXDLLEXPORT
wxLogSysError(const wxChar
*szFormat
, ...)
319 va_start(argptr
, szFormat
);
320 wxVLogSysError(szFormat
, argptr
);
324 void WXDLLEXPORT
wxVLogSysError(long lErrCode
, const wxChar
*szFormat
, va_list argptr
)
326 if ( IsLoggingEnabled() ) {
327 wxCRIT_SECT_LOCKER(locker
, gs_csLogBuf
);
329 wxVsnprintf(s_szBuf
, s_szBufSize
, szFormat
, argptr
);
331 wxLogSysErrorHelper(lErrCode
);
335 void WXDLLEXPORT
wxLogSysError(long lErrCode
, const wxChar
*szFormat
, ...)
338 va_start(argptr
, szFormat
);
339 wxVLogSysError(lErrCode
, szFormat
, argptr
);
343 // ----------------------------------------------------------------------------
344 // wxLog class implementation
345 // ----------------------------------------------------------------------------
349 m_bHasMessages
= FALSE
;
352 wxChar
*wxLog::SetLogBuffer( wxChar
*buf
, size_t size
)
354 wxChar
*oldbuf
= s_szBuf
;
358 s_szBuf
= s_szBufStatic
;
359 s_szBufSize
= WXSIZEOF( s_szBufStatic
);
367 return (oldbuf
== s_szBufStatic
) ? 0 : oldbuf
;
370 wxLog
*wxLog::GetActiveTarget()
372 if ( ms_bAutoCreate
&& ms_pLogger
== NULL
) {
373 // prevent infinite recursion if someone calls wxLogXXX() from
374 // wxApp::CreateLogTarget()
375 static bool s_bInGetActiveTarget
= FALSE
;
376 if ( !s_bInGetActiveTarget
) {
377 s_bInGetActiveTarget
= TRUE
;
379 // ask the application to create a log target for us
380 if ( wxTheApp
!= NULL
)
381 ms_pLogger
= wxTheApp
->CreateLogTarget();
383 ms_pLogger
= new wxLogStderr
;
385 s_bInGetActiveTarget
= FALSE
;
387 // do nothing if it fails - what can we do?
394 wxLog
*wxLog::SetActiveTarget(wxLog
*pLogger
)
396 if ( ms_pLogger
!= NULL
) {
397 // flush the old messages before changing because otherwise they might
398 // get lost later if this target is not restored
402 wxLog
*pOldLogger
= ms_pLogger
;
403 ms_pLogger
= pLogger
;
408 void wxLog::DontCreateOnDemand()
410 ms_bAutoCreate
= FALSE
;
412 // this is usually called at the end of the program and we assume that it
413 // is *always* called at the end - so we free memory here to avoid false
414 // memory leak reports from wxWin memory tracking code
418 void wxLog::RemoveTraceMask(const wxString
& str
)
420 int index
= ms_aTraceMasks
.Index(str
);
421 if ( index
!= wxNOT_FOUND
)
422 ms_aTraceMasks
.Remove((size_t)index
);
425 void wxLog::ClearTraceMasks()
427 ms_aTraceMasks
.Clear();
430 void wxLog::TimeStamp(wxString
*str
)
436 (void)time(&timeNow
);
437 wxStrftime(buf
, WXSIZEOF(buf
), ms_timestamp
, localtime(&timeNow
));
440 *str
<< buf
<< wxT(": ");
444 void wxLog::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
447 case wxLOG_FatalError
:
448 DoLogString(wxString(_("Fatal error: ")) + szString
, t
);
449 DoLogString(_("Program aborted."), t
);
455 DoLogString(wxString(_("Error: ")) + szString
, t
);
459 DoLogString(wxString(_("Warning: ")) + szString
, t
);
466 default: // log unknown log levels too
467 DoLogString(szString
, t
);
474 wxString msg
= level
== wxLOG_Trace
? wxT("Trace: ")
484 void wxLog::DoLogString(const wxChar
*WXUNUSED(szString
), time_t WXUNUSED(t
))
486 wxFAIL_MSG(wxT("DoLogString must be overriden if it's called."));
491 // remember that we don't have any more messages to show
492 m_bHasMessages
= FALSE
;
495 // ----------------------------------------------------------------------------
496 // wxLogStderr class implementation
497 // ----------------------------------------------------------------------------
499 wxLogStderr::wxLogStderr(FILE *fp
)
507 #if defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ > 0x5300)
509 #if !TARGET_API_MAC_CARBON
510 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
512 #ifndef __MetroNubUtils__
513 #include "MetroNubUtils.h"
532 #if TARGET_API_MAC_CARBON
534 #include <CodeFragments.h>
537 CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
539 ProcPtr gCallUniversalProc_Proc
= NULL
;
543 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
545 static long fRunOnce
= false;
547 Boolean
IsCompatibleVersion(short inVersion
);
549 /* ---------------------------------------------------------------------------
551 --------------------------------------------------------------------------- */
553 Boolean
IsCompatibleVersion(short inVersion
)
555 Boolean result
= false;
559 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
561 result
= (inVersion
<= block
->apiHiVersion
);
567 /* ---------------------------------------------------------------------------
569 --------------------------------------------------------------------------- */
571 Boolean
IsMetroNubInstalled()
578 gMetroNubEntry
= NULL
;
580 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
582 /* look for MetroNub's Gestalt selector */
583 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
586 #if TARGET_API_MAC_CARBON
587 if (gCallUniversalProc_Proc
== NULL
)
589 CFragConnectionID connectionID
;
592 ProcPtr symbolAddress
;
594 CFragSymbolClass symbolClass
;
596 symbolAddress
= NULL
;
597 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
598 &connectionID
, &mainAddress
, errorString
);
602 gCallUniversalProc_Proc
= NULL
;
606 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
607 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
611 gCallUniversalProc_Proc
= NULL
;
618 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
620 /* make sure the version of the API is compatible */
621 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
622 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
623 gMetroNubEntry
= block
; /* success! */
632 #if TARGET_API_MAC_CARBON
633 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
635 return (gMetroNubEntry
!= NULL
);
639 /* ---------------------------------------------------------------------------
640 IsMWDebuggerRunning [v1 API]
641 --------------------------------------------------------------------------- */
643 Boolean
IsMWDebuggerRunning()
645 if (IsMetroNubInstalled())
646 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
651 /* ---------------------------------------------------------------------------
652 AmIBeingMWDebugged [v1 API]
653 --------------------------------------------------------------------------- */
655 Boolean
AmIBeingMWDebugged()
657 if (IsMetroNubInstalled())
658 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
663 /* ---------------------------------------------------------------------------
664 UserSetWatchPoint [v2 API]
665 --------------------------------------------------------------------------- */
667 OSErr
UserSetWatchPoint (Ptr address
, long length
, WatchPointIDT
* watchPointID
)
669 if (IsMetroNubInstalled() && IsCompatibleVersion(kMetroNubUserAPIVersion
))
670 return CallUserSetWatchPointProc(gMetroNubEntry
->userSetWatchPoint
,
671 address
, length
, watchPointID
);
673 return errProcessIsNotClient
;
676 /* ---------------------------------------------------------------------------
677 ClearWatchPoint [v2 API]
678 --------------------------------------------------------------------------- */
680 OSErr
ClearWatchPoint (WatchPointIDT watchPointID
)
682 if (IsMetroNubInstalled() && IsCompatibleVersion(kMetroNubUserAPIVersion
))
683 return CallClearWatchPointProc(gMetroNubEntry
->clearWatchPoint
, watchPointID
);
685 return errProcessIsNotClient
;
692 #endif // !TARGET_API_MAC_CARBON
694 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ > 0x5300)
696 void wxLogStderr::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
702 fputs(str
.mb_str(), m_fp
);
703 fputc(_T('\n'), m_fp
);
706 // under Windows, programs usually don't have stderr at all, so show the
707 // messages also under debugger - unless it's a console program
708 #if defined(__WXMSW__) && wxUSE_GUI && !defined(__WXMICROWIN__)
710 OutputDebugString(str
.c_str());
712 #if defined(__WXMAC__) && !defined(__DARWIN__) && wxUSE_GUI
714 strcpy( (char*) pstr
, str
.c_str() ) ;
715 strcat( (char*) pstr
, ";g" ) ;
716 c2pstr( (char*) pstr
) ;
718 Boolean running
= false ;
720 #if !TARGET_API_MAC_CARBON && (__MWERKS__ > 0x5300)
722 if ( IsMWDebuggerRunning() && AmIBeingMWDebugged() )
740 // ----------------------------------------------------------------------------
741 // wxLogStream implementation
742 // ----------------------------------------------------------------------------
744 #if wxUSE_STD_IOSTREAM
745 wxLogStream::wxLogStream(wxSTD ostream
*ostr
)
748 m_ostr
= &wxSTD cerr
;
753 void wxLogStream::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
757 (*m_ostr
) << str
<< wxConvertWX2MB(szString
) << wxSTD endl
;
759 #endif // wxUSE_STD_IOSTREAM
761 // ----------------------------------------------------------------------------
763 // ----------------------------------------------------------------------------
765 wxLogChain::wxLogChain(wxLog
*logger
)
768 m_logOld
= wxLog::SetActiveTarget(this);
771 wxLogChain::~wxLogChain()
776 void wxLogChain::SetLog(wxLog
*logger
)
778 if ( m_logNew
!= this )
781 wxLog::SetActiveTarget(logger
);
786 void wxLogChain::Flush()
791 // be careful to avoid inifinite recursion
792 if ( m_logNew
&& m_logNew
!= this )
796 void wxLogChain::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
798 // let the previous logger show it
799 if ( m_logOld
&& IsPassingMessages() )
801 // bogus cast just to access protected DoLog
802 ((wxLogChain
*)m_logOld
)->DoLog(level
, szString
, t
);
805 if ( m_logNew
&& m_logNew
!= this )
808 ((wxLogChain
*)m_logNew
)->DoLog(level
, szString
, t
);
812 // ----------------------------------------------------------------------------
814 // ----------------------------------------------------------------------------
817 // "'this' : used in base member initializer list" - so what?
818 #pragma warning(disable:4355)
821 wxLogPassThrough::wxLogPassThrough()
827 #pragma warning(default:4355)
830 // ============================================================================
831 // Global functions/variables
832 // ============================================================================
834 // ----------------------------------------------------------------------------
836 // ----------------------------------------------------------------------------
838 wxLog
*wxLog::ms_pLogger
= (wxLog
*)NULL
;
839 bool wxLog::ms_doLog
= TRUE
;
840 bool wxLog::ms_bAutoCreate
= TRUE
;
841 bool wxLog::ms_bVerbose
= FALSE
;
843 size_t wxLog::ms_suspendCount
= 0;
846 const wxChar
*wxLog::ms_timestamp
= wxT("%X"); // time only, no date
848 const wxChar
*wxLog::ms_timestamp
= NULL
; // save space
851 wxTraceMask
wxLog::ms_ulTraceMask
= (wxTraceMask
)0;
852 wxArrayString
wxLog::ms_aTraceMasks
;
854 // ----------------------------------------------------------------------------
855 // stdout error logging helper
856 // ----------------------------------------------------------------------------
858 // helper function: wraps the message and justifies it under given position
859 // (looks more pretty on the terminal). Also adds newline at the end.
861 // TODO this is now disabled until I find a portable way of determining the
862 // terminal window size (ok, I found it but does anybody really cares?)
863 #ifdef LOG_PRETTY_WRAP
864 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
)
866 size_t nMax
= 80; // FIXME
867 size_t nStart
= strlen(pszPrefix
);
871 while ( *psz
!= '\0' ) {
872 for ( n
= nStart
; (n
< nMax
) && (*psz
!= '\0'); n
++ )
876 if ( *psz
!= '\0' ) {
878 for ( n
= 0; n
< nStart
; n
++ )
881 // as we wrapped, squeeze all white space
882 while ( isspace(*psz
) )
889 #endif //LOG_PRETTY_WRAP
891 // ----------------------------------------------------------------------------
892 // error code/error message retrieval functions
893 // ----------------------------------------------------------------------------
895 // get error code from syste
896 unsigned long wxSysErrorCode()
898 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
900 return ::GetLastError();
902 // TODO what to do on Windows 3.1?
910 // get error message from system
911 const wxChar
*wxSysErrorMsg(unsigned long nErrCode
)
914 nErrCode
= wxSysErrorCode();
916 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
918 static wxChar s_szBuf
[LOG_BUFFER_SIZE
/ 2];
920 // get error message from system
922 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
924 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
928 // copy it to our buffer and free memory
929 if( lpMsgBuf
!= 0 ) {
930 wxStrncpy(s_szBuf
, (const wxChar
*)lpMsgBuf
, WXSIZEOF(s_szBuf
) - 1);
931 s_szBuf
[WXSIZEOF(s_szBuf
) - 1] = wxT('\0');
935 // returned string is capitalized and ended with '\r\n' - bad
936 s_szBuf
[0] = (wxChar
)wxTolower(s_szBuf
[0]);
937 size_t len
= wxStrlen(s_szBuf
);
940 if ( s_szBuf
[len
- 2] == wxT('\r') )
941 s_szBuf
[len
- 2] = wxT('\0');
945 s_szBuf
[0] = wxT('\0');
955 static wxChar s_szBuf
[LOG_BUFFER_SIZE
/ 2];
956 wxConvCurrent
->MB2WC(s_szBuf
, strerror(nErrCode
), WXSIZEOF(s_szBuf
) -1);
959 return strerror((int)nErrCode
);