view libsci/util.h @ 33:1d0ddf9e6efd

misc: general documentation
author David Demelier <markand@malikania.fr>
date Thu, 04 Aug 2022 16:47:10 +0200
parents lib/util.h@081e1c258e64
children e52c762d8ba8
line wrap: on
line source

/*
 * util.h -- miscellaneous utilities
 *
 * Copyright (c) 2021-2022 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>

#include <jansson.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);

char *
util_basename(const char *);

char *
util_dirname(const char *);

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

FILE *
util_open_memstream(char **, size_t *);

char *
util_read(const char *);

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

json_t *
util_json_pack(const char *, ...);

char *
util_json_dump(const json_t *);

/* defined in extern/ */

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

long long
util_strtonum(const char *, long long, long long, const char **);

#endif /* !SCI_UTIL_H */