git / brickware / marrow.git - main

(45 minutes ago)commit 7790c99: Meh. Halfway vector implementation. Not happy with the name

tree / slice_tocstr.c

slice_tocstr.c

raw

/***
 * slice_tocstr.c
 */

#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "./slice.h"


char *
slice_tocstr(const struct slice s) {
    if (0 == s.ptr || 0 == s.size) {
        return 0x00;
    }

    char *str = malloc(s.size + 1);
    if (!str) {
        return 0x00;
    }

    memcpy(str, s.ptr, s.size);
    str[s.size] = '\0';
    return str;
}