Gama C Library
Gama C API Documentation
str.h File Reference

Defines a dynamic string structure and provides utility functions for its manipulation. More...

#include "_malloc.h"
#include <stddef.h>
#include <string.h>

Go to the source code of this file.

Data Structures

struct  gmStr
 Represents a dynamic, heap-allocated string. More...

Functions

gmStr gm_str ()
 Initializes an empty gmStr struct.
int gm_str_appendn (gmStr *s, size_t n, const char *txt)
 Appends a specified number of characters from a C string to a gmStr.
void gm_str_clear (gmStr *str)
 Frees the heap-allocated content of a gmStr and resets its length to 0.

Detailed Description

Defines a dynamic string structure and provides utility functions for its manipulation.

This file offers a simple dynamic string (gmStr) implementation that can grow as needed, making it suitable for building strings without fixed-size buffer limitations.

Function Documentation

◆ gm_str()

gmStr gm_str ( )

Initializes an empty gmStr struct.

Returns
A new gmStr instance with length 0 and NULL content.

◆ gm_str_appendn()

int gm_str_appendn ( gmStr * s,
size_t n,
const char * txt )

Appends a specified number of characters from a C string to a gmStr.

This function reallocates memory for the gmStr's content if necessary to accommodate the new characters.

Parameters
sA pointer to the gmStr to append to.
nThe number of characters from txt to append.
txtThe null-terminated C string to append.
Returns
0 on success, -1 on invalid input, -5 on reallocation failure.

◆ gm_str_clear()

void gm_str_clear ( gmStr * str)

Frees the heap-allocated content of a gmStr and resets its length to 0.

The gmStr struct itself is not freed, only its internal buffer.

Parameters
strA pointer to the gmStr to clear.