ReactOS  0.4.15-dev-5499-g1341c38
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)
 

Function Documentation

◆ DuplicateQuotedString()

PWSTR DuplicateQuotedString ( _In_ PWSTR  pszInString)

Definition at line 84 of file misc.c.

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 }
uint16_t * PWSTR
Definition: typedefs.h:56
_In_ DWORD nLength
Definition: wincon.h:473
int32_t INT
Definition: typedefs.h:58
#define L(x)
Definition: ntvdm.h:50
#define UNICODE_NULL
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
#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)

◆ 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 }
uint16_t * PWSTR
Definition: typedefs.h:56
_In_ DWORD nLength
Definition: wincon.h:473
int32_t INT
Definition: typedefs.h:58
#define UNICODE_NULL
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
__wchar_t WCHAR
Definition: xmlstorage.h:180
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#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)

◆ 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 }
_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
int ret
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_In_ DWORD _In_ DWORD _Out_writes_to_opt_ pcchString LPSTR pszString
Definition: wincrypt.h:4505

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
uint16_t * PWSTR
Definition: typedefs.h:56
#define iswdigit(_c)
Definition: ctype.h:667
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
static PVOID ptr
Definition: dispmode.c:27
#define NULL
Definition: types.h:112

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 TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
#define iswxdigit(_c)
Definition: ctype.h:668
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
static PVOID ptr
Definition: dispmode.c:27
#define NULL
Definition: types.h:112

Referenced by 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:3044