ReactOS  0.4.15-dev-5112-g22d8c0f
misc.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS DiskPart
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: base/system/diskpart/misc.c
5  * PURPOSE: Manages all the partitions of the OS in an interactive way.
6  * PROGRAMMERS: Eric Kohl
7  */
8 
9 #include "diskpart.h"
10 
11 /* FUNCTIONS ******************************************************************/
12 
13 BOOL
15  _In_ PWSTR pszDecString)
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 }
33 
34 
35 BOOL
37  _In_ PWSTR pszHexString)
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 }
55 
56 
57 BOOL
60  _In_ PWSTR pszPrefix,
61  _Out_opt_ PWSTR *ppszSuffix)
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 }
72 
73 
76  _In_ ULONGLONG Dividend,
78 {
79  return (Dividend + Divisor / 2) / Divisor;
80 }
81 
82 
83 PWSTR
85  _In_ PWSTR pszInString)
86 {
87  PWSTR pszOutString = NULL;
88  PWSTR pStart, pEnd;
89  INT nLength;
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 }
126 
127 
128 PWSTR
130  _In_ PWSTR pszInString)
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 }
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
#define iswxdigit(_c)
Definition: ctype.h:668
#define iswdigit(_c)
Definition: ctype.h:667
ULONGLONG RoundingDivide(_In_ ULONGLONG Dividend, _In_ ULONGLONG Divisor)
Definition: misc.c:75
_In_ DWORD nLength
Definition: wincon.h:473
_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)
int32_t INT
Definition: typedefs.h:58
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
static PVOID ptr
Definition: dispmode.c:27
#define _In_
Definition: ms_sal.h:308
BOOL HasPrefix(_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *ppszSuffix)
Definition: misc.c:58
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
BOOL IsHexString(_In_ PWSTR pszHexString)
Definition: misc.c:36
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
PWSTR DuplicateQuotedString(_In_ PWSTR pszInString)
Definition: misc.c:84
uint64_t ULONGLONG
Definition: typedefs.h:67
int ret
PWSTR DuplicateString(_In_ PWSTR pszInString)
Definition: misc.c:129
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#define _Out_opt_
Definition: ms_sal.h:346
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOL IsDecString(_In_ PWSTR pszDecString)
Definition: misc.c:14
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3044
_In_ DWORD _In_ DWORD _Out_writes_to_opt_ pcchString LPSTR pszString
Definition: wincrypt.h:4505