errinfo.cpp revision 13493ab7596e827b8d0caab2c89e635dd65f78f9
2N/A/* $Id$ */
2N/A/** @file
2N/A * IPRT - Error Info, Setters.
2N/A */
2N/A
2N/A/*
2N/A * Copyright (C) 2010-2014 Oracle Corporation
2N/A *
2N/A * This file is part of VirtualBox Open Source Edition (OSE), as
2N/A * available from http://www.virtualbox.org. This file is free software;
2N/A * you can redistribute it and/or modify it under the terms of the GNU
2N/A * General Public License (GPL) as published by the Free Software
2N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
2N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2N/A *
2N/A * The contents of this file may alternatively be used under the terms
2N/A * of the Common Development and Distribution License Version 1.0
2N/A * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
2N/A * VirtualBox OSE distribution, in which case the provisions of the
2N/A * CDDL are applicable instead of those of the GPL.
2N/A *
2N/A * You may elect to license modified versions of this file under the
2N/A * terms and conditions of either the GPL or the CDDL or both.
2N/A */
2N/A
2N/A
2N/A/*******************************************************************************
2N/A* Header Files *
2N/A*******************************************************************************/
2N/A#include "internal/iprt.h"
2N/A#include <iprt/err.h>
2N/A
2N/A#include <iprt/assert.h>
2N/A#include <iprt/string.h>
2N/A
2N/A
2N/ARTDECL(int) RTErrInfoSet(PRTERRINFO pErrInfo, int rc, const char *pszMsg)
2N/A{
2N/A if (pErrInfo)
2N/A {
2N/A AssertPtr(pErrInfo);
2N/A Assert((pErrInfo->fFlags & RTERRINFO_FLAGS_MAGIC_MASK) == RTERRINFO_FLAGS_MAGIC);
2N/A
2N/A RTStrCopy(pErrInfo->pszMsg, pErrInfo->cbMsg, pszMsg);
2N/A pErrInfo->rc = rc;
2N/A pErrInfo->fFlags |= RTERRINFO_FLAGS_SET;
2N/A }
2N/A return rc;
2N/A}
2N/A
2N/A
2N/ARTDECL(int) RTErrInfoSetF(PRTERRINFO pErrInfo, int rc, const char *pszFormat, ...)
2N/A{
2N/A va_list va;
2N/A va_start(va, pszFormat);
2N/A RTErrInfoSetV(pErrInfo, rc, pszFormat, va);
2N/A va_end(va);
2N/A return rc;
2N/A}
2N/A
2N/A
2N/ARTDECL(int) RTErrInfoSetV(PRTERRINFO pErrInfo, int rc, const char *pszFormat, va_list va)
2N/A{
2N/A if (pErrInfo)
2N/A {
2N/A AssertPtr(pErrInfo);
2N/A Assert((pErrInfo->fFlags & RTERRINFO_FLAGS_MAGIC_MASK) == RTERRINFO_FLAGS_MAGIC);
2N/A
2N/A RTStrPrintfV(pErrInfo->pszMsg, pErrInfo->cbMsg, pszFormat, va);
2N/A pErrInfo->rc = rc;
2N/A pErrInfo->fFlags |= RTERRINFO_FLAGS_SET;
2N/A }
2N/A return rc;
2N/A}
2N/A
2N/A
2N/ARTDECL(int) RTErrInfoAdd(PRTERRINFO pErrInfo, int rc, const char *pszMsg)
2N/A{
2N/A if (pErrInfo)
2N/A {
2N/A AssertPtr(pErrInfo);
2N/A if (pErrInfo->fFlags & RTERRINFO_FLAGS_SET)
2N/A RTStrCat(pErrInfo->pszMsg, pErrInfo->cbMsg, pszMsg);
2N/A else
2N/A {
2N/A while (*pszMsg == ' ')
2N/A pszMsg++;
2N/A return RTErrInfoSet(pErrInfo, rc, pszMsg);
2N/A }
2N/A }
2N/A return rc;
2N/A}
2N/A
2N/A
2N/ARTDECL(int) RTErrInfoAddF(PRTERRINFO pErrInfo, int rc, const char *pszFormat, ...)
2N/A{
2N/A va_list va;
2N/A va_start(va, pszFormat);
2N/A RTErrInfoAddV(pErrInfo, rc, pszFormat, va);
2N/A va_end(va);
2N/A return rc;
2N/A}
2N/A
2N/A
2N/ARTDECL(int) RTErrInfoAddV(PRTERRINFO pErrInfo, int rc, const char *pszFormat, va_list va)
2N/A{
2N/A if (pErrInfo)
2N/A {
2N/A AssertPtr(pErrInfo);
2N/A Assert((pErrInfo->fFlags & RTERRINFO_FLAGS_MAGIC_MASK) == RTERRINFO_FLAGS_MAGIC);
2N/A if (pErrInfo->fFlags & RTERRINFO_FLAGS_SET)
2N/A {
2N/A char *pszOut = (char *)memchr(pErrInfo->pszMsg, '\0', pErrInfo->cbMsg - 2);
2N/A if (pszOut)
2N/A RTStrPrintfV(pszOut, &pErrInfo->pszMsg[pErrInfo->cbMsg] - pszOut, pszFormat, va);
2N/A }
2N/A else
2N/A {
2N/A while (*pszFormat == ' ')
2N/A pszFormat++;
2N/A return RTErrInfoSetV(pErrInfo, rc, pszFormat, va);
2N/A }
2N/A }
2N/A return rc;
2N/A}
2N/A
2N/A