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 !defined(HAVE_SECURE_GETENV) && !defined(HAVE___SECURE_GETENV)
45 # define secure_getenv(name) \
46 (issetugid() ? NULL : getenv(name))
47 # define HAVE_SECURE_GETENV 1
48 #endif // HAVE_[__]SECURE_GETENV
50 /* Poor man's basename */
51 #define basename(path) \
52 (strrchr(path, '/') ? strrchr(path, '/')+1 : path)
54 /* strndupa may already be defined in another compatibility header */
55 #if !defined(strndupa)
56 #define strndupa(src, n) \
57 (__extension__ ({const char *in = (src); \
58 size_t len = strnlen(in, (n)) + 1; \
59 char *out = (char *) alloca(len); \
61 (char *) memcpy(out, in, len-1);}) \
65 /* See http://man7.org/linux/man-pages/man3/canonicalize_file_name.3.html */
66 #define canonicalize_file_name(path) \
69 /* GLOB_BRACE is another glibc extension - ignore it for musl libc */
72 /* getnameinfo(3) glibc extensions are undefined in musl libc */
74 #define NI_IDN_USE_STD3_ASCII_RULES 0
76 /* Taken from glibc's net/if_arp.h */
77 #if !defined(ARPHRD_IEEE802154_PHY)
78 #define ARPHRD_IEEE802154_PHY 805 /* IEEE 802.15.4 PHY header. */
81 /* Shorthand for type of comparison functions. */
83 # define __COMPAR_FN_T
84 typedef int (*__compar_fn_t) (const void *, const void *);
85 typedef __compar_fn_t comparison_fn_t;
89 #endif // !defined(__GLIBC__)
91 #endif // ELOGIND_BASIC_MUSL_MISSING_H_INCLUDED