ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
os.h
Go to the documentation of this file.
1 #ifndef OS_H
2 #define OS_H
3 
4 // OS definitions
5 
6 #ifdef __linux
7 #define OS_LINUX
8 #endif
9 #ifdef __APPLE__
10 #define OS_MAC
11 #endif
12 
13 #if !defined(OS_LINUX) && !defined(OS_MAC)
14 #error Your OS is not supported. Edit os.h if you want to compile anyway.
15 #endif
16 
17 // OS-specific includes
18 
19 #ifdef OS_LINUX
20 
21 #ifndef _DEFAULT_SOURCE
22 #define _DEFAULT_SOURCE
23 #endif
24 
25 #ifndef _GNU_SOURCE
26 #define _GNU_SOURCE
27 #endif
28 
29 #include <features.h>
30 #include <libudev.h>
31 #include <linux/uinput.h>
32 #include <linux/usbdevice_fs.h>
33 
34 #ifndef UINPUT_VERSION
35 #define UINPUT_VERSION 2
36 #endif
37 
38 // The OSX process needs to change its EUID to post events, so thread safety must be ensured
39 // On Linux the EUID is always root
40 #define euid_guard_start
41 #define euid_guard_stop
42 
43 #endif // OS_LINUX
44 
45 #ifdef OS_MAC
46 
47 #define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 1
48 #include <AssertMacros.h>
49 
50 #include <Availability.h>
51 #include <Carbon/Carbon.h>
52 #include <IOKit/IOMessage.h>
53 #include <IOKit/hid/IOHIDDevicePlugin.h>
54 #include <IOKit/hid/IOHIDLib.h>
55 #include <IOKit/hidsystem/IOHIDLib.h>
56 #include <IOKit/hidsystem/ev_keymap.h>
57 #include <IOKit/usb/IOUSBLib.h>
58 #include <IOKit/usb/USB.h>
59 
60 typedef IOHIDDeviceDeviceInterface** hid_dev_t;
61 typedef IOUSBDeviceInterface182** usb_dev_t;
62 typedef IOUSBInterfaceInterface183** usb_iface_t;
63 
64 // The OSX process needs to change its EUID to post events, so thread safety must be ensured
65 // On Linux the EUID is always root
66 extern pthread_mutex_t _euid_guard;
67 #define euid_guard_start pthread_mutex_lock(&_euid_guard)
68 #define euid_guard_stop pthread_mutex_unlock(&_euid_guard)
69 
70 // Various POSIX functions that aren't present on OSX
71 
72 void *memrchr(const void *s, int c, size_t n);
73 
74 #if __MAC_OS_X_VERSION_MAX_ALLOWED < 101200
75 typedef int clockid_t;
76 #define CLOCK_MONOTONIC 1
77 #endif
78 
79 #define TIMER_ABSTIME 1
80 
81 int clock_gettime(clockid_t clk_id, struct timespec *tp);
82 int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp);
83 
84 #endif // OS_MAC
85 
86 #endif // OS_H