ReactOS 0.4.16-dev-1990-gfa5cf28
misc.c File Reference
#include "diskpart.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

BOOL IsDecString (_In_ PWSTR pszDecString)
 
BOOL IsHexString (_In_ PWSTR pszHexString)
 
BOOL HasPrefix (_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *ppszSuffix)
 
ULONGLONG RoundingDivide (_In_ ULONGLONG Dividend, _In_ ULONGLONG Divisor)
 
PWSTR DuplicateQuotedString (_In_ PWSTR pszInString)
 
PWSTR DuplicateString (_In_ PWSTR pszInString)
 
VOID CreateGUID (_Out_ GUID *pGuid)
 
VOID CreateSignature (_Out_ PDWORD pSignature)
 
VOID PrintGUID (_Out_ PWSTR pszBuffer, _In_ GUID *pGuid)
 
static BYTE CharToByte (WCHAR Char)
 
BOOL StringToGUID (_Out_ GUID *pGuid, _In_ PWSTR pszString)
 

Function Documentation

◆ CharToByte()

static BYTE CharToByte ( WCHAR  Char)
static

Definition at line 208 of file misc.c.

210{
211 if (iswdigit(Char))
212 {
213 return (BYTE)((INT)Char - (INT)'0');
214 }
215 else if (iswalpha(Char))
216 {
217 if (iswupper(Char))
218 return (INT)Char - ((INT)'A' - 10);
219 else
220 return (INT)Char - ((INT)'a' - 10);
221 }
222 return 0;
223}
#define iswupper(_c)
Definition: ctype.h:665
#define iswdigit(_c)
Definition: ctype.h:667
#define iswalpha(_c)
Definition: ctype.h:664
#define INT
Definition: polytest.cpp:20
int32_t INT
Definition: typedefs.h:58
unsigned char BYTE
Definition: xxhash.c:193

Referenced by StringToGUID().

◆ CreateGUID()

VOID CreateGUID ( _Out_ GUID pGuid)

Definition at line 152 of file misc.c.

154{
155 RtlGenRandom(pGuid, sizeof(*pGuid));
156 /* Clear the version bits and set the version (4) */
157 pGuid->Data3 &= 0x0fff;
158 pGuid->Data3 |= (4 << 12);
159 /* Set the topmost bits of Data4 (clock_seq_hi_and_reserved) as
160 * specified in RFC 4122, section 4.4.
161 */
162 pGuid->Data4[0] &= 0x3f;
163 pGuid->Data4[0] |= 0x80;
164}
#define RtlGenRandom
Definition: ntsecapi.h:691

Referenced by ConvertGPT(), and CreatePrimaryGptPartition().

◆ CreateSignature()

VOID CreateSignature ( _Out_ PDWORD  pSignature)

Definition at line 168 of file misc.c.

170{
171 LARGE_INTEGER SystemTime;
174
175 NtQuerySystemTime(&SystemTime);
176 RtlTimeToTimeFields(&SystemTime, &TimeFields);
177
178 Buffer = (PUCHAR)pSignature;
179 Buffer[0] = (UCHAR)(TimeFields.Year & 0xFF) + (UCHAR)(TimeFields.Hour & 0xFF);
180 Buffer[1] = (UCHAR)(TimeFields.Year >> 8) + (UCHAR)(TimeFields.Minute & 0xFF);
181 Buffer[2] = (UCHAR)(TimeFields.Month & 0xFF) + (UCHAR)(TimeFields.Second & 0xFF);
182 Buffer[3] = (UCHAR)(TimeFields.Day & 0xFF) + (UCHAR)(TimeFields.Milliseconds & 0xFF);
183}
Definition: bufpool.h:45
BOOLEAN RtlTimeToTimeFields(IN PLARGE_INTEGER Time, IN PTIME_FIELDS TimeFields)
static PTIME_FIELDS TimeFields
Definition: time.c:104
NTSTATUS NTAPI NtQuerySystemTime(OUT PLARGE_INTEGER SystemTime)
Definition: time.c:569
USHORT Milliseconds
Definition: env_spec_w32.h:717
unsigned char * PUCHAR
Definition: typedefs.h:53
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by ConvertMBR(), CreateExtendedPartition(), and CreatePrimaryPartition().

