ReactOS 0.4.15-dev-7994-gb388cb6
flatbuf.c File Reference
#include "precomp.h"
Include dependency graph for flatbuf.c:

Go to the source code of this file.

Functions

VOID WINAPI FlatBuf_Init (IN PFLATBUFF FlatBuffer, IN PVOID Buffer, IN SIZE_T Size)
 
PVOID WINAPI FlatBuf_Arg_Reserve (IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN SIZE_T Size, IN ULONG Align)
 
PVOID WINAPI FlatBuf_Arg_CopyMemory (IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN PVOID Buffer, IN SIZE_T Size, IN ULONG Align)
 
PVOID WINAPI FlatBuf_Arg_WriteString (IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN PVOID String, IN BOOLEAN IsUnicode)
 

Function Documentation

◆ FlatBuf_Arg_CopyMemory()

PVOID WINAPI FlatBuf_Arg_CopyMemory ( IN OUT PULONG_PTR  Position,
IN OUT PSIZE_T  FreeSize,
IN PVOID  Buffer,
IN SIZE_T  Size,
IN ULONG  Align 
)

Definition at line 60 of file flatbuf.c.

65{
67
68 /* First reserve the memory */
70 if (Destination)
71 {
72 /* We have space, do the copy */
74 }
75
76 /* Return the pointer to the data */
77 return Destination;
78}
Definition: bufpool.h:45
int Align(int arg)
Definition: ehframes.cpp:89
PVOID WINAPI FlatBuf_Arg_Reserve(IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN SIZE_T Size, IN ULONG Align)
Definition: flatbuf.c:32
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3004
static COORD Position
Definition: mouse.c:34
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

◆ FlatBuf_Arg_Reserve()

PVOID WINAPI FlatBuf_Arg_Reserve ( IN OUT PULONG_PTR  Position,
IN OUT PSIZE_T  FreeSize,
IN SIZE_T  Size,
IN ULONG  Align 
)

Definition at line 32 of file flatbuf.c.

36{
37 ULONG_PTR NewPosition, OldPosition = *Position;
38 SIZE_T NewFreeSize = *FreeSize;
39
40 /* Start by aligning our position */
41 if (Align) OldPosition += (Align - 1) & ~Align;
42
43 /* Update it */
44 NewPosition = OldPosition + Size;
45
46 /* Update Free Size */
47 NewFreeSize += (OldPosition - NewPosition);
48
49 /* Save new values */
50 *Position = NewPosition;
51 *FreeSize = NewFreeSize;
52
53 /* Check if we're out of space or not */
54 if (NewFreeSize > 0) return (PVOID)OldPosition;
55 return NULL;
56}
#define NULL
Definition: types.h:112
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by FlatBuf_Arg_CopyMemory(), FlatBuf_Arg_ReserveAlignPointer(), and FlatBuf_Arg_WriteString().

◆ FlatBuf_Arg_WriteString()

PVOID WINAPI FlatBuf_Arg_WriteString ( IN OUT PULONG_PTR  Position,
IN OUT PSIZE_T  FreeSize,
IN PVOID  String,
IN BOOLEAN  IsUnicode 
)

Definition at line 82 of file flatbuf.c.

86{
88 SIZE_T StringLength;
90
91 /* Calculate the string length */
92 if (IsUnicode)
93 {
94 /* Get the length in bytes and use WCHAR alignment */
95 StringLength = (wcslen((LPWSTR)String) + 1) * sizeof(WCHAR);
96 Align = sizeof(WCHAR);
97 }
98 else
99 {
100 /* Get the length in bytes and use CHAR alignment */
101 StringLength = strlen((LPSTR)String) + 1;
102 Align = sizeof(CHAR);
103 }
104
105 /* Now reserve the memory */
106 Destination = FlatBuf_Arg_Reserve(Position, FreeSize, StringLength, Align);
107 if (Destination)
108 {
109 /* We have space, do the copy */
110 RtlCopyMemory(Destination, String, StringLength);
111 }
112
113 /* Return the pointer to the data */
114 return Destination;
115}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define CHAR(Char)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ FlatBuf_Init()

VOID WINAPI FlatBuf_Init ( IN PFLATBUFF  FlatBuffer,
IN PVOID  Buffer,
IN SIZE_T  Size 
)

Definition at line 17 of file flatbuf.c.

20{
21 /* Set up the Flat Buffer start, current and ending position */
22 FlatBuffer->Buffer = Buffer;
23 FlatBuffer->BufferPos = (ULONG_PTR)Buffer;
24 FlatBuffer->BufferEnd = (PVOID)(FlatBuffer->BufferPos + Size);
25
26 /* Setup the current size and the available size */
27 FlatBuffer->BufferSize = FlatBuffer->BufferFreeSize = Size;
28}
#define ULONG_PTR
Definition: config.h:101
void * PVOID
Definition: typedefs.h:50