]> git.ipfire.org Git - thirdparty/kmod.git/blob - shared/missing.h
libkmod: add fallback MODULE_INIT_COMPRESSED_FILE define
[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 MODULE_INIT_COMPRESSED_FILE
19 # define MODULE_INIT_COMPRESSED_FILE 4
20 #endif
21
22 #ifndef __NR_finit_module
23 # define __NR_finit_module -1
24 #endif
25
26 #ifndef HAVE_FINIT_MODULE
27 #include <errno.h>
28
29 static inline int finit_module(int fd, const char *uargs, int flags)
30 {
31 if (__NR_finit_module == -1) {
32 errno = ENOSYS;
33 return -1;
34 }
35
36 return syscall(__NR_finit_module, fd, uargs, flags);
37 }
38 #endif
39
40 #if !HAVE_DECL_STRNDUPA
41 #define strndupa(s, n) \
42 ({ \
43 const char *__old = (s); \
44 size_t __len = strnlen(__old, (n)); \
45 char *__new = alloca(__len + 1); \
46 __new[__len] = '\0'; \
47 memcpy(__new, __old, __len); \
48 })
49 #endif
50
51 #if !HAVE_DECL_BE32TOH
52 #include <endian.h>
53 #include <byteswap.h>
54 #if __BYTE_ORDER == __LITTLE_ENDIAN
55 #define be32toh(x) bswap_32 (x)
56 #else
57 #define be32toh(x) (x)
58 #endif
59 #endif