KMALLOC(3) Library Functions Manual KMALLOC(3)

kasprintf, kcalloc, kmalloc, krealloc, kreallocarray, kstrdup, kvasprintfmemory allocation functions for kcgi

library “libkcgi”

#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>

kasprintf(char **p, const char *fmt, ...);

void *
kcalloc(size_t nm, size_t sz);

void *
kmalloc(size_t sz);

void *
krealloc(void *p, size_t sz);

void *
kreallocarray(void *p, size_t nm, size_t sz);

char *
kstrdup(const char *cp);

kvasprintf(char **p, const char *fmt, va_list ap);

These functions wrap around corresponding libc versions except that on allocation failure, they print a warning message to standard error output and call exit(3).

Calling (), (), (), or () with sz or nm equal to zero, or passing NULL to (), additionally prints a warning message to the standard error output and produces non-portable results.


These functions were written by Kristaps Dzonsons <>.

February 11, 2020 OpenBSD 6.7