]> git.ipfire.org Git - thirdparty/kmod.git/blob - shared/missing.h
kmod 24
[thirdparty/kmod.git] / shared / missing.h
1 #pragma once
2
3 #include <unistd.h>
4 #include <sys/syscall.h>
5
6 #ifdef HAVE_LINUX_MODULE_H
7 #include <linux/module.h>
8 #endif
9
10 #ifndef MODULE_INIT_IGNORE_MODVERSIONS
11 # define MODULE_INIT_IGNORE_MODVERSIONS 1
12 #endif
13
14 #ifndef MODULE_INIT_IGNORE_VERMAGIC
15 # define MODULE_INIT_IGNORE_VERMAGIC 2
16 #endif
17
18 #ifndef __NR_finit_module
19 # define __NR_finit_module -1
20 #endif
21
22 #ifndef HAVE_FINIT_MODULE
23 #include <errno.h>
24
25 static inline int finit_module(int fd, const char *uargs, int flags)
26 {
27 if (__NR_finit_module == -1) {
28 errno = ENOSYS;
29 return -1;
30 }
31
32 return syscall(__NR_finit_module, fd, uargs, flags);
33 }
34 #endif
35
36 #if !HAVE_DECL_STRNDUPA
37 #define strndupa(s, n) \
38 ({ \
39 const char *__old = (s); \
40 size_t __len = strnlen(__old, (n)); \
41 char *__new = alloca(__len + 1); \
42 __new[__len] = '\0'; \
43 memcpy(__new, __old, __len); \
44 })
45 #endif
46
47 #if !HAVE_DECL_BE32TOH
48 #include <endian.h>
49 #include <byteswap.h>
50 #if __BYTE_ORDER == __LITTLE_ENDIAN
51 #define be32toh(x) bswap_32 (x)
52 #else
53 #define be32toh(x) (x)
54 #endif
55 #endif