1 | /* $Id: VBoxGuestR3LibRuntimeXF86.cpp 27687 2010-03-24 22:14:20Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions,
|
---|
4 | * implements the minimum of runtime functions needed for XFree86 driver
|
---|
5 | * code.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2007-2009 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>
|
---|
41 | extern "C" {
|
---|
42 | # define XFree86LOADER
|
---|
43 | # include <xf86_ansic.h>
|
---|
44 | # include <errno.h>
|
---|
45 | # undef size_t
|
---|
46 | }
|
---|
47 |
|
---|
48 | RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...)
|
---|
49 | {
|
---|
50 | va_list args;
|
---|
51 | int cbRet;
|
---|
52 | va_start(args, pszFormat);
|
---|
53 | cbRet = xf86vsnprintf(pszBuffer, cchBuffer, pszFormat, args);
|
---|
54 | va_end(args);
|
---|
55 | return cbRet >= 0 ? cbRet : 0;
|
---|
56 | }
|
---|
57 |
|
---|
58 | RTDECL(int) RTStrToUInt32Ex(const char *pszValue, char **ppszNext, unsigned uBase, uint32_t *pu32)
|
---|
59 | {
|
---|
60 | char *pszNext = NULL;
|
---|
61 | xf86errno = 0;
|
---|
62 | unsigned long ul = xf86strtoul(pszValue, &pszNext, uBase);
|
---|
63 | if (ppszNext)
|
---|
64 | *ppszNext = pszNext;
|
---|
65 | if (RT_UNLIKELY(pszValue == pszNext))
|
---|
66 | return VERR_NO_DIGITS;
|
---|
67 | if (RT_UNLIKELY(ul > UINT32_MAX))
|
---|
68 | ul = UINT32_MAX;
|
---|
69 | if (pu32)
|
---|
70 | *pu32 = (uint32_t) ul;
|
---|
71 | if (RT_UNLIKELY(xf86errno == EINVAL))
|
---|
72 | return VERR_INVALID_PARAMETER;
|
---|
73 | if (RT_UNLIKELY(xf86errno == ERANGE))
|
---|
74 | return VWRN_NUMBER_TOO_BIG;
|
---|
75 | if (RT_UNLIKELY(xf86errno))
|
---|
76 | /* RTErrConvertFromErrno() is not available */
|
---|
77 | return VERR_UNRESOLVED_ERROR;
|
---|
78 | if (RT_UNLIKELY(*pszValue == '-'))
|
---|
79 | return VWRN_NEGATIVE_UNSIGNED;
|
---|
80 | if (RT_UNLIKELY(*pszNext))
|
---|
81 | {
|
---|
82 | while (*pszNext)
|
---|
83 | if (!xf86isspace(*pszNext))
|
---|
84 | return VWRN_TRAILING_CHARS;
|
---|
85 | return VWRN_TRAILING_SPACES;
|
---|
86 | }
|
---|
87 | return VINF_SUCCESS;
|
---|
88 | }
|
---|
89 |
|
---|
90 | RTDECL(int) RTStrToUInt32Full(const char *pszValue, unsigned uBase, uint32_t *pu32)
|
---|
91 | {
|
---|
92 | char *psz;
|
---|
93 | int rc = RTStrToUInt32Ex(pszValue, &psz, uBase, pu32);
|
---|
94 | if (RT_SUCCESS(rc) && *psz)
|
---|
95 | if (rc == VWRN_TRAILING_CHARS || rc == VWRN_TRAILING_SPACES)
|
---|
96 | rc = -rc;
|
---|
97 | return rc;
|
---|
98 | }
|
---|
99 |
|
---|
100 | RTDECL(void) RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
|
---|
101 | {
|
---|
102 | ErrorF("Assertion failed! Expression: %s at %s in\n", pszExpr,
|
---|
103 | pszFunction);
|
---|
104 | ErrorF("%s:%u\n", pszFile, uLine);
|
---|
105 | }
|
---|
106 |
|
---|
107 | RTDECL(void) RTAssertMsg2Weak(const char *pszFormat, ...)
|
---|
108 | {
|
---|
109 | va_list args;
|
---|
110 | va_start(args, pszFormat);
|
---|
111 | VErrorF(pszFormat, args);
|
---|
112 | va_end(args);
|
---|
113 | }
|
---|
114 |
|
---|
115 | RTDECL(bool) RTAssertShouldPanic(void)
|
---|
116 | {
|
---|
117 | return false;
|
---|
118 | }
|
---|
119 |
|
---|
120 | RTDECL(PRTLOGGER) RTLogRelDefaultInstance(void)
|
---|
121 | {
|
---|
122 | return NULL;
|
---|
123 | }
|
---|
124 |
|
---|
125 | RTDECL(void) RTLogLoggerEx(PRTLOGGER, unsigned, unsigned, const char *pszFormat, ...)
|
---|
126 | {
|
---|
127 | va_list args;
|
---|
128 | va_start(args, pszFormat);
|
---|
129 | VErrorF(pszFormat, args);
|
---|
130 | va_end(args);
|
---|
131 | }
|
---|
132 |
|
---|
133 | RTDECL(void *) RTMemTmpAlloc(size_t cb)
|
---|
134 | {
|
---|
135 | return xalloc(cb);
|
---|
136 | }
|
---|
137 |
|
---|
138 | RTDECL(void) RTMemTmpFree(void *pv)
|
---|
139 | {
|
---|
140 | xfree(pv);
|
---|
141 | }
|
---|