ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

flatbuf.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS DNS Shared Library
00004  * FILE:        lib/dnslib/flatbuf.c
00005  * PURPOSE:     Functions for managing the Flat Buffer Implementation (FLATBUF)
00006  */
00007 
00008 /* INCLUDES ******************************************************************/
00009 #include "precomp.h"
00010 
00011 /* DATA **********************************************************************/
00012 
00013 /* FUNCTIONS *****************************************************************/
00014 
00015 VOID
00016 WINAPI
00017 FlatBuf_Init(IN PFLATBUFF FlatBuffer,
00018              IN PVOID Buffer,
00019              IN SIZE_T Size)
00020 {
00021     /* Set up the Flat Buffer start, current and ending position */
00022     FlatBuffer->Buffer = Buffer;
00023     FlatBuffer->BufferPos = (ULONG_PTR)Buffer;
00024     FlatBuffer->BufferEnd = (PVOID)(FlatBuffer->BufferPos + Size);
00025 
00026     /* Setup the current size and the available size */
00027     FlatBuffer->BufferSize = FlatBuffer->BufferFreeSize = Size;
00028 }
00029 
00030 PVOID
00031 WINAPI
00032 FlatBuf_Arg_Reserve(IN OUT PULONG_PTR Position,
00033                     IN OUT PSIZE_T FreeSize,
00034                     IN SIZE_T Size,
00035                     IN ULONG Align)
00036 {
00037     ULONG_PTR NewPosition, OldPosition = *Position;
00038     SIZE_T NewFreeSize = *FreeSize;
00039 
00040     /* Start by aligning our position */
00041     if (Align) OldPosition += (Align - 1) & ~Align;
00042 
00043     /* Update it */
00044     NewPosition = OldPosition + Size;
00045 
00046     /* Update Free Size */
00047     NewFreeSize += (OldPosition - NewPosition);
00048 
00049     /* Save new values */
00050     *Position = NewPosition;
00051     *FreeSize = NewFreeSize;
00052 
00053     /* Check if we're out of space or not */
00054     if (NewFreeSize > 0) return (PVOID)OldPosition;
00055     return NULL;
00056 }
00057 
00058 PVOID
00059 WINAPI
00060 FlatBuf_Arg_CopyMemory(IN OUT PULONG_PTR Position,
00061                        IN OUT PSIZE_T FreeSize,
00062                        IN PVOID Buffer,
00063                        IN SIZE_T Size,
00064                        IN ULONG Align)
00065 {
00066     PVOID Destination;
00067 
00068     /* First reserve the memory */
00069     Destination = FlatBuf_Arg_Reserve(Position, FreeSize, Size, Align);
00070     if (Destination)
00071     {
00072         /* We have space, do the copy */
00073         RtlCopyMemory(Destination, Buffer, Size);
00074     }
00075 
00076     /* Return the pointer to the data */
00077     return Destination;
00078 }
00079 
00080 PVOID
00081 WINAPI
00082 FlatBuf_Arg_WriteString(IN OUT PULONG_PTR Position,
00083                         IN OUT PSIZE_T FreeSize,
00084                         IN PVOID String,
00085                         IN BOOLEAN IsUnicode)
00086 {
00087     PVOID Destination;
00088     SIZE_T StringLength;
00089     ULONG Align;
00090 
00091     /* Calculate the string length */
00092     if (IsUnicode)
00093     {
00094         /* Get the length in bytes and use WCHAR alignment */
00095         StringLength = (wcslen((LPWSTR)String) + 1) * sizeof(WCHAR);
00096         Align = sizeof(WCHAR);
00097     }
00098     else
00099     {
00100         /* Get the length in bytes and use CHAR alignment */
00101         StringLength = strlen((LPSTR)String) + 1;
00102         Align = sizeof(CHAR);
00103     }
00104 
00105     /* Now reserve the memory */
00106     Destination = FlatBuf_Arg_Reserve(Position, FreeSize, StringLength, Align);
00107     if (Destination)
00108     {
00109         /* We have space, do the copy */
00110         RtlCopyMemory(Destination, String, StringLength);
00111     }
00112 
00113     /* Return the pointer to the data */
00114     return Destination;
00115 }
00116 

Generated on Fri May 25 2012 04:34:28 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.