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
includes.h
Go to the documentation of this file.
1 #ifndef INCLUDES_H
2 #define INCLUDES_H
3 
4 #include "os.h"
5 
6 #include <ctype.h>
7 #include <dirent.h>
8 #include <fcntl.h>
9 #include <iconv.h>
10 #include <pthread.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <time.h>
15 #include <unistd.h>
16 
17 #include <sys/errno.h>
18 #include <sys/ioctl.h>
19 #include <sys/signal.h>
20 #include <sys/stat.h>
21 #include <sys/time.h>
22 
23 // Unsigned char/short definition
24 typedef unsigned char uchar;
25 typedef unsigned short ushort;
26 // Gets the index of an object within an array
27 #define INDEX_OF(entry, array) (int)(entry - array)
28 
29 // Compile with -DCKB_OUTPUT_TO_STDERR if you want to separate error messages from normal status updates.
30 // (probably not useful because the errors don't mean much without context)
31 #ifdef CKB_OUTPUT_TO_STDERR
32 #define ckb_s_out stdout
33 #define ckb_s_err stderr
34 #else
35 #define ckb_s_out stdout
36 #define ckb_s_err stdout
37 #endif
38 
39 // Better __FILE__ macro
40 #define __FILE_NOPATH__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
41 
42 // Output helpers
43 // Use ckb_* to output info or ckb_*_fn to override the file/line numbers (useful when describing where a function was invoked from)
44 #define ckb_fatal_nofile(fmt, args...) fprintf(ckb_s_err, "[F] " fmt, ## args)
45 #define ckb_fatal_fn(fmt, file, line, args...) fprintf(ckb_s_err, "[F] %s (via %s:%d): " fmt, __func__, file, line, ## args)
46 #define ckb_fatal(fmt, args...) fprintf(ckb_s_err, "[F] %s (%s:%d): " fmt, __func__, __FILE_NOPATH__, __LINE__, ## args)
47 #define ckb_err_nofile(fmt, args...) fprintf(ckb_s_err, "[E] " fmt, ## args)
48 #define ckb_err_fn(fmt, file, line, args...) fprintf(ckb_s_err, "[E] %s (via %s:%d): " fmt, __func__, file, line, ## args)
49 #define ckb_err(fmt, args...) fprintf(ckb_s_err, "[E] %s (%s:%d): " fmt, __func__, __FILE_NOPATH__, __LINE__, ## args)
50 #define ckb_warn_nofile(fmt, args...) fprintf(ckb_s_out, "[W] " fmt, ## args)
51 #define ckb_warn_fn(fmt, file, line, args...) fprintf(ckb_s_out, "[W] %s (via %s:%d): " fmt, __func__, file, line, ## args)
52 #define ckb_warn(fmt, args...) fprintf(ckb_s_out, "[W] %s (%s:%d): " fmt, __func__, __FILE_NOPATH__, __LINE__, ## args)
53 #define ckb_info_nofile(fmt, args...) fprintf(ckb_s_out, "[I] " fmt, ## args)
54 #define ckb_info_fn(fmt, file, line, args...) fprintf(ckb_s_out, "[I] " fmt, ## args)
55 #define ckb_info(fmt, args...) fprintf(ckb_s_out, "[I] " fmt, ## args)
56 
57 // Timespec utilities
58 void timespec_add(struct timespec* timespec, long nanoseconds);
59 #define timespec_gt(left, right) ((left).tv_sec > (right).tv_sec || ((left).tv_sec == (right).tv_sec && (left).tv_nsec > (right).tv_nsec))
60 #define timespec_eq(left, right) ((left).tv_sec == (right).tv_sec && (left).tv_nsec == (right).tv_nsec)
61 #define timespec_ge(left, right) ((left).tv_sec > (right).tv_sec || ((left).tv_sec == (right).tv_sec && (left).tv_nsec >= (right).tv_nsec))
62 #define timespec_lt(left, right) (!timespec_ge(left, right))
63 #define timespec_le(left, right) (!timespec_gt(left, right))
64 
65 // Common structs
66 #include "structures.h"
67 
68 #endif // INCLUDES_H
unsigned char uchar
Definition: includes.h:24
unsigned short ushort
Definition: includes.h:25
void timespec_add(struct timespec *timespec, long nanoseconds)
Definition: main.c:19