mirror of
https://github.com/AuxXxilium/kmod.git
synced 2024-11-23 15:00:52 +07:00
11eb9bc67c
musl has removed the non-prototype declaration of basename from string.h [1] which now results in build errors with clang-17+ compiler Implement GNU basename behavior using strchr which is portable across libcs Fixes ../git/tools/kmod.c:71:19: error: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 71 | "Commands:\n", basename(argv[0])); | ^ [1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7 Suggested-by: Rich Felker Signed-off-by: Khem Raj <raj.khem@gmail.com> [ Implement a basename() function in missing.h and ensure we always use the right include rather than having a separate gnu_basename() ] Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
70 lines
1.3 KiB
C
70 lines
1.3 KiB
C
#pragma once
|
|
|
|
#include <unistd.h>
|
|
#include <sys/syscall.h>
|
|
|
|
#ifdef HAVE_LINUX_MODULE_H
|
|
#include <linux/module.h>
|
|
#endif
|
|
|
|
#ifndef MODULE_INIT_IGNORE_MODVERSIONS
|
|
# define MODULE_INIT_IGNORE_MODVERSIONS 1
|
|
#endif
|
|
|
|
#ifndef MODULE_INIT_IGNORE_VERMAGIC
|
|
# define MODULE_INIT_IGNORE_VERMAGIC 2
|
|
#endif
|
|
|
|
#ifndef MODULE_INIT_COMPRESSED_FILE
|
|
# define MODULE_INIT_COMPRESSED_FILE 4
|
|
#endif
|
|
|
|
#ifndef __NR_finit_module
|
|
# define __NR_finit_module -1
|
|
#endif
|
|
|
|
#ifndef HAVE_FINIT_MODULE
|
|
#include <errno.h>
|
|
|
|
static inline int finit_module(int fd, const char *uargs, int flags)
|
|
{
|
|
if (__NR_finit_module == -1) {
|
|
errno = ENOSYS;
|
|
return -1;
|
|
}
|
|
|
|
return syscall(__NR_finit_module, fd, uargs, flags);
|
|
}
|
|
#endif
|
|
|
|
#if !HAVE_DECL_STRNDUPA
|
|
#include <string.h>
|
|
#define strndupa(s, n) \
|
|
({ \
|
|
const char *__old = (s); \
|
|
size_t __len = strnlen(__old, (n)); \
|
|
char *__new = alloca(__len + 1); \
|
|
__new[__len] = '\0'; \
|
|
memcpy(__new, __old, __len); \
|
|
})
|
|
#endif
|
|
|
|
#if !HAVE_DECL_BASENAME
|
|
#include <string.h>
|
|
static inline const char *basename(const char *s)
|
|
{
|
|
const char *p = strrchr(s, '/');
|
|
return p ? p + 1 : s;
|
|
}
|
|
#endif
|
|
|
|
#if !HAVE_DECL_BE32TOH
|
|
#include <endian.h>
|
|
#include <byteswap.h>
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
#define be32toh(x) bswap_32 (x)
|
|
#else
|
|
#define be32toh(x) (x)
|
|
#endif
|
|
#endif
|