comparison 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
comparison
equal deleted inserted replaced
431:8f59201dc76b 432:38cf60f5a1c4
1 /*
2 * util.h -- miscellaneous utilities
3 *
4 * Copyright (c) 2020-2022 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef MLK_PORT_H
20 #define MLK_PORT_H
21
22 #include <limits.h>
23 #include <stdio.h>
24
25 /*
26 * This file helps finding what are the available features accross the various
27 * operating system in the landscape.
28 *
29 * The following macros are automatically set depending on the operating
30 * system:
31 *
32 * - MLK_OS_WINDOWS: running on any Windows machine
33 * - MLK_OS_POSIX: every mostly POSIX systems
34 *
35 * The following macro will be automatically defined unless the user override
36 * them:
37 *
38 * - MLK_HAS_FMEMOPEN: defined if fmemopen function is available.
39 * - MLK_HAS_SSIZE_T: defined if ssize_t typedef is available.
40 */
41
42 #if defined(_WIN32)
43 # define MLK_OS_WINDOWS
44 #elif defined(__FreeBSD__)
45 # define MLK_OS_POSIX
46 #elif defined(__OpenBSD__)
47 # define MLK_OS_POSIX
48 #elif defined(__NetBSD__)
49 # define MLK_OS_POSIX
50 #elif defined(__linux__)
51 # define MLK_OS_POSIX
52 #elif defined(__APPLE__)
53 # define MLK_OS_POSIX
54 # define MLK_OS_APPLE
55 #endif
56
57 #if !defined(PATH_MAX)
58 # define PATH_MAX 2048
59 #endif
60
61 #if defined(MLK_OS_POSIX) && !defined(MLK_HAS_SSIZE_T)
62 # define MLK_HAS_SSIZE_T
63 #endif
64
65 #if !defined(MLK_HAS_SSIZE_T)
66 typedef long long int ssize_t;
67 #endif
68
69 #if defined(MLK_OS_POSIX) && !defined(MLK_HAS_FMEMOPEN)
70 # define MLK_HAS_FMEMOPEN
71 #endif
72
73 size_t
74 util_strlcpy(char *, const char *, size_t);
75
76 size_t
77 util_strlcat(char *, const char *, size_t);
78
79 FILE *
80 util_fmemopen(void *, size_t, const char *);
81
82 char *
83 util_basename(char *);
84
85 char *
86 util_dirname(char *);
87
88 extern int util_opterr;
89 extern int util_optind;
90 extern int util_optopt;
91 extern char *util_optarg;
92
93 int
94 util_getopt(int, char **, const char *);
95
96 #endif /* !MLK_PORT_H */