[PATCH libinput] FreeBSD portability fixes
Greg V
greg at unrelenting.technology
Thu Nov 23 18:15:27 UTC 2017
- some items in meson were missing a dependency on udev
- libdl does not exist on FreeBSD, dlopen is in libc
- no linux/types.h on FreeBSD
- stdarg.h included when variadic functions are used
- and other fixes
---
include/linux/input.h | 11 +++++++++++
meson.build | 9 +++++++--
src/evdev.h | 1 +
src/libinput-private.h | 1 +
src/libinput-util.h | 4 ++++
src/libinput.c | 1 +
src/libinput.h | 1 +
test/litest.c | 27 +++++++++++++++++++++++++--
test/litest.h | 1 +
test/test-log.c | 1 +
test/test-misc.c | 1 +
test/test-pointer.c | 2 ++
test/test-tablet.c | 1 +
tools/libinput-debug-events.c | 1 +
tools/libinput-debug-gui.c | 1 +
tools/ptraccel-debug.c | 8 +++++++-
16 files changed, 66 insertions(+), 5 deletions(-)
diff --git a/include/linux/input.h b/include/linux/input.h
index 06316b27..95134d8e 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -11,7 +11,18 @@
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/types.h>
+#ifdef __FreeBSD__
+#define __u8 uint8_t
+#define __u16 uint16_t
+#define __u32 uint32_t
+#define __u64 uint64_t
+#define __s16 int16_t
+#define __s32 int32_t
+#define _IOC_READ IOC_OUT
+#define _IOC_WRITE IOC_IN
+#else
#include <linux/types.h>
+#endif
#include "input-event-codes.h"
diff --git a/meson.build b/meson.build
index 13c6a27f..5d9db605 100644
--- a/meson.build
+++ b/meson.build
@@ -145,7 +145,9 @@ src_libfilter = [
'src/filter.h',
'src/filter-private.h'
]
-libfilter = static_library('filter', src_libfilter)
+libfilter = static_library('filter', src_libfilter,
+ dependencies : dep_udev,
+ include_directories : includes_include)
dep_libfilter = declare_dependency(link_with : libfilter)
############ libinput.so ############
@@ -598,7 +600,7 @@ if get_option('tests')
'test/litest.c'
]
- dep_dl = cc.find_library('dl')
+ dep_dl = cc.find_library('dl', required : false)
deps_litest = [
dep_libinput,
dep_check,
@@ -689,12 +691,14 @@ if get_option('tests')
# build-test only
executable('test-build-pedantic',
'test/build-pedantic.c',
+ dependencies : [dep_udev],
include_directories : [includes_src, includes_include],
c_args : ['-std=c99', '-pedantic', '-Werror'],
install : false)
# build-test only
executable('test-build-std-gnuc90',
'test/build-pedantic.c',
+ dependencies : [dep_udev],
include_directories : [includes_src, includes_include],
c_args : ['-std=gnu90', '-Werror'],
install : false)
@@ -707,6 +711,7 @@ if get_option('tests')
# test including from C++
executable('test-build-cxx',
'test/build-cxx.cc',
+ dependencies : [dep_udev],
include_directories : [includes_src, includes_include],
install : false)
diff --git a/src/evdev.h b/src/evdev.h
index 11ed7da5..75223852 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -29,6 +29,7 @@
#include "config.h"
#include <stdbool.h>
+#include <stdarg.h>
#include "linux/input.h"
#include <libevdev/libevdev.h>
diff --git a/src/libinput-private.h b/src/libinput-private.h
index a59cb08e..d50154ef 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -29,6 +29,7 @@
#include <errno.h>
#include <math.h>
+#include <stdarg.h>
#include "linux/input.h"
diff --git a/src/libinput-util.h b/src/libinput-util.h
index 57bcdbb5..a4522f6b 100644
--- a/src/libinput-util.h
+++ b/src/libinput-util.h
@@ -30,7 +30,11 @@
#include <assert.h>
#include <errno.h>
#include <limits.h>
+#ifdef __FreeBSD__
+#include <xlocale.h>
+#else
#include <locale.h>
+#endif
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
diff --git a/src/libinput.c b/src/libinput.c
index 49de8f27..d85693a4 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -28,6 +28,7 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <string.h>
#include <sys/epoll.h>
#include <unistd.h>
diff --git a/src/libinput.h b/src/libinput.h
index 1a06bc7c..759bce91 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -31,6 +31,7 @@ extern "C" {
#include <stdlib.h>
#include <stdint.h>
+#include <stdarg.h>
#include <libudev.h>
#define LIBINPUT_ATTRIBUTE_PRINTF(_format, _args) \
diff --git a/test/litest.c b/test/litest.c
index 3ca319c2..c27c2369 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -36,12 +36,17 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <time.h>
#include <unistd.h>
#include "linux/input.h"
#include <sys/ptrace.h>
#include <sys/resource.h>
+#ifdef __linux__
#include <sys/sendfile.h>
+#elif __FreeBSD__
+#include <sys/socket.h>
+#endif
#include <sys/timerfd.h>
#include <sys/wait.h>
#include <sys/stat.h>
@@ -1031,7 +1036,13 @@ litest_copy_file(const char *dest, const char *src, const char *header)
src,
strerror(errno));
/* lazy, just check for error and empty file copy */
- litest_assert_int_gt(sendfile(out, in, NULL, 40960), 0);
+ litest_assert_int_gt(
+#ifdef __linux__
+ sendfile(out, in, NULL, 40960)
+#elif __FreeBSD__
+ sendfile(out, in, 0, 40960, NULL, NULL, 0)
+#endif
+ , 0);
close(out);
close(in);
@@ -3536,10 +3547,17 @@ is_debugger_attached(void)
if (pid == 0) {
int ppid = getppid();
+#ifdef __linux__
if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) == 0) {
waitpid(ppid, NULL, 0);
ptrace(PTRACE_CONT, NULL, NULL);
ptrace(PTRACE_DETACH, ppid, NULL, NULL);
+#elif __FreeBSD__
+ if (ptrace(PT_ATTACH, ppid, NULL, 0) == 0) {
+ waitpid(ppid, NULL, 0);
+ ptrace(PT_CONTINUE, ppid, NULL, 0);
+ ptrace(PT_DETACH, ppid, NULL, 0);
+#endif
rc = 0;
} else {
rc = 1;
@@ -3608,7 +3626,12 @@ main(int argc, char **argv)
if (getuid() != 0) {
fprintf(stderr,
"%s must be run as root.\n",
- program_invocation_short_name);
+#ifdef __linux__
+ program_invocation_short_name
+#else
+ argv[0]
+#endif
+ );
return 77;
}
diff --git a/test/litest.h b/test/litest.h
index b7667ffe..faa469c0 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -27,6 +27,7 @@
#define LITEST_H
#include <stdbool.h>
+#include <stdarg.h>
#include <check.h>
#include <libevdev/libevdev.h>
#include <libevdev/libevdev-uinput.h>
diff --git a/test/test-log.c b/test/test-log.c
index 2705a81e..02ff0185 100644
--- a/test/test-log.c
+++ b/test/test-log.c
@@ -28,6 +28,7 @@
#include <fcntl.h>
#include <libinput.h>
#include <unistd.h>
+#include <stdarg.h>
#include "litest.h"
diff --git a/test/test-misc.c b/test/test-misc.c
index 32081c03..94cbfcc1 100644
--- a/test/test-misc.c
+++ b/test/test-misc.c
@@ -29,6 +29,7 @@
#include <libinput.h>
#include <libinput-util.h>
#include <unistd.h>
+#include <stdarg.h>
#include "litest.h"
#include "libinput-util.h"
diff --git a/test/test-pointer.c b/test/test-pointer.c
index 7324c0f6..14801aeb 100644
--- a/test/test-pointer.c
+++ b/test/test-pointer.c
@@ -30,7 +30,9 @@
#include <libinput.h>
#include <math.h>
#include <unistd.h>
+#ifdef __linux__
#include <values.h>
+#endif
#include "libinput-util.h"
#include "litest.h"
diff --git a/test/test-tablet.c b/test/test-tablet.c
index 218b6e40..bc089389 100644
--- a/test/test-tablet.c
+++ b/test/test-tablet.c
@@ -29,6 +29,7 @@
#include <libinput.h>
#include <unistd.h>
#include <stdbool.h>
+#include <stdarg.h>
#include "libinput-util.h"
#include "evdev-tablet.h"
diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c
index 56810c57..33f51d0e 100644
--- a/tools/libinput-debug-events.c
+++ b/tools/libinput-debug-events.c
@@ -29,6 +29,7 @@
#include <getopt.h>
#include <poll.h>
#include <stdio.h>
+#include <stdarg.h>
#include <signal.h>
#include <string.h>
#include <time.h>
diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c
index 43ae5499..ab49ad66 100644
--- a/tools/libinput-debug-gui.c
+++ b/tools/libinput-debug-gui.c
@@ -31,6 +31,7 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <string.h>
#include <unistd.h>
diff --git a/tools/ptraccel-debug.c b/tools/ptraccel-debug.c
index 93be523f..262b8587 100644
--- a/tools/ptraccel-debug.c
+++ b/tools/ptraccel-debug.c
@@ -190,7 +190,13 @@ print_accel_func_trackpoint(struct motion_filter *filter,
static void
usage(void)
{
- printf("Usage: %s [options] [dx1] [dx2] [...] > gnuplot.data\n", program_invocation_short_name);
+ printf("Usage: %s [options] [dx1] [dx2] [...] > gnuplot.data\n",
+#ifdef __linux__
+ program_invocation_short_name
+#else
+ "ptraccel-debug"
+#endif
+ );
printf("\n"
"Options:\n"
"--mode=<motion|accel|delta|sequence> \n"
--
2.15.0
More information about the wayland-devel
mailing list