◆ DuplicateQuotedString()

PWSTR DuplicateQuotedString ( _In_ PWSTR  pszInString)

Definition at line 84 of file misc.c.

86{
87 PWSTR pszOutString = NULL;
88 PWSTR pStart, pEnd;
90
91 if ((pszInString == NULL) || (pszInString[0] == UNICODE_NULL))
92 return NULL;
93
94 if (pszInString[0] == L'"')
95 {
96 if (pszInString[1] == UNICODE_NULL)
97 return NULL;
98
99 pStart = &pszInString[1];
100 pEnd = wcschr(pStart, '"');
101 if (pEnd == NULL)
102 {
103 nLength = wcslen(pStart);
104 }
105 else
106 {
107 nLength = (pEnd - pStart);
108 }
109 }
110 else
111 {
112 pStart = pszInString;
113 nLength = wcslen(pStart);
114 }
115
116 pszOutString = RtlAllocateHeap(RtlGetProcessHeap(),
118 (nLength + 1) * sizeof(WCHAR));
119 if (pszOutString == NULL)
120 return NULL;
121
122 wcsncpy(pszOutString, pStart, nLength);
123
124 return pszOutString;
125}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
wcsncpy
#define NULL
Definition: types.h:112
#define wcschr
Definition: compat.h:17
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define L(x)
Definition: resources.c:13
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define UNICODE_NULL
uint16_t * PWSTR
Definition: typedefs.h:56
WINBASEAPI _In_ DWORD nLength
Definition: wincon.h:682
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ DuplicateString()

PWSTR DuplicateString ( _In_ PWSTR  pszInString)

Definition at line 129 of file misc.c.

131{
132 PWSTR pszOutString = NULL;
133 INT nLength;
134
135 if ((pszInString == NULL) || (pszInString[0] == UNICODE_NULL))
136 return NULL;
137
138 nLength = wcslen(pszInString);
139 pszOutString = RtlAllocateHeap(RtlGetProcessHeap(),
141 (nLength + 1) * sizeof(WCHAR));
142 if (pszOutString == NULL)
143 return NULL;
144
145 wcscpy(pszOutString, pszInString);
146
147 return pszOutString;
148}
wcscpy

◆ HasPrefix()

BOOL HasPrefix ( _In_ PWSTR  pszString,
_In_ PWSTR  pszPrefix,
_Out_opt_ PWSTR ppszSuffix 
)

Definition at line 58 of file misc.c.

62{
63 INT nPrefixLength, ret;
64
65 nPrefixLength = wcslen(pszPrefix);
66 ret = _wcsnicmp(pszString, pszPrefix, nPrefixLength);
67 if ((ret == 0) && (ppszSuffix != NULL))
68 *ppszSuffix = &pszString[nPrefixLength];
69
70 return (ret == 0);
71}
return ret
Definition: mutex.c:146
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
Definition: _wcsnicmp_nt.c:13

Referenced by AcpiExGetNameString(), CreateExtendedPartition(), CreateLogicalPartition(), CreatePrimaryPartition(), setid_main(), and UniqueIdDisk().

◆ IsDecString()

BOOL IsDecString ( _In_ PWSTR  pszDecString)

Definition at line 14 of file misc.c.

16{
17 PWSTR ptr;
18
19 if ((pszDecString == NULL) || (*pszDecString == UNICODE_NULL))
20 return FALSE;
21
22 ptr = pszDecString;
23 while (*ptr != UNICODE_NULL)
24 {
25 if (!iswdigit(*ptr))
26 return FALSE;
27
28 ptr++;
29 }
30
31 return TRUE;
32}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static PVOID ptr
Definition: dispmode.c:27

