ReactOS  0.4.14-dev-114-gc8cbd56
infhostrtl.c File Reference
#include "inflib.h"
#include "infhost.h"
#include <debug.h>
Include dependency graph for infhostrtl.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI RtlMultiByteToUnicodeN (IN PWCHAR UnicodeString, IN ULONG UnicodeSize, IN PULONG ResultSize, IN PCSTR MbString, IN ULONG MbSize)
 
BOOLEAN NTAPI RtlIsTextUnicode (PVOID buf, INT len, INT *pf)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file infhostrtl.c.

Function Documentation

◆ RtlIsTextUnicode()

BOOLEAN NTAPI RtlIsTextUnicode ( PVOID  buf,
INT  len,
INT pf 
)

Definition at line 51 of file infhostrtl.c.

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 }
#define TRUE
Definition: types.h:120
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
WINE_UNICODE_INLINE WCHAR * strchrW(const WCHAR *str, WCHAR ch)
Definition: unicode.h:248
#define IS_TEXT_UNICODE_NOT_ASCII_MASK
Definition: winnt_old.h:934
#define INT
Definition: polytest.cpp:20
#define IS_TEXT_UNICODE_SIGNATURE
Definition: winnt_old.h:925
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
#define IS_TEXT_UNICODE_STATISTICS
Definition: winnt_old.h:921
#define IS_TEXT_UNICODE_REVERSE_SIGNATURE
Definition: winnt_old.h:926
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IS_TEXT_UNICODE_ODD_LENGTH
Definition: winnt_old.h:928
GLbitfield flags
Definition: glext.h:7161
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
#define IS_TEXT_UNICODE_REVERSE_CONTROLS
Definition: winnt_old.h:924
#define IS_TEXT_UNICODE_CONTROLS
Definition: winnt_old.h:923
#define MAXULONG
Definition: typedefs.h:250
#define IS_TEXT_UNICODE_REVERSE_MASK
Definition: winnt_old.h:932
#define IS_TEXT_UNICODE_NULL_BYTES
Definition: winnt_old.h:930
#define IS_TEXT_UNICODE_UNICODE_MASK
Definition: winnt_old.h:931
#define IS_TEXT_UNICODE_NOT_UNICODE_MASK
Definition: winnt_old.h:933
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

◆ RtlMultiByteToUnicodeN()

NTSTATUS NTAPI RtlMultiByteToUnicodeN ( IN PWCHAR  UnicodeString,
IN ULONG  UnicodeSize,
IN PULONG  ResultSize,
IN PCSTR  MbString,
IN ULONG  MbSize 
)

Definition at line 18 of file infhostrtl.c.

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 }
unsigned char * PUCHAR
Definition: retypes.h:3
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
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char UCHAR
Definition: xmlstorage.h:181
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966