OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcFlexArrayLib.h File Reference
#include <Uefi.h>
#include <Library/OcStringLib.h>
#include <Protocol/ApplePlatformInfoDatabase.h>

Go to the source code of this file.

Data Structures

struct  OC_FLEX_ARRAY_
 
struct  OC_ASCII_STRING_BUFFER_
 

Macros

#define OC_TRACE_FLEX   DEBUG_VERBOSE
 

Typedefs

typedef struct OC_FLEX_ARRAY_ OC_FLEX_ARRAY
 
typedef VOID(* OC_FLEX_ARRAY_FREE_ITEM) (IN VOID *Item)
 
typedef struct OC_ASCII_STRING_BUFFER_ OC_ASCII_STRING_BUFFER
 

Functions

VOID OcFlexArrayFreePointerItem (IN VOID *Item)
 
OC_FLEX_ARRAYOcFlexArrayInit (IN CONST UINTN ItemSize, IN CONST OC_FLEX_ARRAY_FREE_ITEM FreeItem OPTIONAL)
 
VOID * OcFlexArrayAddItem (IN OUT OC_FLEX_ARRAY *FlexArray)
 
VOID * OcFlexArrayInsertItem (IN OUT OC_FLEX_ARRAY *FlexArray, IN CONST UINTN InsertIndex)
 
VOID * OcFlexArrayItemAt (IN CONST OC_FLEX_ARRAY *FlexArray, IN CONST UINTN Index)
 
VOID OcFlexArrayFree (IN OUT OC_FLEX_ARRAY **FlexArray)
 
VOID OcFlexArrayDiscardItem (IN OUT OC_FLEX_ARRAY *FlexArray, IN CONST BOOLEAN FreeItem)
 
VOID OcFlexArrayFreeContainer (IN OUT OC_FLEX_ARRAY **FlexArray, IN OUT VOID **Items, IN OUT UINTN *Count)
 
OC_ASCII_STRING_BUFFEROcAsciiStringBufferInit (VOID)
 
EFI_STATUS OcAsciiStringBufferAppend (IN OUT OC_ASCII_STRING_BUFFER *Buffer, IN CONST CHAR8 *AppendString OPTIONAL)
 
EFI_STATUS OcAsciiStringBufferAppendN (IN OUT OC_ASCII_STRING_BUFFER *Buffer, IN CONST CHAR8 *AppendString, OPTIONAL IN CONST UINTN Length)
 
EFI_STATUS EFIAPI OcAsciiStringBufferSPrint (IN OUT OC_ASCII_STRING_BUFFER *Buffer, IN CONST CHAR8 *FormatString,...)
 
CHAR8 * OcAsciiStringBufferFreeContainer (IN OUT OC_ASCII_STRING_BUFFER **StringBuffer)
 
VOID OcAsciiStringBufferFree (IN OUT OC_ASCII_STRING_BUFFER **StringBuffer)
 
OC_FLEX_ARRAYOcStringSplit (IN CONST VOID *String, IN CONST CHAR16 Delim, IN CONST OC_STRING_FORMAT StringFormat)
 

Detailed Description

Copyright (C) 2021, Mike Beaton. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause

Definition in file OcFlexArrayLib.h.

Macro Definition Documentation

◆ OC_TRACE_FLEX

#define OC_TRACE_FLEX   DEBUG_VERBOSE

Definition at line 10 of file OcFlexArrayLib.h.

Typedef Documentation

◆ OC_ASCII_STRING_BUFFER

Definition at line 174 of file OcFlexArrayLib.h.

◆ OC_FLEX_ARRAY

typedef struct OC_FLEX_ARRAY_ OC_FLEX_ARRAY

Forward declaration of OC_FLEX_ARRAY structure.

Definition at line 20 of file OcFlexArrayLib.h.

◆ OC_FLEX_ARRAY_FREE_ITEM

typedef VOID(* OC_FLEX_ARRAY_FREE_ITEM) (IN VOID *Item)

Free any allocated memory pointed to by flex array item.

Parameters
[in]ItemItem to free.

Definition at line 28 of file OcFlexArrayLib.h.

Function Documentation

◆ OcAsciiStringBufferAppend()

EFI_STATUS OcAsciiStringBufferAppend ( IN OUT OC_ASCII_STRING_BUFFER * Buffer,
IN CONST CHAR8 *AppendString OPTIONAL )

Append new string to buffer, resizing if necessary.

Parameters
[in,out]StringBufferBuffer to modify.
[in]AppendStringString to append. If NULL, nothing will be modified.
Return values
EFI_SUCCESSString was appended.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_UNSUPPORTEDInternal error.

Definition at line 29 of file AsciiStringBuffer.c.

◆ OcAsciiStringBufferAppendN()

EFI_STATUS OcAsciiStringBufferAppendN ( IN OUT OC_ASCII_STRING_BUFFER * Buffer,
IN CONST CHAR8 * AppendString,
OPTIONAL IN CONST UINTN Length )

Append new substring to buffer, resizing if necessary.

Parameters
[in,out]StringBufferBuffer to modify.
[in]AppendStringString to append. If NULL, nothing will be modified.
[in]LengthMaxiumum length of substring to use. 0 means use 0 characters. Use MAX_UINTN for all chars. Ignored if AppendString is NULL.
Return values
EFI_SUCCESSString was appended.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_UNSUPPORTEDInternal error.

Definition at line 101 of file AsciiStringBuffer.c.

◆ OcAsciiStringBufferFree()

VOID OcAsciiStringBufferFree ( IN OUT OC_ASCII_STRING_BUFFER ** StringBuffer)

Free string buffer memory; free and discard any allocated resultant string.

Parameters
[in,out]StringBufferStringBuffer to free.
Return values
Non-NULLPointer to pool allocated accumulated string.
NULLNo data was ever added to the string.

