ReactOS 0.4.15-dev-7918-g2a2556c
infhostrtl.c
Go to the documentation of this file.
1/*
2 * PROJECT: .inf file parser
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PROGRAMMER: Royce Mitchell III
5 * Eric Kohl
6 * Ge van Geldorp <gvg@reactos.org>
7 */
8
9/* INCLUDES *****************************************************************/
10
11#include "inflib.h"
12#include "infhost.h"
13
14#define NDEBUG
15#include <debug.h>
16
20 IN ULONG UnicodeSize,
21 IN PULONG ResultSize,
22 IN PCSTR MbString,
23 IN ULONG MbSize)
24{
25 ULONG Size = 0;
26 ULONG i;
27 PUCHAR WideString;
28
29 /* single-byte code page */
30 if (MbSize > (UnicodeSize / sizeof(WCHAR)))
31 Size = UnicodeSize / sizeof(WCHAR);
32 else
33 Size = MbSize;
34
35 if (ResultSize != NULL)
36 *ResultSize = Size * sizeof(WCHAR);
37
38 WideString = (PUCHAR)UnicodeString;
39 for (i = 0; i < Size; i++)
40 {
41 WideString[2 * i + 0] = (UCHAR)MbString[i];
42 WideString[2 * i + 1] = 0;
43 }
44
45 return STATUS_SUCCESS;
46}
47
48
52{
53 static const WCHAR std_control_chars[] = {'\r','\n','\t',' ',0x3000,0};
54 static const WCHAR byterev_control_chars[] = {0x0d00,0x0a00,0x0900,0x2000,0};
55 const WCHAR *s = buf;
56 int i;
57 unsigned int flags = MAXULONG, out_flags = 0;
58
59 if (len < sizeof(WCHAR))
60 {
61 /* FIXME: MSDN documents IS_TEXT_UNICODE_BUFFER_TOO_SMALL but there is no such thing... */
62 if (pf) *pf = 0;
63 return FALSE;
64 }
65 if (pf)
66 flags = (unsigned int)*pf;
67 /*
68 * Apply various tests to the text string. According to the
69 * docs, each test "passed" sets the corresponding flag in
70 * the output flags. But some of the tests are mutually
71 * exclusive, so I don't see how you could pass all tests ...
72 */
73
74 /* Check for an odd length ... pass if even. */
75 if (len & 1) out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
76
77 if (((char *)buf)[len - 1] == 0)
78 len--; /* Windows seems to do something like that to avoid e.g. false IS_TEXT_UNICODE_NULL_BYTES */
79
80 len /= (INT)sizeof(WCHAR);
81 /* Windows only checks the first 256 characters */
82 if (len > 256) len = 256;
83
84 /* Check for the special byte order unicode marks. */
85 if (*s == 0xFEFF) out_flags |= IS_TEXT_UNICODE_SIGNATURE;
86 if (*s == 0xFFFE) out_flags |= IS_TEXT_UNICODE_REVERSE_SIGNATURE;
87
88 /* apply some statistical analysis */
90 {
91 int stats = 0;
92 /* FIXME: checks only for ASCII characters in the unicode stream */
93 for (i = 0; i < len; i++)
94 {
95 if (s[i] <= 255) stats++;
96 }
97 if (stats > len / 2)
98 out_flags |= IS_TEXT_UNICODE_STATISTICS;
99 }
100
101 /* Check for unicode NULL chars */
103 {
104 for (i = 0; i < len; i++)
105 {
106 if (!(s[i] & 0xff) || !(s[i] >> 8))
107 {
108 out_flags |= IS_TEXT_UNICODE_NULL_BYTES;
109 break;
110 }
111 }
112 }
113
115 {
116 for (i = 0; i < len; i++)
117 {
118 if (strchrW(std_control_chars, s[i]))
119 {
120 out_flags |= IS_TEXT_UNICODE_CONTROLS;
121 break;
122 }
123 }
124 }
125
127 {
128 for (i = 0; i < len; i++)
129 {
130 if (strchrW(byterev_control_chars, s[i]))
131 {
133 break;
134 }
135 }
136 }
137
138 if (pf)
139 {
140 out_flags &= (unsigned int)*pf;
141 *pf = (INT)out_flags;
142 }
143 /* check for flags that indicate it's definitely not valid Unicode */
145 /* now check for invalid ASCII, and assume Unicode if so */
146 if (out_flags & IS_TEXT_UNICODE_NOT_ASCII_MASK) return TRUE;
147 /* now check for Unicode flags */
148 if (out_flags & IS_TEXT_UNICODE_UNICODE_MASK) return TRUE;
149 /* no flags set */
150 return FALSE;
151}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLdouble s
Definition: gl.h:2039
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS NTAPI RtlMultiByteToUnicodeN(IN PWCHAR UnicodeString, IN ULONG UnicodeSize, IN PULONG ResultSize, IN PCSTR MbString, IN ULONG MbSize)
Definition: infhostrtl.c:18
BOOLEAN NTAPI RtlIsTextUnicode(PVOID buf, INT len, INT *pf)
Definition: infhostrtl.c:51
#define INT
Definition: polytest.cpp:20
#define strchrW(s, c)
Definition: unicode.h:34
#define STATUS_SUCCESS
Definition: shellext.h:65
#define MAXULONG
Definition: typedefs.h:251
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
int32_t INT
Definition: typedefs.h:58
const char * PCSTR
Definition: typedefs.h:52
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define IS_TEXT_UNICODE_UNICODE_MASK
Definition: winnt_old.h:898
#define IS_TEXT_UNICODE_NOT_ASCII_MASK
Definition: winnt_old.h:901
#define IS_TEXT_UNICODE_NULL_BYTES
Definition: winnt_old.h:897
#define IS_TEXT_UNICODE_REVERSE_CONTROLS
Definition: winnt_old.h:891
#define IS_TEXT_UNICODE_REVERSE_MASK
Definition: winnt_old.h:899
#define IS_TEXT_UNICODE_CONTROLS
Definition: winnt_old.h:890
#define IS_TEXT_UNICODE_ODD_LENGTH
Definition: winnt_old.h:895
#define IS_TEXT_UNICODE_REVERSE_SIGNATURE
Definition: winnt_old.h:893
#define IS_TEXT_UNICODE_NOT_UNICODE_MASK
Definition: winnt_old.h:900
#define IS_TEXT_UNICODE_STATISTICS
Definition: winnt_old.h:888
#define IS_TEXT_UNICODE_SIGNATURE
Definition: winnt_old.h:892
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180