Mercurial > molko
diff libmlk-util/mlk/util/util.h @ 432:38cf60f5a1c4
util: cleanup hierarchy
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 15 Oct 2022 20:28:59 +0200 |
parents | src/libmlk-util/util/util.h@7d2ebc334c8c |
children | 9f062143e675 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmlk-util/mlk/util/util.h Sat Oct 15 20:28:59 2022 +0200 @@ -0,0 +1,96 @@ +/* + * util.h -- miscellaneous utilities + * + * Copyright (c) 2020-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 MLK_PORT_H +#define MLK_PORT_H + +#include <limits.h> +#include <stdio.h> + +/* + * This file helps finding what are the available features accross the various + * operating system in the landscape. + * + * The following macros are automatically set depending on the operating + * system: + * + * - MLK_OS_WINDOWS: running on any Windows machine + * - MLK_OS_POSIX: every mostly POSIX systems + * + * The following macro will be automatically defined unless the user override + * them: + * + * - MLK_HAS_FMEMOPEN: defined if fmemopen function is available. + * - MLK_HAS_SSIZE_T: defined if ssize_t typedef is available. + */ + +#if defined(_WIN32) +# define MLK_OS_WINDOWS +#elif defined(__FreeBSD__) +# define MLK_OS_POSIX +#elif defined(__OpenBSD__) +# define MLK_OS_POSIX +#elif defined(__NetBSD__) +# define MLK_OS_POSIX +#elif defined(__linux__) +# define MLK_OS_POSIX +#elif defined(__APPLE__) +# define MLK_OS_POSIX +# define MLK_OS_APPLE +#endif + +#if !defined(PATH_MAX) +# define PATH_MAX 2048 +#endif + +#if defined(MLK_OS_POSIX) && !defined(MLK_HAS_SSIZE_T) +# define MLK_HAS_SSIZE_T +#endif + +#if !defined(MLK_HAS_SSIZE_T) +typedef long long int ssize_t; +#endif + +#if defined(MLK_OS_POSIX) && !defined(MLK_HAS_FMEMOPEN) +# define MLK_HAS_FMEMOPEN +#endif + +size_t +util_strlcpy(char *, const char *, size_t); + +size_t +util_strlcat(char *, const char *, size_t); + +FILE * +util_fmemopen(void *, size_t, const char *); + +char * +util_basename(char *); + +char * +util_dirname(char *); + +extern int util_opterr; +extern int util_optind; +extern int util_optopt; +extern char *util_optarg; + +int +util_getopt(int, char **, const char *); + +#endif /* !MLK_PORT_H */