view lib/util.h @ 20:f98ea578b1ef

misc: revamp database
author David Demelier <markand@malikania.fr>
date Tue, 19 Jul 2022 21:52:42 +0200
parents de4bf839b565
children dd078aea5d02
line wrap: on
line source

/*
 * util.h -- miscellaneous utilities
 *
 * Copyright (c) 2021 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef SCI_UTIL_H
#define SCI_UTIL_H

#include <stddef.h>
#include <stdio.h>

#define UTIL_SIZE(x) (sizeof (x) / sizeof (x[0]))

void *
util_malloc(size_t);

void *
util_calloc(size_t, size_t);

void *
util_realloc(void *, size_t);

void *
util_reallocarray(void *, size_t, size_t);

void *
util_memdup(const void *, size_t);

char *
util_strdup(const char *);

char *
util_strndup(const char *, size_t);

size_t
util_strlcpy(char *, const char *, size_t);

char *
util_basename(const char *);

char *
util_dirname(const char *);

FILE *
util_fmemopen(void *, size_t, const char *);

char *
util_printf(char *, size_t, const char *, ...);

char *
util_read(const char *);

const char *
util_path(const char *);

void
util_die(const char *, ...);

#endif /* !SCI_UTIL_H */