21 #elif defined(_POSIX_MAPPED_FILES)
25 #elif defined(PRISM_HAS_FILESYSTEM)
70 #define PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = NULL, .length = 0 })
Macro definitions used throughout the prism library.
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition: defines.h:50
PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string)
Returns the length associated with the string.
Definition: pm_string.c:352
void pm_string_ensure_owned(pm_string_t *string)
Ensure the string is owned.
Definition: pm_string.c:315
void pm_string_constant_init(pm_string_t *string, const char *source, size_t length)
Initialize a constant string that doesn't own its memory source.
Definition: pm_string.c:42
void pm_string_owned_init(pm_string_t *string, uint8_t *source, size_t length)
Initialize an owned string that is responsible for freeing allocated memory.
Definition: pm_string.c:30
pm_string_init_result_t
Represents the result of calling pm_string_mapped_init or pm_string_file_init.
Definition: pm_string.h:105
@ PM_STRING_INIT_SUCCESS
Indicates that the string was successfully initialized.
Definition: pm_string.h:107
@ PM_STRING_INIT_ERROR_GENERIC
Indicates a generic error from a string_*_init function, where the type of error should be read from ...
Definition: pm_string.h:112
@ PM_STRING_INIT_ERROR_DIRECTORY
Indicates that the file that was attempted to be opened was a directory.
Definition: pm_string.h:116
void pm_string_shared_init(pm_string_t *string, const uint8_t *start, const uint8_t *end)
Initialize a shared string that is based on initial input.
Definition: pm_string.c:16
PRISM_EXPORTED_FUNCTION pm_string_init_result_t pm_string_mapped_init(pm_string_t *string, const char *filepath)
Read the file indicated by the filepath parameter into source and load its contents and size into the...
Definition: pm_string.c:118
PRISM_EXPORTED_FUNCTION void pm_string_free(pm_string_t *string)
Free the associated memory of the given string.
Definition: pm_string.c:368
PRISM_EXPORTED_FUNCTION size_t pm_string_sizeof(void)
Returns the size of the pm_string_t struct.
Definition: pm_string.c:8
PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string)
Returns the start pointer associated with the string.
Definition: pm_string.c:360
int pm_string_compare(const pm_string_t *left, const pm_string_t *right)
Compare the underlying lengths and bytes of two strings.
Definition: pm_string.c:335
PRISM_EXPORTED_FUNCTION pm_string_init_result_t pm_string_file_init(pm_string_t *string, const char *filepath)
Read the file indicated by the filepath parameter into source and load its contents and size into the...
Definition: pm_string.c:209
A generic string type that can have various ownership semantics.
Definition: pm_string.h:33
const uint8_t * source
A pointer to the start of the string.
Definition: pm_string.h:35
size_t length
The length of the string in bytes of memory.
Definition: pm_string.h:38
@ PM_STRING_OWNED
This string owns its memory, and should be freed using pm_string_free.
Definition: pm_string.h:49
@ PM_STRING_CONSTANT
This string is a constant string, and should not be freed.
Definition: pm_string.h:43
@ PM_STRING_SHARED
This is a slice of another string, and should not be freed.
Definition: pm_string.h:46