view src/dmgrowbuf.h @ 2634:f3c7115cbf85 default tip

Fix verbose build echos.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 29 Feb 2024 21:47:31 +0200
parents 9807ae37ad69
children
line wrap: on
line source

/*
 * DMLib
 * -- Growable buffer implementation
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2018-2021 Tecnic Software productions (TNSP)
 */
#ifndef DMGROWBUF_H
#define DMGROWBUF_H

#include "dmlib.h"

#ifdef __cplusplus
extern "C" {
#endif


typedef struct
{
    Uint8
        *data;      // Actually allocated data pointer

    size_t
        offs,       // Current offset
        size,       // Actual allocated size
        len,        // Size requested
        mingrow;    // Minimum amount of bytes the allocation size grows by

    bool
        backwards,  // true if the buffer grows backwards (e.g. "offs" moves backwards)
        literal,    // true if dmGrowBufPut*() functions stores data "literally" in backwards mode
        is_const;   // true will cause any reallocs etc. modifications to fail
} DMGrowBuf;


int    dmGrowBufInit(DMGrowBuf *buf);
int    dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow);
void   dmGrowBufFree(DMGrowBuf *buf);

DMGrowBuf * dmGrowBufCopy(DMGrowBuf *dst, const DMGrowBuf *src, const size_t enlarge);
DMGrowBuf * dmGrowBufCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t enlarge);
DMGrowBuf * dmGrowBufCopyOffsSize(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t len, const size_t enlarge);

DMGrowBuf * dmGrowBufConstCopy(DMGrowBuf *dst, const DMGrowBuf *src);
DMGrowBuf * dmGrowBufConstCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs);
DMGrowBuf * dmGrowBufConstCopyOffsSize(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t len);
DMGrowBuf * dmGrowBufConstCreateFrom(DMGrowBuf *buf, Uint8 *data, const size_t len);


bool   dmGrowBufGrow(DMGrowBuf *buf, const size_t amount);
bool   dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize);

bool   dmGrowBufPut(DMGrowBuf *buf, const Uint8 *data, const size_t len);
bool   dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value);
bool   dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val);
bool   dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val);
bool   dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val);
bool   dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val);

bool   dmGrowBufGetU8(DMGrowBuf *buf, Uint8 *value);


#ifdef __cplusplus
}
#endif

#endif // DMGROWBUF_H