Referenced by SelectDisk(), SelectPartition(), and SelectVolume().

◆ IsHexString()

BOOL IsHexString ( _In_ PWSTR  pszHexString)

Definition at line 36 of file misc.c.

38{
39 PWSTR ptr;
40
41 if ((pszHexString == NULL) || (*pszHexString == UNICODE_NULL))
42 return FALSE;
43
44 ptr = pszHexString;
45 while (*ptr != UNICODE_NULL)
46 {
47 if (!iswxdigit(*ptr))
48 return FALSE;
49
50 ptr++;
51 }
52
53 return TRUE;
54}
#define iswxdigit(_c)
Definition: ctype.h:668

Referenced by UniqueIdDisk().

◆ PrintGUID()

VOID PrintGUID ( _Out_ PWSTR  pszBuffer,
_In_ GUID pGuid 
)

Definition at line 187 of file misc.c.

190{
191 swprintf(pszBuffer,
192 L"%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
193 pGuid->Data1,
194 pGuid->Data2,
195 pGuid->Data3,
196 pGuid->Data4[0],
197 pGuid->Data4[1],
198 pGuid->Data4[2],
199 pGuid->Data4[3],
200 pGuid->Data4[4],
201 pGuid->Data4[5],
202 pGuid->Data4[6],
203 pGuid->Data4[7]);
204}
#define swprintf
Definition: precomp.h:40

Referenced by DetailDisk(), DetailPartition(), and UniqueIdDisk().

◆ RoundingDivide()

ULONGLONG RoundingDivide ( _In_ ULONGLONG  Dividend,
_In_ ULONGLONG  Divisor 
)

Definition at line 75 of file misc.c.

78{
79 return (Dividend + Divisor / 2) / Divisor;
80}
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3061

◆ StringToGUID()

BOOL StringToGUID ( _Out_ GUID pGuid,
_In_ PWSTR  pszString 
)

Definition at line 227 of file misc.c.

230{
231 INT i;
232
233 if (pszString == NULL)
234 return FALSE;
235
236 pGuid->Data1 = 0;
237 for (i = 0; i < 8; i++)
238 {
239 if (!iswxdigit(pszString[i]))
240 return FALSE;
241
242 pGuid->Data1 = (pGuid->Data1 << 4) | CharToByte(pszString[i]);
243 }
244
245 if (pszString[8] != L'-')
246 return FALSE;
247
248 pGuid->Data2 = 0;
249 for (i = 9; i < 13; i++)
250 {
251 if (!iswxdigit(pszString[i]))
252 return FALSE;
253
254 pGuid->Data2 = (pGuid->Data2 << 4) | CharToByte(pszString[i]);
255 }
256
257 if (pszString[13] != L'-')
258 return FALSE;
259
260 pGuid->Data3 = 0;
261 for (i = 14; i < 18; i++)
262 {
263 if (!iswxdigit(pszString[i]))
264 return FALSE;
265
266 pGuid->Data3 = (pGuid->Data3 << 4) | CharToByte(pszString[i]);
267 }
268
269 if (pszString[18] != L'-')
270 return FALSE;
271
272 for (i = 19; i < 36; i += 2)
273 {
274 if (i == 23)
275 {
276 if (pszString[i] != L'-')
277 return FALSE;
278 i++;
279 }
280
281 if (!iswxdigit(pszString[i]) || !iswxdigit(pszString[i + 1]))
282 return FALSE;
283
284 pGuid->Data4[(i - 19) / 2] = CharToByte(pszString[i]) << 4 | CharToByte(pszString[i + 1]);
285 }
286
287 if (pszString[36] == L'\0')
288 return TRUE;
289
290 return FALSE;
291}
static BYTE CharToByte(WCHAR Char)
Definition: misc.c:208
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

Referenced by CreatePrimaryGptPartition(), setid_main(), and UniqueIdDisk().