Definition at line 197 of file AsciiStringBuffer.c.

◆ OcAsciiStringBufferFreeContainer()

CHAR8 * OcAsciiStringBufferFreeContainer ( IN OUT OC_ASCII_STRING_BUFFER ** StringBuffer)

Free string buffer memory and return pointer to pool allocated resultant string. Note that if no data was ever appended to the string then the return value will be NULL, not a zero length string.

Parameters
[in,out]StringBufferStringBuffer to free.
Return values
Non-NULLPointer to pool allocated accumulated string.
NULLNo data was ever added to the string.

Definition at line 178 of file AsciiStringBuffer.c.

◆ OcAsciiStringBufferInit()

OC_ASCII_STRING_BUFFER * OcAsciiStringBufferInit ( VOID )

Initialize string buffer.

Return values
Non-NULLBuffer was created.
NULLOut of memory.

Definition at line 17 of file AsciiStringBuffer.c.

◆ OcAsciiStringBufferSPrint()

EFI_STATUS EFIAPI OcAsciiStringBufferSPrint ( IN OUT OC_ASCII_STRING_BUFFER * Buffer,
IN CONST CHAR8 * FormatString,
... )

Safely print to string buffer.

Parameters
[in,out]StringBufferBuffer to modify.
[in]FormatStringA Null-terminated ASCII format string.
[in]...Variable argument list whose contents are accessed based on the format string specified by FormatString.
Return values
EFI_SUCCESSWhen data was printed to string buffer.
EFI_OUT_OF_RESOURCESOut of memory increasing string buffer sufficiently to print to.

Definition at line 140 of file AsciiStringBuffer.c.

◆ OcFlexArrayAddItem()

VOID * OcFlexArrayAddItem ( IN OUT OC_FLEX_ARRAY * FlexArray)

Add new item to flex array, resizing if necessary. New item memory is zeroed.

Parameters
[in,out]FlexArrayFlex array to modify.
Return values
Non-NULLAddress of item created.
NULLOut of memory, in which case FlexArray->Items will be set to NULL, but FlexArray itself will still be allocated.

Definition at line 136 of file FlexArray.c.

◆ OcFlexArrayDiscardItem()

VOID OcFlexArrayDiscardItem ( IN OUT OC_FLEX_ARRAY * FlexArray,
IN CONST BOOLEAN FreeItem )

Discard last item on flex array, optionally calling item free method.

Parameters
[in,out]FlexArrayFlex array to modify.
[in]FreeItemWhether to call item free method.

Definition at line 238 of file FlexArray.c.

◆ OcFlexArrayFree()

VOID OcFlexArrayFree ( IN OUT OC_FLEX_ARRAY ** FlexArray)

Free flex array.

Parameters
[in,out]FlexArrayFlex array to free.

◆ OcFlexArrayFreeContainer()

VOID OcFlexArrayFreeContainer ( IN OUT OC_FLEX_ARRAY ** FlexArray,
IN OUT VOID ** Items,
IN OUT UINTN * Count )

Free dynamic container object, but do not free and pass back out allocated items with item count.

Parameters
[in,out]FlexArrayFlex array to free.
[in,out]ItemsPool allocated flex array item list.
[in,out]CountItem list count.

◆ OcFlexArrayFreePointerItem()

VOID OcFlexArrayFreePointerItem ( IN VOID * Item)

Utility method to free memory pointed to by flex array item when the item is a single pointer, or when the only allocated memory is pointed to by a pointer which is the first element.

Parameters
[in]ItemFlex array item to free.

Definition at line 18 of file FlexArray.c.

◆ OcFlexArrayInit()

OC_FLEX_ARRAY * OcFlexArrayInit ( IN CONST UINTN ItemSize,
IN CONST OC_FLEX_ARRAY_FREE_ITEM FreeItem OPTIONAL )

Initialize flex array.

Parameters
[in]ItemSizeSize of each item in the array.
[in]FreeItemMethod to free one item, called once per item by OcFlexArrayFree; may be NULL if there is nothing pointed to by pool items which needs freeing.
Return values
Non-NULLFlex array was created.
NULLOut of memory.

Definition at line 31 of file FlexArray.c.

◆ OcFlexArrayInsertItem()

VOID * OcFlexArrayInsertItem ( IN OUT OC_FLEX_ARRAY * FlexArray,
IN CONST UINTN InsertIndex )

Insert new item at position in flex array, resizing array if necessary. New item memory is zeroed.

Parameters
[in,out]FlexArrayFlex array to modify.
[in]InsertIndexIndex at which to insert; must be less than or equal to current item count.
Return values
Non-NULLAddress of item created.
NULLOut of memory, in which case FlexArray->Items will be set to NULL, but FlexArray itself will still be allocated.

Definition at line 156 of file FlexArray.c.

◆ OcFlexArrayItemAt()

VOID * OcFlexArrayItemAt ( IN CONST OC_FLEX_ARRAY * FlexArray,
IN CONST UINTN Index )

Return item at index in array.

Parameters
[in,out]FlexArrayFlex array to access.
[in,out]IndexIndex of item to return.
Return values
Non-NULLItem.
NULLOut-of-range item requested. This also ASSERTs.

Definition at line 189 of file FlexArray.c.

◆ OcStringSplit()

OC_FLEX_ARRAY * OcStringSplit ( IN CONST VOID * String,
IN CONST CHAR16 Delim,
IN CONST OC_STRING_FORMAT StringFormat )

Split string by delimiter.

Parameters
[in]StringA Null-terminated string.
[in]DelimDelimiter to search in String.
[in]StringFormatAre option names and values Unicode or ASCII?
Returns
A flex array containing splitted string.

Definition at line 15 of file FlexString.c.