Changeset 35182 in vbox for trunk/include/iprt
- Timestamp:
- Dec 16, 2010 1:57:44 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 69021
- Location:
- trunk/include/iprt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/err.h
r34786 r35182 29 29 #include <iprt/cdefs.h> 30 30 #include <iprt/types.h> 31 #include <iprt/stdarg.h> 31 32 32 33 … … 279 280 */ 280 281 RTDECL(int) RTErrConvertToErrno(int iErr); 281 282 282 283 283 #ifdef IN_RING3 … … 392 392 393 393 #endif /* IN_RING3 */ 394 395 /** @defgroup RTERRINFO_FLAGS_XXX RTERRINFO::fFlags 396 * @{ */ 397 /** Custom structure (the default). */ 398 #define RTERRINFO_FLAGS_T_CUSTOM UINT32_C(0) 399 /** Static structure (RTERRINFOSTATIC). */ 400 #define RTERRINFO_FLAGS_T_STATIC UINT32_C(1) 401 /** Allocated structure (RTErrInfoAlloc). */ 402 #define RTERRINFO_FLAGS_T_ALLOC UINT32_C(2) 403 /** Reserved type. */ 404 #define RTERRINFO_FLAGS_T_RESERVED UINT32_C(3) 405 /** Type mask. */ 406 #define RTERRINFO_FLAGS_T_MASK UINT32_C(3) 407 /** Error info is set. */ 408 #define RTERRINFO_FLAGS_SET RT_BIT_32(2) 409 /** Fixed flags (magic). */ 410 #define RTERRINFO_FLAGS_MAGIC UINT32_C(0xbabe0000) 411 /** The bit mask for the magic value. */ 412 #define RTERRINFO_FLAGS_MAGIC_MASK UINT32_C(0xffff0000) 413 /** @} */ 414 415 /** 416 * Initializes an error info structure. 417 * 418 * @returns @a pErrInfo. 419 * @param pErrInfo The error info structure to init. 420 * @param pszMsg The message buffer. Must be at least one byte. 421 * @param cbMsg The size of the message buffer. 422 */ 423 DECLINLINE(PRTERRINFO) RTErrInfoInit(PRTERRINFO pErrInfo, char *pszMsg, size_t cbMsg) 424 { 425 *pszMsg = '\0'; 426 427 pErrInfo->fFlags = RTERRINFO_FLAGS_T_CUSTOM | RTERRINFO_FLAGS_MAGIC; 428 pErrInfo->rc = /*VINF_SUCCESS*/ 0; 429 pErrInfo->pszMsg = pszMsg; 430 pErrInfo->cbMsg = cbMsg; 431 pErrInfo->apvReserved[0] = NULL; 432 pErrInfo->apvReserved[1] = NULL; 433 434 return pErrInfo; 435 } 436 437 /** 438 * Initialize a static error info structure. 439 * 440 * @param pStaticErrInfo The static error info structure to init. 441 */ 442 DECLINLINE(void) RTErrInfoInitStatic(PRTERRINFOSTATIC pStaticErrInfo) 443 { 444 RTErrInfoInit(&pStaticErrInfo->Core, pStaticErrInfo->szMsg, sizeof(pStaticErrInfo->szMsg)); 445 pStaticErrInfo->Core.fFlags = RTERRINFO_FLAGS_T_STATIC | RTERRINFO_FLAGS_MAGIC; 446 } 447 448 /** 449 * Allocates a error info structure with a buffer at least the given size. 450 * 451 * @returns Pointer to an error info structure on success, NULL on failure. 452 * 453 * @param cbMsg The minimum message buffer size. Use 0 to get 454 * the default buffer size. 455 */ 456 RTDECL(PRTERRINFO) RTErrInfoAlloc(size_t cbMsg); 457 458 /** 459 * Same as RTErrInfoAlloc, except that an IPRT status code is returned. 460 * 461 * @returns IPRT status code. 462 * 463 * @param cbMsg The minimum message buffer size. Use 0 to get 464 * the default buffer size. 465 * @param ppErrInfo Where to store the pointer to the allocated 466 * error info structure on success. This is 467 * always set to NULL. 468 */ 469 RTDECL(int) RTErrInfoAllocEx(size_t cbMsg, PRTERRINFO *ppErrInfo); 470 471 /** 472 * Frees an error info structure allocated by RTErrInfoAlloc or 473 * RTErrInfoAllocEx. 474 * 475 * @param pErrInfo The error info structure. 476 */ 477 RTDECL(void) RTErrInfoFree(PRTERRINFO pErrInfo); 478 479 /** 480 * Fills in the error info details. 481 * 482 * @returns @a rc. 483 * 484 * @param pErrInfo The error info structure to fill in. 485 * @param rc The status code to return. 486 * @param pszMsg The error message string. 487 */ 488 RTDECL(int) RTErrInfoSet(PRTERRINFO pErrInfo, int rc, const char *pszMsg); 489 490 /** 491 * Fills in the error info details, with a sprintf style message. 492 * 493 * @returns @a rc. 494 * 495 * @param pErrInfo The error info structure to fill in. 496 * @param rc The status code to return. 497 * @param pszFormat The format string. 498 * @param ... The format arguments. 499 */ 500 RTDECL(int) RTErrInfoSetF(PRTERRINFO pErrInfo, int rc, const char *pszFormat, ...); 501 502 /** 503 * Fills in the error info details, with a vsprintf style message. 504 * 505 * @returns @a rc. 506 * 507 * @param pErrInfo The error info structure to fill in. 508 * @param rc The status code to return. 509 * @param pszFormat The format string. 510 * @param va The format arguments. 511 */ 512 RTDECL(int) RTErrInfoSetV(PRTERRINFO pErrInfo, int rc, const char *pszFormat, va_list va); 513 514 /** 515 * Checks if the error info is set. 516 * 517 * @returns true if set, false if not. 518 * @param pErrInfo The error info structure. NULL is OK. 519 */ 520 DECLINLINE(bool) RTErrInfoIsSet(PCRTERRINFO pErrInfo) 521 { 522 if (!pErrInfo) 523 return false; 524 return (pErrInfo->fFlags & (RTERRINFO_FLAGS_MAGIC_MASK | RTERRINFO_FLAGS_SET)) 525 == (RTERRINFO_FLAGS_MAGIC | RTERRINFO_FLAGS_SET); 526 } 527 528 /** 529 * Clears the error info structure. 530 * 531 * @param pErrInfo The error info structure. NULL is OK. 532 */ 533 DECLINLINE(void) RTErrInfoClear(PRTERRINFO pErrInfo) 534 { 535 if (pErrInfo) 536 { 537 pErrInfo->fFlags &= ~RTERRINFO_FLAGS_SET; 538 pErrInfo->rc = /*VINF_SUCCESS*/0; 539 *pErrInfo->pszMsg = '\0'; 540 } 541 } 394 542 395 543 RT_C_DECLS_END -
trunk/include/iprt/types.h
r34882 r35182 1647 1647 1648 1648 /** 1649 * Error info. 1650 * 1651 * See RTErrInfo*. 1652 */ 1653 typedef struct RTERRINFO 1654 { 1655 /** Flags, see RTERRINFO_FLAGS_XXX. */ 1656 uint32_t fFlags; 1657 /** The status code. */ 1658 int32_t rc; 1659 /** The size of the message */ 1660 size_t cbMsg; 1661 /** The error buffer. */ 1662 char *pszMsg; 1663 /** Reserved for future use. */ 1664 void *apvReserved[2]; 1665 } RTERRINFO; 1666 /** Pointer to an error info structure. */ 1667 typedef RTERRINFO *PRTERRINFO; 1668 /** Pointer to a const error info structure. */ 1669 typedef RTERRINFO const *PCRTERRINFO; 1670 1671 /** 1672 * Static error info structure, see RTErrInfoInitStatic. 1673 */ 1674 typedef struct RTERRINFOSTATIC 1675 { 1676 /** The core error info. */ 1677 RTERRINFO Core; 1678 /** The static message buffer. */ 1679 char szMsg[3072]; 1680 } RTERRINFOSTATIC; 1681 /** Pointer to a error info buffer. */ 1682 typedef RTERRINFOSTATIC *PRTERRINFOSTATIC; 1683 /** Pointer to a const static error info buffer. */ 1684 typedef RTERRINFOSTATIC const *PCRTERRINFOSTATIC; 1685 1686 1687 /** 1649 1688 * UUID data type. 1650 1689 * 1651 * @note IPRT defines that the first three integers in the @c Gen struct 1652 * interpretation are in little endian representation. This is different to 1653 * many other UUID implementation, and requires conversion if you need to 1654 * achieve consistent results. 1690 * See RTUuid*. 1691 * 1692 * @remarks IPRT defines that the first three integers in the @c Gen struct 1693 * interpretation are in little endian representation. This is 1694 * different to many other UUID implementation, and requires 1695 * conversion if you need to achieve consistent results. 1655 1696 */ 1656 1697 typedef union RTUUID … … 1680 1721 typedef const RTUUID *PCRTUUID; 1681 1722 1682 /** 1683 * UUID string maximum length. 1684 */ 1723 /** UUID string maximum length. */ 1685 1724 #define RTUUID_STR_LENGTH 37 1686 1725 … … 1688 1727 /** Compression handle. */ 1689 1728 typedef struct RTZIPCOMP *PRTZIPCOMP; 1690 1691 1729 /** Decompressor handle. */ 1692 1730 typedef struct RTZIPDECOMP *PRTZIPDECOMP;
Note:
See TracChangeset
for help on using the changeset viewer.