OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
fsw_lib.c File Reference
#include "fsw_core.h"
#include "fsw_strfunc.h"

Go to the source code of this file.

Macros

#define STREQ_DISPATCH(type1, type2)
 
#define STRCOERCE_DISPATCH(type1, type2)
 

Functions

fsw_status_t fsw_alloc_zero (int len, void **ptr_out)
 
fsw_status_t fsw_memdup (void **dest_out, void *src, int len)
 
int fsw_strlen (struct fsw_string *s)
 
int fsw_strsize (struct fsw_string *s)
 
void * fsw_strdata (struct fsw_string *s)
 
int fsw_streq (struct fsw_string *s1, struct fsw_string *s2)
 
int fsw_streq_cstr (struct fsw_string *s1, const char *s2)
 
fsw_status_t fsw_strdup_coerce (struct fsw_string *dest, int type, struct fsw_string *src)
 
void fsw_strsplit (struct fsw_string *element, struct fsw_string *buffer, char separator)
 
void fsw_strfree (struct fsw_string *s)
 

Detailed Description

Core file system wrapper library functions.

Definition in file fsw_lib.c.

Macro Definition Documentation

◆ STRCOERCE_DISPATCH

#define STRCOERCE_DISPATCH ( type1,
type2 )
Value:
if (src->type == FSW_STRING_TYPE_##type1 && type == FSW_STRING_TYPE_##type2) \
return fsw_strcoerce_##type1##_##type2(src->data, src->len, dest);
cache_type_t type

◆ STREQ_DISPATCH

#define STREQ_DISPATCH ( type1,
type2 )
Value:
if (s1->type == FSW_STRING_TYPE_##type1 && s2->type == FSW_STRING_TYPE_##type2) \
return fsw_streq_##type1##_##type2(s1->data, s2->data, s1->len); \
if (s2->type == FSW_STRING_TYPE_##type1 && s1->type == FSW_STRING_TYPE_##type2) \
return fsw_streq_##type1##_##type2(s2->data, s1->data, s1->len);

Function Documentation

◆ fsw_alloc_zero()

fsw_status_t fsw_alloc_zero ( int len,
void ** ptr_out )

Allocate memory and clear it.

Definition at line 49 of file fsw_lib.c.

◆ fsw_memdup()

fsw_status_t fsw_memdup ( void ** dest_out,
void * src,
int len )

Duplicate a piece of data.

Definition at line 64 of file fsw_lib.c.

◆ fsw_strdata()

void * fsw_strdata ( struct fsw_string * s)

Get the data of a string.

Definition at line 100 of file fsw_lib.c.

◆ fsw_strdup_coerce()

fsw_status_t fsw_strdup_coerce ( struct fsw_string * dest,
int type,
struct fsw_string * src )

Creates a duplicate of a string, converting it to the given encoding during the copy. If the function returns FSW_SUCCESS, the caller must free the string later with fsw_strfree.

Definition at line 190 of file fsw_lib.c.

◆ fsw_streq()

int fsw_streq ( struct fsw_string * s1,
struct fsw_string * s2 )

Compare two strings for equality. The two strings are compared, taking their encoding into account. If they are considered equal, boolean true is returned. Otherwise, boolean false is returned.

Definition at line 114 of file fsw_lib.c.

◆ fsw_streq_cstr()

int fsw_streq_cstr ( struct fsw_string * s1,
const char * s2 )

Compare a string with a C string constant. This sets up a string descriptor for the string constant (second argument) and runs fsw_streq on the two strings. Currently the C string is interpreted as ISO 8859-1. Returns boolean true if the strings are considered equal, boolean false otherwise.

Definition at line 169 of file fsw_lib.c.

◆ fsw_strfree()

void fsw_strfree ( struct fsw_string * s)

Frees the memory used by a string returned from fsw_strdup_coerce.

Definition at line 310 of file fsw_lib.c.

◆ fsw_strlen()

int fsw_strlen ( struct fsw_string * s)

Get the length of a string. Returns the number of characters in the string.

Definition at line 79 of file fsw_lib.c.

◆ fsw_strsize()

int fsw_strsize ( struct fsw_string * s)

Get the size of a string in bytes.

Definition at line 89 of file fsw_lib.c.

◆ fsw_strsplit()

void fsw_strsplit ( struct fsw_string * element,
struct fsw_string * buffer,
char separator )

Splits a string at the first occurence of the separator character. The buffer string is searched for the separator character. If it is found, the element string descriptor is filled to point at the part of the buffer string before the separator. The buffer string itself is adjusted to point at the remaining part of the string (without the separator).

If the separator is not found in the buffer string, then element is changed to point at the whole buffer string, and the buffer string itself is changed into an empty string.

This function only manipulates the pointers and lengths in the two string descriptors, it does not change the actual string. If the buffer string is dynamically allocated, you must make a copy of it so that you can release it later.

Definition at line 246 of file fsw_lib.c.