ckb-next  beta-v0.2.8 at branch testing
ckb-next driver for corsair devices
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator 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 #include <Availability.h>
48 #include <Carbon/Carbon.h>
49 #include <IOKit/IOMessage.h>
50 #include <IOKit/hid/IOHIDDevicePlugin.h>
51 #include <IOKit/hid/IOHIDLib.h>
52 #include <IOKit/hidsystem/IOHIDLib.h>
53 #include <IOKit/hidsystem/ev_keymap.h>
54 #include <IOKit/usb/IOUSBLib.h>
55 #include <IOKit/usb/USB.h>
56 
57 typedef IOHIDDeviceDeviceInterface** hid_dev_t;
58 typedef IOUSBDeviceInterface182** usb_dev_t;
59 typedef IOUSBInterfaceInterface183** usb_iface_t;
60 
61 // The OSX process needs to change its EUID to post events, so thread safety must be ensured
62 // On Linux the EUID is always root
63 extern pthread_mutex_t _euid_guard;
64 #define euid_guard_start pthread_mutex_lock(&_euid_guard)
65 #define euid_guard_stop pthread_mutex_unlock(&_euid_guard)
66 
67 // Various POSIX functions that aren't present on OSX
68 
69 void *memrchr(const void *s, int c, size_t n);
70 
71 #if __MAC_OS_X_VERSION_MAX_ALLOWED < 101200
72 typedef int clockid_t;
73 #define CLOCK_MONOTONIC 1
74 #endif
75 
76 #define TIMER_ABSTIME 1
77 
78 int clock_gettime(clockid_t clk_id, struct timespec *tp);
79 int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, struct timespec *rmtp);
80 
81 #endif // OS_MAC
82 
83 #endif // OS_H