2 * PROJECT: ReactOS Floppy Disk Controller Driver
3 * LICENSE: GNU GPLv2 only as published by the Free Software Foundation
4 * FILE: drivers/storage/fdc/fdc/misc.c
5 * PURPOSE: Misc Routines
6 * PROGRAMMERS: Eric Kohl
9 /* INCLUDES *******************************************************************/
16 /* FUNCTIONS ******************************************************************/
19 DuplicateUnicodeString(
21 IN PCUNICODE_STRING SourceString
,
22 OUT PUNICODE_STRING DestinationString
)
26 if (SourceString
== NULL
||
27 DestinationString
== NULL
||
28 SourceString
->Length
> SourceString
->MaximumLength
||
29 (SourceString
->Length
== 0 && SourceString
->MaximumLength
> 0 && SourceString
->Buffer
== NULL
) ||
30 Flags
== RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
||
33 return STATUS_INVALID_PARAMETER
;
36 if ((SourceString
->Length
== 0) &&
37 (Flags
!= (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
|
38 RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
)))
40 DestinationString
->Length
= 0;
41 DestinationString
->MaximumLength
= 0;
42 DestinationString
->Buffer
= NULL
;
46 DestMaxLength
= SourceString
->Length
;
48 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
49 DestMaxLength
+= sizeof(UNICODE_NULL
);
51 DestinationString
->Buffer
= ExAllocatePoolWithTag(PagedPool
, DestMaxLength
, FDC_TAG
);
52 if (DestinationString
->Buffer
== NULL
)
53 return STATUS_NO_MEMORY
;
55 RtlCopyMemory(DestinationString
->Buffer
, SourceString
->Buffer
, SourceString
->Length
);
56 DestinationString
->Length
= SourceString
->Length
;
57 DestinationString
->MaximumLength
= DestMaxLength
;
59 if (Flags
& RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
)
60 DestinationString
->Buffer
[DestinationString
->Length
/ sizeof(WCHAR
)] = 0;
63 return STATUS_SUCCESS
;