VirtualBox

source: vbox/trunk/include/iprt/errcore.h@ 76373

Last change on this file since 76373 was 76348, checked in by vboxsync, 6 years ago

iprt/err*.h: Make VINF_SUCCESS available via errcore.h too.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.7 KB
Line 
1/** @file
2 * IPRT - Status Codes Core.
3 */
4
5/*
6 * Copyright (C) 2006-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_errcore_h
27#define ___iprt_errcore_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31#include <iprt/stdarg.h>
32
33
34/** @defgroup grp_rt_err_core Status Codes Core
35 * @ingroup grp_rt_err
36 * @{
37 */
38
39/** Success.
40 * @ingroup grp_rt_err */
41#define VINF_SUCCESS 0
42
43
44/** @def RTERR_STRICT_RC
45 * Indicates that RT_SUCCESS_NP, RT_SUCCESS, RT_FAILURE_NP and RT_FAILURE should
46 * make type enforcing at compile time.
47 *
48 * @remarks Only define this for C++ code.
49 */
50#if defined(__cplusplus) \
51 && !defined(RTERR_STRICT_RC) \
52 && !defined(RTERR_NO_STRICT_RC) \
53 && ( defined(DOXYGEN_RUNNING) \
54 || defined(DEBUG) \
55 || defined(RT_STRICT) )
56# define RTERR_STRICT_RC 1
57#endif
58
59
60/** @def RT_SUCCESS
61 * Check for success. We expect success in normal cases, that is the code path depending on
62 * this check is normally taken. To prevent any prediction use RT_SUCCESS_NP instead.
63 *
64 * @returns true if rc indicates success.
65 * @returns false if rc indicates failure.
66 *
67 * @param rc The iprt status code to test.
68 */
69#define RT_SUCCESS(rc) ( RT_LIKELY(RT_SUCCESS_NP(rc)) )
70
71/** @def RT_SUCCESS_NP
72 * Check for success. Don't predict the result.
73 *
74 * @returns true if rc indicates success.
75 * @returns false if rc indicates failure.
76 *
77 * @param rc The iprt status code to test.
78 */
79#ifdef RTERR_STRICT_RC
80# define RT_SUCCESS_NP(rc) ( RTErrStrictType(rc).success() )
81#else
82# define RT_SUCCESS_NP(rc) ( (int)(rc) >= VINF_SUCCESS )
83#endif
84
85/** @def RT_FAILURE
86 * Check for failure, predicting unlikely.
87 *
88 * We don't expect in normal cases, that is the code path depending on this
89 * check is normally NOT taken. To prevent any prediction use RT_FAILURE_NP
90 * instead.
91 *
92 * @returns true if rc indicates failure.
93 * @returns false if rc indicates success.
94 *
95 * @param rc The iprt status code to test.
96 *
97 * @remarks Please structure your code to use the RT_SUCCESS() macro instead of
98 * RT_FAILURE() where possible, as that gives us a better shot at good
99 * code with the windows compilers.
100 */
101#define RT_FAILURE(rc) ( RT_UNLIKELY(!RT_SUCCESS_NP(rc)) )
102
103/** @def RT_FAILURE_NP
104 * Check for failure, no prediction.
105 *
106 * @returns true if rc indicates failure.
107 * @returns false if rc indicates success.
108 *
109 * @param rc The iprt status code to test.
110 */
111#define RT_FAILURE_NP(rc) ( !RT_SUCCESS_NP(rc) )
112
113
114#ifdef __cplusplus
115/**
116 * Strict type validation class.
117 *
118 * This is only really useful for type checking the arguments to RT_SUCCESS,
119 * RT_SUCCESS_NP, RT_FAILURE and RT_FAILURE_NP. The RTErrStrictType2
120 * constructor is for integration with external status code strictness regimes.
121 */
122class RTErrStrictType
123{
124protected:
125 int32_t m_rc;
126
127public:
128 /**
129 * Constructor for interaction with external status code strictness regimes.
130 *
131 * This is a special constructor for helping external return code validator
132 * classes interact cleanly with RT_SUCCESS, RT_SUCCESS_NP, RT_FAILURE and
133 * RT_FAILURE_NP while barring automatic cast to integer.
134 *
135 * @param rcObj IPRT status code object from an automatic cast.
136 */
137 RTErrStrictType(RTErrStrictType2 const rcObj)
138 : m_rc(rcObj.getValue())
139 {
140 }
141
142 /**
143 * Integer constructor used by RT_SUCCESS_NP.
144 *
145 * @param rc IPRT style status code.
146 */
147 RTErrStrictType(int32_t rc)
148 : m_rc(rc)
149 {
150 }
151
152#if 0 /** @todo figure where int32_t is long instead of int. */
153 /**
154 * Integer constructor used by RT_SUCCESS_NP.
155 *
156 * @param rc IPRT style status code.
157 */
158 RTErrStrictType(signed int rc)
159 : m_rc(rc)
160 {
161 }
162#endif
163
164 /**
165 * Test for success.
166 */
167 bool success() const
168 {
169 return m_rc >= 0;
170 }
171
172private:
173 /** @name Try ban a number of wrong types.
174 * @{ */
175 RTErrStrictType(uint8_t rc) : m_rc(-999) { NOREF(rc); }
176 RTErrStrictType(uint16_t rc) : m_rc(-999) { NOREF(rc); }
177 RTErrStrictType(uint32_t rc) : m_rc(-999) { NOREF(rc); }
178 RTErrStrictType(uint64_t rc) : m_rc(-999) { NOREF(rc); }
179 RTErrStrictType(int8_t rc) : m_rc(-999) { NOREF(rc); }
180 RTErrStrictType(int16_t rc) : m_rc(-999) { NOREF(rc); }
181 RTErrStrictType(int64_t rc) : m_rc(-999) { NOREF(rc); }
182 /** @todo fight long here - clashes with int32_t/int64_t on some platforms. */
183 /** @} */
184};
185#endif /* __cplusplus */
186
187
188RT_C_DECLS_BEGIN
189
190/**
191 * Converts a Darwin HRESULT error to an iprt status code.
192 *
193 * @returns iprt status code.
194 * @param iNativeCode HRESULT error code.
195 * @remark Darwin ring-3 only.
196 */
197RTDECL(int) RTErrConvertFromDarwinCOM(int32_t iNativeCode);
198
199/**
200 * Converts a Darwin IOReturn error to an iprt status code.
201 *
202 * @returns iprt status code.
203 * @param iNativeCode IOReturn error code.
204 * @remark Darwin only.
205 */
206RTDECL(int) RTErrConvertFromDarwinIO(int iNativeCode);
207
208/**
209 * Converts a Darwin kern_return_t error to an iprt status code.
210 *
211 * @returns iprt status code.
212 * @param iNativeCode kern_return_t error code.
213 * @remark Darwin only.
214 */
215RTDECL(int) RTErrConvertFromDarwinKern(int iNativeCode);
216
217/**
218 * Converts a Darwin error to an iprt status code.
219 *
220 * This will consult RTErrConvertFromDarwinKern, RTErrConvertFromDarwinIO
221 * and RTErrConvertFromDarwinCOM in this order. The latter is ring-3 only as it
222 * doesn't apply elsewhere.
223 *
224 * @returns iprt status code.
225 * @param iNativeCode Darwin error code.
226 * @remarks Darwin only.
227 * @remarks This is recommended over RTErrConvertFromDarwinKern and RTErrConvertFromDarwinIO
228 * since these are really just subsets of the same error space.
229 */
230RTDECL(int) RTErrConvertFromDarwin(int iNativeCode);
231
232/**
233 * Converts errno to iprt status code.
234 *
235 * @returns iprt status code.
236 * @param uNativeCode errno code.
237 */
238RTDECL(int) RTErrConvertFromErrno(unsigned uNativeCode);
239
240/**
241 * Converts a L4 errno to a iprt status code.
242 *
243 * @returns iprt status code.
244 * @param uNativeCode l4 errno.
245 * @remark L4 only.
246 */
247RTDECL(int) RTErrConvertFromL4Errno(unsigned uNativeCode);
248
249/**
250 * Converts NT status code to iprt status code.
251 *
252 * Needless to say, this is only available on NT and winXX targets.
253 *
254 * @returns iprt status code.
255 * @param lNativeCode NT status code.
256 * @remark Windows only.
257 */
258RTDECL(int) RTErrConvertFromNtStatus(long lNativeCode);
259
260/**
261 * Converts OS/2 error code to iprt status code.
262 *
263 * @returns iprt status code.
264 * @param uNativeCode OS/2 error code.
265 * @remark OS/2 only.
266 */
267RTDECL(int) RTErrConvertFromOS2(unsigned uNativeCode);
268
269/**
270 * Converts Win32 error code to iprt status code.
271 *
272 * @returns iprt status code.
273 * @param uNativeCode Win32 error code.
274 * @remark Windows only.
275 */
276RTDECL(int) RTErrConvertFromWin32(unsigned uNativeCode);
277
278/**
279 * Converts an iprt status code to a errno status code.
280 *
281 * @returns errno status code.
282 * @param iErr iprt status code.
283 */
284RTDECL(int) RTErrConvertToErrno(int iErr);
285
286#ifdef IN_RING3
287
288/**
289 * iprt status code message.
290 */
291typedef struct RTSTATUSMSG
292{
293 /** Pointer to the short message string. */
294 const char *pszMsgShort;
295 /** Pointer to the full message string. */
296 const char *pszMsgFull;
297 /** Pointer to the define string. */
298 const char *pszDefine;
299 /** Status code number. */
300 int iCode;
301} RTSTATUSMSG;
302/** Pointer to iprt status code message. */
303typedef RTSTATUSMSG *PRTSTATUSMSG;
304/** Pointer to const iprt status code message. */
305typedef const RTSTATUSMSG *PCRTSTATUSMSG;
306
307/**
308 * Get the message structure corresponding to a given iprt status code.
309 *
310 * @returns Pointer to read-only message description.
311 * @param rc The status code.
312 */
313RTDECL(PCRTSTATUSMSG) RTErrGet(int rc);
314
315/**
316 * Get the define corresponding to a given iprt status code.
317 *
318 * @returns Pointer to read-only string with the \#define identifier.
319 * @param rc The status code.
320 */
321#define RTErrGetDefine(rc) (RTErrGet(rc)->pszDefine)
322
323/**
324 * Get the short description corresponding to a given iprt status code.
325 *
326 * @returns Pointer to read-only string with the description.
327 * @param rc The status code.
328 */
329#define RTErrGetShort(rc) (RTErrGet(rc)->pszMsgShort)
330
331/**
332 * Get the full description corresponding to a given iprt status code.
333 *
334 * @returns Pointer to read-only string with the description.
335 * @param rc The status code.
336 */
337#define RTErrGetFull(rc) (RTErrGet(rc)->pszMsgFull)
338
339#ifdef RT_OS_WINDOWS
340/**
341 * Windows error code message.
342 */
343typedef struct RTWINERRMSG
344{
345 /** Pointer to the full message string. */
346 const char *pszMsgFull;
347 /** Pointer to the define string. */
348 const char *pszDefine;
349 /** Error code number. */
350 long iCode;
351} RTWINERRMSG;
352/** Pointer to Windows error code message. */
353typedef RTWINERRMSG *PRTWINERRMSG;
354/** Pointer to const Windows error code message. */
355typedef const RTWINERRMSG *PCRTWINERRMSG;
356
357/**
358 * Get the message structure corresponding to a given Windows error code.
359 *
360 * @returns Pointer to read-only message description.
361 * @param rc The status code.
362 */
363RTDECL(PCRTWINERRMSG) RTErrWinGet(long rc);
364
365/** On windows COM errors are part of the Windows error database. */
366typedef RTWINERRMSG RTCOMERRMSG;
367
368#else /* !RT_OS_WINDOWS */
369
370/**
371 * COM/XPCOM error code message.
372 */
373typedef struct RTCOMERRMSG
374{
375 /** Pointer to the full message string. */
376 const char *pszMsgFull;
377 /** Pointer to the define string. */
378 const char *pszDefine;
379 /** Error code number. */
380 uint32_t iCode;
381} RTCOMERRMSG;
382#endif /* !RT_OS_WINDOWS */
383/** Pointer to a XPCOM/COM error code message. */
384typedef RTCOMERRMSG *PRTCOMERRMSG;
385/** Pointer to const a XPCOM/COM error code message. */
386typedef const RTCOMERRMSG *PCRTCOMERRMSG;
387
388/**
389 * Get the message structure corresponding to a given COM/XPCOM error code.
390 *
391 * @returns Pointer to read-only message description.
392 * @param rc The status code.
393 */
394RTDECL(PCRTCOMERRMSG) RTErrCOMGet(uint32_t rc);
395
396#endif /* IN_RING3 */
397
398/** @defgroup RTERRINFO_FLAGS_XXX RTERRINFO::fFlags
399 * @{ */
400/** Custom structure (the default). */
401#define RTERRINFO_FLAGS_T_CUSTOM UINT32_C(0)
402/** Static structure (RTERRINFOSTATIC). */
403#define RTERRINFO_FLAGS_T_STATIC UINT32_C(1)
404/** Allocated structure (RTErrInfoAlloc). */
405#define RTERRINFO_FLAGS_T_ALLOC UINT32_C(2)
406/** Reserved type. */
407#define RTERRINFO_FLAGS_T_RESERVED UINT32_C(3)
408/** Type mask. */
409#define RTERRINFO_FLAGS_T_MASK UINT32_C(3)
410/** Error info is set. */
411#define RTERRINFO_FLAGS_SET RT_BIT_32(2)
412/** Fixed flags (magic). */
413#define RTERRINFO_FLAGS_MAGIC UINT32_C(0xbabe0000)
414/** The bit mask for the magic value. */
415#define RTERRINFO_FLAGS_MAGIC_MASK UINT32_C(0xffff0000)
416/** @} */
417
418/**
419 * Initializes an error info structure.
420 *
421 * @returns @a pErrInfo.
422 * @param pErrInfo The error info structure to init.
423 * @param pszMsg The message buffer. Must be at least one byte.
424 * @param cbMsg The size of the message buffer.
425 */
426DECLINLINE(PRTERRINFO) RTErrInfoInit(PRTERRINFO pErrInfo, char *pszMsg, size_t cbMsg)
427{
428 *pszMsg = '\0';
429
430 pErrInfo->fFlags = RTERRINFO_FLAGS_T_CUSTOM | RTERRINFO_FLAGS_MAGIC;
431 pErrInfo->rc = /*VINF_SUCCESS*/ 0;
432 pErrInfo->pszMsg = pszMsg;
433 pErrInfo->cbMsg = cbMsg;
434 pErrInfo->apvReserved[0] = NULL;
435 pErrInfo->apvReserved[1] = NULL;
436
437 return pErrInfo;
438}
439
440/**
441 * Initialize a static error info structure.
442 *
443 * @returns Pointer to the core error info structure.
444 * @param pStaticErrInfo The static error info structure to init.
445 */
446DECLINLINE(PRTERRINFO) RTErrInfoInitStatic(PRTERRINFOSTATIC pStaticErrInfo)
447{
448 RTErrInfoInit(&pStaticErrInfo->Core, pStaticErrInfo->szMsg, sizeof(pStaticErrInfo->szMsg));
449 pStaticErrInfo->Core.fFlags = RTERRINFO_FLAGS_T_STATIC | RTERRINFO_FLAGS_MAGIC;
450 return &pStaticErrInfo->Core;
451}
452
453/**
454 * Allocates a error info structure with a buffer at least the given size.
455 *
456 * @returns Pointer to an error info structure on success, NULL on failure.
457 *
458 * @param cbMsg The minimum message buffer size. Use 0 to get
459 * the default buffer size.
460 */
461RTDECL(PRTERRINFO) RTErrInfoAlloc(size_t cbMsg);
462
463/**
464 * Same as RTErrInfoAlloc, except that an IPRT status code is returned.
465 *
466 * @returns IPRT status code.
467 *
468 * @param cbMsg The minimum message buffer size. Use 0 to get
469 * the default buffer size.
470 * @param ppErrInfo Where to store the pointer to the allocated
471 * error info structure on success. This is
472 * always set to NULL.
473 */
474RTDECL(int) RTErrInfoAllocEx(size_t cbMsg, PRTERRINFO *ppErrInfo);
475
476/**
477 * Frees an error info structure allocated by RTErrInfoAlloc or
478 * RTErrInfoAllocEx.
479 *
480 * @param pErrInfo The error info structure.
481 */
482RTDECL(void) RTErrInfoFree(PRTERRINFO pErrInfo);
483
484/**
485 * Fills in the error info details.
486 *
487 * @returns @a rc.
488 *
489 * @param pErrInfo The error info structure to fill in.
490 * @param rc The status code to return.
491 * @param pszMsg The error message string.
492 */
493RTDECL(int) RTErrInfoSet(PRTERRINFO pErrInfo, int rc, const char *pszMsg);
494
495/**
496 * Fills in the error info details, with a sprintf style message.
497 *
498 * @returns @a rc.
499 *
500 * @param pErrInfo The error info structure to fill in.
501 * @param rc The status code to return.
502 * @param pszFormat The format string.
503 * @param ... The format arguments.
504 */
505RTDECL(int) RTErrInfoSetF(PRTERRINFO pErrInfo, int rc, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
506
507/**
508 * Fills in the error info details, with a vsprintf style message.
509 *
510 * @returns @a rc.
511 *
512 * @param pErrInfo The error info structure to fill in.
513 * @param rc The status code to return.
514 * @param pszFormat The format string.
515 * @param va The format arguments.
516 */
517RTDECL(int) RTErrInfoSetV(PRTERRINFO pErrInfo, int rc, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
518
519/**
520 * Adds more error info details.
521 *
522 * @returns @a rc.
523 *
524 * @param pErrInfo The error info structure to fill in.
525 * @param rc The status code to return.
526 * @param pszMsg The error message string to add.
527 */
528RTDECL(int) RTErrInfoAdd(PRTERRINFO pErrInfo, int rc, const char *pszMsg);
529
530/**
531 * Adds more error info details, with a sprintf style message.
532 *
533 * @returns @a rc.
534 *
535 * @param pErrInfo The error info structure to fill in.
536 * @param rc The status code to return.
537 * @param pszFormat The format string to add.
538 * @param ... The format arguments.
539 */
540RTDECL(int) RTErrInfoAddF(PRTERRINFO pErrInfo, int rc, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
541
542/**
543 * Adds more error info details, with a vsprintf style message.
544 *
545 * @returns @a rc.
546 *
547 * @param pErrInfo The error info structure to fill in.
548 * @param rc The status code to return.
549 * @param pszFormat The format string to add.
550 * @param va The format arguments.
551 */
552RTDECL(int) RTErrInfoAddV(PRTERRINFO pErrInfo, int rc, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
553
554/** @name RTERRINFO_LOG_F_XXX
555 * @{ */
556/** Both debug and release log. */
557#define RTERRINFO_LOG_F_RELEASE RT_BIT_32(0)
558/** @} */
559
560/**
561 * Fills in the error info details.
562 *
563 * @returns @a rc.
564 *
565 * @param pErrInfo The error info structure to fill in.
566 * @param rc The status code to return.
567 * @param iLogGroup The logging group.
568 * @param fFlags RTERRINFO_LOG_F_XXX.
569 * @param pszMsg The error message string.
570 */
571RTDECL(int) RTErrInfoLogAndSet(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszMsg);
572
573/**
574 * Fills in the error info details, with a sprintf style message.
575 *
576 * @returns @a rc.
577 *
578 * @param pErrInfo The error info structure to fill in.
579 * @param rc The status code to return.
580 * @param iLogGroup The logging group.
581 * @param fFlags RTERRINFO_LOG_F_XXX.
582 * @param pszFormat The format string.
583 * @param ... The format arguments.
584 */
585RTDECL(int) RTErrInfoLogAndSetF(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(5, 6);
586
587/**
588 * Fills in the error info details, with a vsprintf style message.
589 *
590 * @returns @a rc.
591 *
592 * @param pErrInfo The error info structure to fill in.
593 * @param rc The status code to return.
594 * @param iLogGroup The logging group.
595 * @param fFlags RTERRINFO_LOG_F_XXX.
596 * @param pszFormat The format string.
597 * @param va The format arguments.
598 */
599RTDECL(int) RTErrInfoLogAndSetV(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(5, 0);
600
601/**
602 * Adds more error info details.
603 *
604 * @returns @a rc.
605 *
606 * @param pErrInfo The error info structure to fill in.
607 * @param rc The status code to return.
608 * @param iLogGroup The logging group.
609 * @param fFlags RTERRINFO_LOG_F_XXX.
610 * @param pszMsg The error message string to add.
611 */
612RTDECL(int) RTErrInfoLogAndAdd(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszMsg);
613
614/**
615 * Adds more error info details, with a sprintf style message.
616 *
617 * @returns @a rc.
618 *
619 * @param pErrInfo The error info structure to fill in.
620 * @param rc The status code to return.
621 * @param iLogGroup The logging group.
622 * @param fFlags RTERRINFO_LOG_F_XXX.
623 * @param pszFormat The format string to add.
624 * @param ... The format arguments.
625 */
626RTDECL(int) RTErrInfoLogAndAddF(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(5, 6);
627
628/**
629 * Adds more error info details, with a vsprintf style message.
630 *
631 * @returns @a rc.
632 *
633 * @param pErrInfo The error info structure to fill in.
634 * @param rc The status code to return.
635 * @param iLogGroup The logging group.
636 * @param fFlags RTERRINFO_LOG_F_XXX.
637 * @param pszFormat The format string to add.
638 * @param va The format arguments.
639 */
640RTDECL(int) RTErrInfoLogAndAddV(PRTERRINFO pErrInfo, int rc, uint32_t iLogGroup, uint32_t fFlags, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(5, 0);
641
642/** @name Macros wrapping the RTErrInfoLog* functions.
643 * @{ */
644#ifndef LOG_DISABLED
645# define RTERRINFO_LOG_SET( a_pErrInfo, a_rc, a_pszMsg) RTErrInfoLogAndSet( a_pErrInfo, a_rc, LOG_GROUP, 0, a_pszMsg)
646# define RTERRINFO_LOG_SET_V(a_pErrInfo, a_rc, a_pszMsg, a_va) RTErrInfoLogAndSetV(a_pErrInfo, a_rc, LOG_GROUP, 0, a_pszMsg, a_va)
647# define RTERRINFO_LOG_ADD( a_pErrInfo, a_rc, a_pszMsg) RTErrInfoLogAndAdd( a_pErrInfo, a_rc, LOG_GROUP, 0, a_pszMsg)
648# define RTERRINFO_LOG_ADD_V(a_pErrInfo, a_rc, a_pszMsg, a_va) RTErrInfoLogAndAddV(a_pErrInfo, a_rc, LOG_GROUP, 0, a_pszMsg, a_va)
649# ifdef RT_COMPILER_SUPPORTS_VA_ARGS
650# define RTERRINFO_LOG_ADD_F(a_pErrInfo, a_rc, ...) RTErrInfoLogAndAddF(a_pErrInfo, a_rc, LOG_GROUP, 0, __VA_ARGS__)
651# define RTERRINFO_LOG_SET_F(a_pErrInfo, a_rc, ...) RTErrInfoLogAndSetF(a_pErrInfo, a_rc, LOG_GROUP, 0, __VA_ARGS__)
652# else
653# define RTERRINFO_LOG_ADD_F RTErrInfoSetF
654# define RTERRINFO_LOG_SET_F RTErrInfoAddF
655# endif
656#else
657# define RTERRINFO_LOG_SET( a_pErrInfo, a_rc, a_pszMsg) RTErrInfoSet( a_pErrInfo, a_rc, a_pszMsg)
658# define RTERRINFO_LOG_SET_V(a_pErrInfo, a_rc, a_pszMsg, a_va) RTErrInfoSetV(a_pErrInfo, a_rc, a_pszMsg, a_va)
659# define RTERRINFO_LOG_ADD( a_pErrInfo, a_rc, a_pszMsg) RTErrInfoAdd( a_pErrInfo, a_rc, a_pszMsg)
660# define RTERRINFO_LOG_ADD_V(a_pErrInfo, a_rc, a_pszMsg, a_va) RTErrInfoAddV(a_pErrInfo, a_rc, a_pszMsg, a_va)
661# define RTERRINFO_LOG_ADD_F RTErrInfoSetF
662# define RTERRINFO_LOG_SET_F RTErrInfoAddF
663#endif
664
665#define RTERRINFO_LOG_REL_SET( a_pErrInfo, a_rc, a_pszMsg) RTErrInfoLogAndSet( a_pErrInfo, a_rc, LOG_GROUP, RTERRINFO_LOG_F_RELEASE, a_pszMsg)
666#define RTERRINFO_LOG_REL_SET_V(a_pErrInfo, a_rc, a_pszMsg, a_va) RTErrInfoLogAndSetV(a_pErrInfo, a_rc, LOG_GROUP, RTERRINFO_LOG_F_RELEASE, a_pszMsg, a_va)
667#define RTERRINFO_LOG_REL_ADD( a_pErrInfo, a_rc, a_pszMsg) RTErrInfoLogAndAdd( a_pErrInfo, a_rc, LOG_GROUP, RTERRINFO_LOG_F_RELEASE, a_pszMsg)
668#define RTERRINFO_LOG_REL_ADD_V(a_pErrInfo, a_rc, a_pszMsg, a_va) RTErrInfoLogAndAddV(a_pErrInfo, a_rc, LOG_GROUP, RTERRINFO_LOG_F_RELEASE, a_pszMsg, a_va)
669#ifdef RT_COMPILER_SUPPORTS_VA_ARGS
670# define RTERRINFO_LOG_REL_ADD_F(a_pErrInfo, a_rc, ...) RTErrInfoLogAndAddF(a_pErrInfo, a_rc, LOG_GROUP, RTERRINFO_LOG_F_RELEASE, __VA_ARGS__)
671# define RTERRINFO_LOG_REL_SET_F(a_pErrInfo, a_rc, ...) RTErrInfoLogAndSetF(a_pErrInfo, a_rc, LOG_GROUP, RTERRINFO_LOG_F_RELEASE, __VA_ARGS__)
672#else
673# define RTERRINFO_LOG_REL_ADD_F RTErrInfoSetF
674# define RTERRINFO_LOG_REL_SET_F RTErrInfoAddF
675#endif
676/** @} */
677
678
679/**
680 * Checks if the error info is set.
681 *
682 * @returns true if set, false if not.
683 * @param pErrInfo The error info structure. NULL is OK.
684 */
685DECLINLINE(bool) RTErrInfoIsSet(PCRTERRINFO pErrInfo)
686{
687 if (!pErrInfo)
688 return false;
689 return (pErrInfo->fFlags & (RTERRINFO_FLAGS_MAGIC_MASK | RTERRINFO_FLAGS_SET))
690 == (RTERRINFO_FLAGS_MAGIC | RTERRINFO_FLAGS_SET);
691}
692
693/**
694 * Clears the error info structure.
695 *
696 * @param pErrInfo The error info structure. NULL is OK.
697 */
698DECLINLINE(void) RTErrInfoClear(PRTERRINFO pErrInfo)
699{
700 if (pErrInfo)
701 {
702 pErrInfo->fFlags &= ~RTERRINFO_FLAGS_SET;
703 pErrInfo->rc = /*VINF_SUCCESS*/0;
704 *pErrInfo->pszMsg = '\0';
705 }
706}
707
708/**
709 * Storage for error variables.
710 *
711 * @remarks Do NOT touch the members! They are platform specific and what's
712 * where may change at any time!
713 */
714typedef union RTERRVARS
715{
716 int8_t ai8Vars[32];
717 int16_t ai16Vars[16];
718 int32_t ai32Vars[8];
719 int64_t ai64Vars[4];
720} RTERRVARS;
721/** Pointer to an error variable storage union. */
722typedef RTERRVARS *PRTERRVARS;
723/** Pointer to a const error variable storage union. */
724typedef RTERRVARS const *PCRTERRVARS;
725
726/**
727 * Saves the error variables.
728 *
729 * @returns @a pVars.
730 * @param pVars The variable storage union.
731 */
732RTDECL(PRTERRVARS) RTErrVarsSave(PRTERRVARS pVars);
733
734/**
735 * Restores the error variables.
736 *
737 * @param pVars The variable storage union.
738 */
739RTDECL(void) RTErrVarsRestore(PCRTERRVARS pVars);
740
741/**
742 * Checks if the first variable set equals the second.
743 *
744 * @returns true if they are equal, false if not.
745 * @param pVars1 The first variable storage union.
746 * @param pVars2 The second variable storage union.
747 */
748RTDECL(bool) RTErrVarsAreEqual(PCRTERRVARS pVars1, PCRTERRVARS pVars2);
749
750/**
751 * Checks if the (live) error variables have changed since we saved them.
752 *
753 * @returns @c true if they have changed, @c false if not.
754 * @param pVars The saved variables to compare the current state
755 * against.
756 */
757RTDECL(bool) RTErrVarsHaveChanged(PCRTERRVARS pVars);
758
759RT_C_DECLS_END
760
761/** @} */
762
763#endif
764
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette