VirtualBox

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

Last change on this file since 28303 was 28303, checked in by vboxsync, 15 years ago

Misc: made it possible to do: DEFS += RTMEM_WRAP_TO_EF_APIS RTALLOC_USE_EFENCE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: VBoxGuestR3LibRuntimeXF86.cpp 28303 2010-04-14 13:17:56Z 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 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
29 * Clara, CA 95054 USA or visit http://www.sun.com if you need
30 * additional information or have any questions.
31 */
32
33
34/****************************************************************************
35* Header Files *
36****************************************************************************/
37#include <iprt/assert.h>
38#include <iprt/log.h>
39#include <iprt/mem.h>
40#include <iprt/string.h>
41extern "C" {
42# define XFree86LOADER
43# include <xf86_ansic.h>
44# include <errno.h>
45# undef size_t
46}
47
48/* This is risky as it restricts call to the ANSI format type specifiers. */
49RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...)
50{
51 va_list args;
52 int cbRet;
53 va_start(args, pszFormat);
54 cbRet = xf86vsnprintf(pszBuffer, cchBuffer, pszFormat, args);
55 va_end(args);
56 return cbRet >= 0 ? cbRet : 0;
57}
58
59RTDECL(int) RTStrToUInt32Ex(const char *pszValue, char **ppszNext, unsigned uBase, uint32_t *pu32)
60{
61 char *pszNext = NULL;
62 xf86errno = 0;
63 unsigned long ul = xf86strtoul(pszValue, &pszNext, uBase);
64 if (ppszNext)
65 *ppszNext = pszNext;
66 if (RT_UNLIKELY(pszValue == pszNext))
67 return VERR_NO_DIGITS;
68 if (RT_UNLIKELY(ul > UINT32_MAX))
69 ul = UINT32_MAX;
70 if (pu32)
71 *pu32 = (uint32_t) ul;
72 if (RT_UNLIKELY(xf86errno == EINVAL))
73 return VERR_INVALID_PARAMETER;
74 if (RT_UNLIKELY(xf86errno == ERANGE))
75 return VWRN_NUMBER_TOO_BIG;
76 if (RT_UNLIKELY(xf86errno))
77 /* RTErrConvertFromErrno() is not available */
78 return VERR_UNRESOLVED_ERROR;
79 if (RT_UNLIKELY(*pszValue == '-'))
80 return VWRN_NEGATIVE_UNSIGNED;
81 if (RT_UNLIKELY(*pszNext))
82 {
83 while (*pszNext)
84 if (!xf86isspace(*pszNext))
85 return VWRN_TRAILING_CHARS;
86 return VWRN_TRAILING_SPACES;
87 }
88 return VINF_SUCCESS;
89}
90
91RTDECL(int) RTStrToUInt32Full(const char *pszValue, unsigned uBase, uint32_t *pu32)
92{
93 char *psz;
94 int rc = RTStrToUInt32Ex(pszValue, &psz, uBase, pu32);
95 if (RT_SUCCESS(rc) && *psz)
96 if (rc == VWRN_TRAILING_CHARS || rc == VWRN_TRAILING_SPACES)
97 rc = -rc;
98 return rc;
99}
100
101RTDECL(void) RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
102{
103 ErrorF("Assertion failed! Expression: %s at %s in\n", pszExpr,
104 pszFunction);
105 ErrorF("%s:%u\n", pszFile, uLine);
106}
107
108RTDECL(void) RTAssertMsg2Weak(const char *pszFormat, ...)
109{
110 va_list args;
111 va_start(args, pszFormat);
112 VErrorF(pszFormat, args);
113 va_end(args);
114}
115
116RTDECL(bool) RTAssertShouldPanic(void)
117{
118 return false;
119}
120
121RTDECL(PRTLOGGER) RTLogRelDefaultInstance(void)
122{
123 return NULL;
124}
125
126RTDECL(void) RTLogLoggerEx(PRTLOGGER, unsigned, unsigned, const char *pszFormat, ...)
127{
128 va_list args;
129 va_start(args, pszFormat);
130 VErrorF(pszFormat, args);
131 va_end(args);
132}
133
134RTDECL(void *) RTMemTmpAlloc(size_t cb)
135{
136 return xalloc(cb);
137}
138
139RTDECL(void) RTMemTmpFree(void *pv)
140{
141 xfree(pv);
142}
143
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