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