2 #ifndef ELOGIND_BASIC_MUSL_MISSING_H_INCLUDED
3 #define ELOGIND_BASIC_MUSL_MISSING_H_INCLUDED
6 /****************************************************************
7 * musl_missing.h - work around glibc extensions for musl libc.
9 * Implements glibc functions missing in musl libc as macros.
10 * Is to be included where these functions are used.
11 * Also defines some glibc only constants as either 0 or
12 * as found in the corresponding glibc header file.
14 * Juergen Buchmueller <pullmoll@t-online.de> for Void Linux
15 * Public Domain; no warranties whatsoever. Thank you Mr. P.
17 ****************************************************************/
20 void elogind_set_program_name(const char* pcall);
22 #if !defined(__GLIBC__)
28 #define strerror_r(e, m, k) (strerror_r(e, m, k) < 0 ? strdup("strerror_r() failed") : m);
31 extern char *program_invocation_name;
32 extern char *program_invocation_short_name;
33 #endif // errno.h included beforehand
36 * Possibly TODO according to http://man7.org/linux/man-pages/man3/getenv.3.html
37 * + test if the process's effective user ID does not match its real user ID or
38 * the process's effective group ID does not match its real group ID;
39 * typically this is the result of executing a set-user-ID or set-
40 * group-ID program. Is calling issetugid() sufficient here?
41 * + test if the effective capability bit was set on the executable file
42 * + test if the process has a nonempty permitted capability set
44 #if ! HAVE_SECURE_GETENV && ! HAVE___SECURE_GETENV
45 # define secure_getenv(name) \
46 (issetugid() ? NULL : getenv(name))
47 # undef HAVE_SECURE_GETENV
48 # define HAVE_SECURE_GETENV 1
49 #endif // HAVE_[__]SECURE_GETENV
51 /* Poor man's basename */
52 #define basename(path) \
53 (strrchr(path, '/') ? strrchr(path, '/')+1 : path)
55 /* strndupa may already be defined in another compatibility header */
56 #if !defined(strndupa)
57 #define strndupa(src, n) \
58 (__extension__ ({const char *in = (src); \
59 size_t len = strnlen(in, (n)) + 1; \
60 char *out = (char *) alloca(len); \
62 (char *) memcpy(out, in, len-1);}) \
66 /* See http://man7.org/linux/man-pages/man3/canonicalize_file_name.3.html */
67 #define canonicalize_file_name(path) \
70 /* GLOB_BRACE is another glibc extension - ignore it for musl libc */
73 /* getnameinfo(3) glibc extensions are undefined in musl libc */
75 #define NI_IDN_USE_STD3_ASCII_RULES 0
77 /* Taken from glibc's net/if_arp.h */
78 #if !defined(ARPHRD_IEEE802154_PHY)
79 #define ARPHRD_IEEE802154_PHY 805 /* IEEE 802.15.4 PHY header. */
82 /* Shorthand for type of comparison functions. */
84 # define __COMPAR_FN_T
85 typedef int (*__compar_fn_t) (const void *, const void *);
86 typedef __compar_fn_t comparison_fn_t;
89 /* Make musl utmp/wtmp stubs visible if needed. */
94 # if defined(_PATH_UTMP) && !defined(_PATH_UTMPX)
95 # define _PATH_UTMPX _PATH_UTMP
97 # if defined(_PATH_WTMP) && !defined(_PATH_WTMPX)
98 # define _PATH_WTMPX _PATH_WTMP
100 #endif // ENABLE_UTMP
102 #endif // !defined(__GLIBC__)
104 #endif // ELOGIND_BASIC_MUSL_MISSING_H_INCLUDED