VirtualBox

source: vbox/trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibRuntimeXF86.cpp@ 44824

Last change on this file since 44824 was 31159, checked in by vboxsync, 14 years ago

iprt,++: Tag allocation in all builds with a string, defaulting to FILE.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: VBoxGuestR3LibRuntimeXF86.cpp 31159 2010-07-28 03:28:00Z vboxsync $ */
2/** @file
3 * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions,
4 * implements the minimum of runtime functions needed for
5 * XFree86 driver code.
6 */
7
8/*
9 * Copyright (C) 2007-2010 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * The contents of this file may alternatively be used under the terms
20 * of the Common Development and Distribution License Version 1.0
21 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
22 * VirtualBox OSE distribution, in which case the provisions of the
23 * CDDL are applicable instead of those of the GPL.
24 *
25 * You may elect to license modified versions of this file under the
26 * terms and conditions of either the GPL or the CDDL or both.
27 */
28
29
30/****************************************************************************
31* Header Files *
32****************************************************************************/
33#include <iprt/assert.h>
34#include <iprt/log.h>
35#include <iprt/mem.h>
36#include <iprt/string.h>
37extern "C" {
38# define XFree86LOADER
39# include <xf86_ansic.h>
40# include <errno.h>
41# undef size_t
42}
43
44/* This is risky as it restricts call to the ANSI format type specifiers. */
45RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...)
46{
47 va_list args;
48 int cbRet;
49 va_start(args, pszFormat);
50 cbRet = xf86vsnprintf(pszBuffer, cchBuffer, pszFormat, args);
51 va_end(args);
52 return cbRet >= 0 ? cbRet : 0;
53}
54
55RTDECL(int) RTStrToUInt32Ex(const char *pszValue, char **ppszNext, unsigned uBase, uint32_t *pu32)
56{
57 char *pszNext = NULL;
58 xf86errno = 0;
59 unsigned long ul = xf86strtoul(pszValue, &pszNext, uBase);
60 if (ppszNext)
61 *ppszNext = pszNext;
62 if (RT_UNLIKELY(pszValue == pszNext))
63 return VERR_NO_DIGITS;
64 if (RT_UNLIKELY(ul > UINT32_MAX))
65 ul = UINT32_MAX;
66 if (pu32)
67 *pu32 = (uint32_t) ul;
68 if (RT_UNLIKELY(xf86errno == EINVAL))
69 return VERR_INVALID_PARAMETER;
70 if (RT_UNLIKELY(xf86errno == ERANGE))
71 return VWRN_NUMBER_TOO_BIG;
72 if (RT_UNLIKELY(xf86errno))
73 /* RTErrConvertFromErrno() is not available */
74 return VERR_UNRESOLVED_ERROR;
75 if (RT_UNLIKELY(*pszValue == '-'))
76 return VWRN_NEGATIVE_UNSIGNED;
77 if (RT_UNLIKELY(*pszNext))
78 {
79 while (*pszNext)
80 if (!xf86isspace(*pszNext))
81 return VWRN_TRAILING_CHARS;
82 return VWRN_TRAILING_SPACES;
83 }
84 return VINF_SUCCESS;
85}
86
87RTDECL(int) RTStrToUInt32Full(const char *pszValue, unsigned uBase, uint32_t *pu32)
88{
89 char *psz;
90 int rc = RTStrToUInt32Ex(pszValue, &psz, uBase, pu32);
91 if (RT_SUCCESS(rc) && *psz)
92 if (rc == VWRN_TRAILING_CHARS || rc == VWRN_TRAILING_SPACES)
93 rc = -rc;
94 return rc;
95}
96
97RTDECL(void) RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
98{
99 ErrorF("Assertion failed! Expression: %s at %s in\n", pszExpr,
100 pszFunction);
101 ErrorF("%s:%u\n", pszFile, uLine);
102}
103
104RTDECL(void) RTAssertMsg2Weak(const char *pszFormat, ...)
105{
106 va_list args;
107 va_start(args, pszFormat);
108 VErrorF(pszFormat, args);
109 va_end(args);
110}
111
112RTDECL(bool) RTAssertShouldPanic(void)
113{
114 return false;
115}
116
117RTDECL(PRTLOGGER) RTLogRelDefaultInstance(void)
118{
119 return NULL;
120}
121
122RTDECL(void) RTLogLoggerEx(PRTLOGGER, unsigned, unsigned, const char *pszFormat, ...)
123{
124 va_list args;
125 va_start(args, pszFormat);
126 VErrorF(pszFormat, args);
127 va_end(args);
128}
129
130RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag)
131{
132 NOREF(pszTag);
133 return xalloc(cb);
134}
135
136RTDECL(void) RTMemTmpFree(void *pv)
137{
138 xfree(pv);
139}
140
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