ReactOS  0.4.13-dev-52-g0efcfec
string_lib.cpp
Go to the documentation of this file.
1 // Copyright (C) Alexander Telyatnikov, Ivan Keliukh, Yegor Anchishkin, SKIF Software, 1999-2013. Kiev, Ukraine
3 // All rights reserved
4 // This file was released under the GPLv2 on June 2015.
6 
7 extern "C"
8 ULONG
10  PVOID s1,
11  PVOID s2,
12  ULONG len
13  )
14 {
15  ULONG i;
16 
17  for(i=0; i<len; i++) {
18  if( ((char*)s1)[i] != ((char*)s2)[i] )
19  break;
20  }
21  return i;
22 }
23 
24 #define STRING_BUFFER_ALIGNMENT (32)
25 #define STRING_BUFFER_ALIGN(sz) (((sz)+STRING_BUFFER_ALIGNMENT)&(~((ULONG)(STRING_BUFFER_ALIGNMENT-1))))
26 
27 #ifndef NT_NATIVE_MODE
28 
29 extern "C"
30 ULONG
34  BOOLEAN UpCase
35  )
36 {
37  ULONG i;
38 
39  if(s1->Length != s2->Length) return (-1);
40  i = memcmp(s1->Buffer, s2->Buffer, (s1->Length) ? (s1->Length) : (s2->Length));
41  return i;
42 }
43 
44 extern "C"
50  )
51 {
52 // if(s1->Length != s2->Length) return (-1);
53  memcpy(dst->Buffer, src->Buffer, src->Length);
54  dst->Buffer[src->Length/sizeof(WCHAR)] = 0;
55  dst->Length = src->Length;
56  _wcsupr(dst->Buffer);
57  return STATUS_SUCCESS;
58 }
59 
60 extern "C"
63  IN PUNICODE_STRING Str1,
64  IN PWSTR Str2
65  )
66 {
67  PWCHAR tmp;
68  USHORT i;
69 
70 #ifdef _X86_
71 
72  __asm push ebx
73  __asm push esi
74  __asm xor ebx,ebx
75  __asm mov esi,Str2
76 Scan_1:
77  __asm cmp [word ptr esi+ebx],0
78  __asm je EO_Scan
79  __asm add ebx,2
80  __asm jmp Scan_1
81 EO_Scan:
82  __asm mov i,bx
83  __asm pop esi
84  __asm pop ebx
85 
86 #else // NO X86 optimization, use generic C/C++
87 
88  i=0;
89  while(Str2[i]) {
90  i++;
91  }
92  i *= sizeof(WCHAR);
93 
94 #endif // _X86_
95 
96  tmp = Str1->Buffer;
97  ASSERT(Str1->MaximumLength);
98  if((Str1->Length+i+sizeof(WCHAR)) > Str1->MaximumLength) {
99  PWCHAR tmp2 = (PWCHAR)ExAllocatePoolWithTag(NonPagedPool, STRING_BUFFER_ALIGN(i + Str1->Length + sizeof(WCHAR))*2, 'ilTS');
100  if(!tmp2)
102  memcpy(tmp2, tmp, Str1->MaximumLength);
103  ExFreePool(tmp);
104  tmp = tmp2;
105  Str1->MaximumLength = STRING_BUFFER_ALIGN(i + sizeof(WCHAR))*2;
106  Str1->Buffer = tmp;
107  }
108  RtlCopyMemory(((PCHAR)tmp)+Str1->Length, Str2, i);
109  i+=Str1->Length;
110  tmp[(i / sizeof(WCHAR))] = 0;
111  Str1->Length = i;
112 
113  return STATUS_SUCCESS;
114 
115 #undef UDF_UNC_STR_TAG
116 
117 } // end RtlAppendUnicodeToString()
118 
119 #endif //NT_NATIVE_MODE
120 
121 #ifdef CDRW_W32
122 NTSTATUS
124  IN PUNICODE_STRING Str1,
125  IN PCWSTR Str2
126  )
127 {
128 
129  USHORT i;
130 
131 #ifdef _X86_
132 
133  __asm push ebx
134  __asm push esi
135  __asm xor ebx,ebx
136  __asm mov esi,Str2
137 Scan_1:
138  __asm cmp [word ptr esi+ebx],0
139  __asm je EO_Scan
140  __asm add ebx,2
141  __asm jmp Scan_1
142 EO_Scan:
143  __asm mov i,bx
144  __asm pop esi
145  __asm pop ebx
146 
147 #else // NO X86 optimization, use generic C/C++
148 
149  i=0;
150  while(Str2[i]) {
151  i++;
152  }
153  i *= sizeof(WCHAR);
154 
155 #endif // _X86_
156 
157  Str1->MaximumLength = STRING_BUFFER_ALIGN((Str1->Length = i) + sizeof(WCHAR));
158  Str1->Buffer = (PWCHAR)MyAllocatePool__(NonPagedPool, Str1->MaximumLength);
159  if(!Str1->Buffer)
161  RtlCopyMemory(Str1->Buffer, Str2, i);
162  Str1->Buffer[i/sizeof(WCHAR)] = 0;
163  return STATUS_SUCCESS;
164 
165 } // end MyInitUnicodeString()
166 #endif //CDRW_W32
signed char * PCHAR
Definition: retypes.h:7
int add
Definition: i386-dis.c:3122
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define IN
Definition: typedefs.h:38
struct S2 s2
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static void xor(unsigned char *dst, const unsigned char *a, const unsigned char *b, const int count)
Definition: crypt_des.c:251
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx eax jnz xchgl ecx incl TEMP esi
Definition: synth_sse3d.h:103
uint16_t * PWSTR
Definition: typedefs.h:54
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:54
#define cmp(status, error)
Definition: error.c:114
static calc_node_t * pop(void)
Definition: rpn_ieee.c:90
NTSTATUS MyInitUnicodeString(IN PUNICODE_STRING Str1, IN PCWSTR Str2)
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
static PVOID ptr
Definition: dispmode.c:27
unsigned char BOOLEAN
ULONG MyRtlCompareMemory(PVOID s1, PVOID s2, ULONG len)
Definition: string_lib.cpp:9
_CRTIMP wchar_t *__cdecl _wcsupr(_Inout_z_ wchar_t *_String)
#define MyAllocatePool__(type, size)
Definition: mem_tools.h:149
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct S1 s1
PVOID Alloc(IN DWORD dwFlags, IN SIZE_T dwBytes)
Definition: main.c:63
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl ebx
Definition: synth_sse3d.h:83
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
GLenum src
Definition: glext.h:6340
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
unsigned short USHORT
Definition: pedump.c:61
GLenum GLenum dst
Definition: glext.h:6340
const WCHAR * word
Definition: lex.c:78
#define STRING_BUFFER_ALIGN(sz)
Definition: string_lib.cpp:25
unsigned int ULONG
Definition: retypes.h:1
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
static void push(calc_node_t *op)
Definition: rpn_ieee.c:113
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
jmp_buf jmp
Definition: mach.c:36