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

Provides general utility functions for file handling and string manipulation. More...

#include "_malloc.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Functions

void gmu_get_filename_base (const char *path, char *out_base, size_t out_size)
 Extracts the base filename (filename with extension) from a full path.
void gmu_get_filename_stem (const char *path, char *out_stem, size_t out_size)
 Extracts the filename stem (filename without extension) from a full path.
int gmu_read_file (const char *path, char **content, size_t *size)
 Reads the entire content of a file into a dynamically allocated buffer.

Detailed Description

Provides general utility functions for file handling and string manipulation.

This file contains miscellaneous helper functions that are not directly related to a specific Gama module but are useful across the engine.

Function Documentation

◆ gmu_get_filename_base()

void gmu_get_filename_base ( const char * path,
char * out_base,
size_t out_size )

Extracts the base filename (filename with extension) from a full path.

Example: path = "/home/user/image.png" -> out_base = "image.png"

Parameters
pathThe full path string.
out_baseBuffer to store the extracted filename.
out_sizeThe size of the out_base buffer.

◆ gmu_get_filename_stem()

void gmu_get_filename_stem ( const char * path,
char * out_stem,
size_t out_size )

Extracts the filename stem (filename without extension) from a full path.

Example: path = "/home/user/image.png" -> out_stem = "image"

Parameters
pathThe full path string.
out_stemBuffer to store the extracted filename stem.
out_sizeThe size of the out_stem buffer.

◆ gmu_read_file()

int gmu_read_file ( const char * path,
char ** content,
size_t * size )

Reads the entire content of a file into a dynamically allocated buffer.

The caller is responsible for freeing the *content buffer.

Parameters
pathThe path to the file to read.
contentA pointer to a char* that will be allocated and filled with the file's content.
sizeA pointer to a size_t that will store the size of the read content. Can be NULL.
Returns
0 on success, -1 if the file cannot be opened, -5 on memory allocation failure.