VirtualBox

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

Last change on this file since 53402 was 52210, checked in by vboxsync, 11 years ago

Additions/x11: do not pull the whole (mini) run-time library into the X.Org drivers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: VBoxGuestR3LibRuntimeXF86.cpp 52210 2014-07-28 15:03:24Z 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>
37#if defined(VBOX_VBGLR3_XFREE86)
38extern "C" {
39# define XFree86LOADER
40# include <xf86_ansic.h>
41# include <errno.h>
42# undef size_t
43}
44#else
45# include <ctype.h>
46# include <errno.h>
47# include <stdarg.h>
48# include <stdio.h>
49# include <stdlib.h>
50# define xalloc malloc
51# define xf86vsnprintf vsnprintf
52# define xf86errno errno
53# define xf86strtoul strtoul
54# define xf86isspace isspace
55# define xfree free
56extern "C" void ErrorF(const char *f, ...);
57extern "C" void VErrorF(const char *f, va_list args);
58#endif
59
60/* This is risky as it restricts call to the ANSI format type specifiers. */
61RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...)
62{
63 va_list args;
64 int cbRet;
65 va_start(args, pszFormat);
66 cbRet = xf86vsnprintf(pszBuffer, cchBuffer, pszFormat, args);
67 va_end(args);
68 return cbRet >= 0 ? cbRet : 0;
69}
70
71RTDECL(int) RTStrToUInt32Ex(const char *pszValue, char **ppszNext, unsigned uBase, uint32_t *pu32)
72{
73 char *pszNext = NULL;
74 xf86errno = 0;
75 unsigned long ul = xf86strtoul(pszValue, &pszNext, uBase);
76 if (ppszNext)
77 *ppszNext = pszNext;
78 if (RT_UNLIKELY(pszValue == pszNext))
79 return VERR_NO_DIGITS;
80 if (RT_UNLIKELY(ul > UINT32_MAX))
81 ul = UINT32_MAX;
82 if (pu32)
83 *pu32 = (uint32_t) ul;
84 if (RT_UNLIKELY(xf86errno == EINVAL))
85 return VERR_INVALID_PARAMETER;
86 if (RT_UNLIKELY(xf86errno == ERANGE))
87 return VWRN_NUMBER_TOO_BIG;
88 if (RT_UNLIKELY(xf86errno))
89 /* RTErrConvertFromErrno() is not available */
90 return VERR_UNRESOLVED_ERROR;
91 if (RT_UNLIKELY(*pszValue == '-'))
92 return VWRN_NEGATIVE_UNSIGNED;
93 if (RT_UNLIKELY(*pszNext))
94 {
95 while (*pszNext)
96 if (!xf86isspace(*pszNext))
97 return VWRN_TRAILING_CHARS;
98 return VWRN_TRAILING_SPACES;
99 }
100 return VINF_SUCCESS;
101}
102
103RTDECL(int) RTStrToUInt32Full(const char *pszValue, unsigned uBase, uint32_t *pu32)
104{
105 char *psz;
106 int rc = RTStrToUInt32Ex(pszValue, &psz, uBase, pu32);
107 if (RT_SUCCESS(rc) && *psz)
108 if (rc == VWRN_TRAILING_CHARS || rc == VWRN_TRAILING_SPACES)
109 rc = -rc;
110 return rc;
111}
112
113RTDECL(void) RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
114{
115 ErrorF("Assertion failed! Expression: %s at %s in\n", pszExpr,
116 pszFunction);
117 ErrorF("%s:%u\n", pszFile, uLine);
118}
119
120RTDECL(void) RTAssertMsg2Weak(const char *pszFormat, ...)
121{
122 va_list args;
123 va_start(args, pszFormat);
124 VErrorF(pszFormat, args);
125 va_end(args);
126}
127
128RTDECL(bool) RTAssertShouldPanic(void)
129{
130 return false;
131}
132
133RTDECL(PRTLOGGER) RTLogRelDefaultInstance(void)
134{
135 return NULL;
136}
137
138RTDECL(void) RTLogLoggerEx(PRTLOGGER, unsigned, unsigned, const char *pszFormat, ...)
139{
140 va_list args;
141 va_start(args, pszFormat);
142 VErrorF(pszFormat, args);
143 va_end(args);
144}
145
146RTDECL(void *) RTMemTmpAllocTag(size_t cb, const char *pszTag)
147{
148 NOREF(pszTag);
149 return xalloc(cb);
150}
151
152RTDECL(void) RTMemTmpFree(void *pv)
153{
154 xfree(pv);
155}
156
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette