view libcore/core/util.h @ 193:78774cc2cc6b

doc: minimal typo
author David Demelier <markand@malikania.fr>
date Sat, 07 Nov 2020 19:26:51 +0100
parents 7103d6574062
children d6f217a5e4b1
line wrap: on
line source

/*
 * util.h -- utilities
 *
 * Copyright (c) 2020 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 MOLKO_UTIL_H
#define MOLKO_UTIL_H

/**
 * \file util.h
 * \brief Utilities.
 * \ingroup basics
 *
 * This file contains several utilities.
 *
 * \note In contrast to other files, identifiers are not prefixed with `util_`
 *       for convenience.
 */

#include <stdarg.h>
#include <stddef.h>

#include "plat.h"

/**
 * Get the number of elements in a static array.
 *
 * \param x the array
 * \return the number of elements
 */
#define NELEM(x) sizeof ((x)) / sizeof ((x)[0])

/**
 * Put the thread to sleep for a given amount of milliseconds.
 *
 * \param ms the number of milliseconds to wait
 */
void
delay(unsigned int ms);

/**
 * Generate a random number between lower and upper (included).
 *
 * \pre upper must be <= RAND_MAX
 * \param lower the lower bound
 * \param upper the upper bound
 * \return The generated number.
 */
unsigned int
nrand(unsigned int lower, unsigned int upper);

#endif /* !MOLKO_UTIL_H */