• src/xpdev/stbuf.c stbuf.hsrc/xpdev/objects.mk xpdev.vcxproj xpdev_mt.v

    From Deuc¨@VERT to Git commit to main/sbbs/master on Tuesday, October 07, 2025 19:17:57
    https://gitlab.synchro.net/main/sbbs/-/commit/fb578e8021cd323e6b4e76a8
    Added Files:
    src/xpdev/stbuf.c stbuf.h
    Modified Files:
    src/xpdev/objects.mk xpdev.vcxproj xpdev_mt.vcxproj
    Log Message:
    Add a new stbuf.[ch] object

    This provides an API to manipulate buffers in a memory safe way.
    The guarantee there is a NUL after the buffer contents, so they
    can be passed to C string functions without possibly out of bounds
    reads (though they support embedded NULs, so are subject to truncation
    in that case).

    Buffer memory is by default managed with realloc(), but you can
    create a buffer object from statically allocated memory as well, and
    they prevent buffer overflows.

    The buffer manipulation functions are convenience wrappers around
    a repl() function that replaces a specified number of bytes in the
    buffer at a specific location with a specified number of new bytes.

    With this, the whole set of: stbuf_[mem|str|][repl|cpy|cat|ins]()
    functions are available. The source for stbuf_mem*() is a void *
    with a size_t size, the source for stbuf_str*() is a C string,
    and the source for functions without this name component is a stbuf.

    The *repl() functions do the full repl() API, cpy copies the source
    as the only data in the destination, cat appends to the end of the
    destination buffer, and ins inserts into the middle of the buffer.

    I've been wishing we had something like this fora while, and now
    we do. :D

    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net