/* =====================================
 * Generated by Mod-c 0.26.5
 * HEADER dynbuf MODULE
 * ===================================== */

#ifndef MODC_MODULE_dynbuf_H
#define MODC_MODULE_dynbuf_H

#include <stdint.h>
#include <stdbool.h>
#include <assert.h>

#define nil ((void *)0)
#define NIL nil
typedef uint8_t byte;
typedef const char* string;
typedef int integer;
typedef unsigned int cardinal;
typedef float real;

/**
 * Mod-c
 * By M. Scott Reynolds
 * Date 20 February 2026
 *
 * dynbuf.c - Dynamic null-terminated string buffer with exponential growth.
 */

/* === IMPORT === */
#include "stddef.h"

/* === IMPORT === */
#include "stdio.h"

/* === IMPORT === */
#include "stdlib.h"

/* === IMPORT === */
#include "string.h"

/**
 * Dynamic string buffer with exponential growth and null-termination.
 * All functions maintain null-termination (data[used] == '\0').
 * The bufffer owns its data pointer - caller must call dynbuf_free().
 */

/* === TYPE EXPORT === */
typedef struct DynBuf DynBuf;
typedef struct DynBuf {
    char* data;
    size_t size;
    size_t used;
} DynBuf;

/* === TYPE EXPORT === */
typedef DynBuf* pDynBuf;

/**
 * Initialize a dynamic buffer with initial capacity.
 * Exits program on allocation failure.
 */

/* === PROC/FUNC EXPORT === */
void dynbuf_init(DynBuf* b);

/**
 * Append a null-terminated string to the buffer.
 * Automatically grows if needed.
 * Exits on reallocation failure.
 */

/* === PROC/FUNC EXPORT === */
void dynbuf_appendn(DynBuf* b, const char* str, size_t str_len);

/**
 * Append n chars of a string to the buffer.
 */

/* === PROC/FUNC EXPORT === */
void dynbuf_append(DynBuf* b, const char* str);

/**
 * Append a single character to the buffer.
 * Automatically grows if needed.
 * Exits on reallocation failure.
 */

/* === PROC/FUNC EXPORT === */
void dynbuf_append_char(DynBuf* b, char c);

/**
 * Free the buffer's memory and reset all fields.
 * Safe to call multiple times or on uninitialized buffer.
 */

/* === PROC/FUNC EXPORT === */
void dynbuf_free(DynBuf* b);

void dynbuf(void);

#endif /* MODC_MODULE_dynbuf_H */
