truck-code
common.h
Go to the documentation of this file.
1 
13 #include <setjmp.h> /* jmp_buf, setjmp, longjmp */
14 #include <sys/iofunc.h> /* SIGINT, SIGQUIT, SIGTERM, SIGALRM */
15 
16 
17 #ifndef INCLUDE_UTILS_COMMON_H_
18 #define INCLUDE_UTILS_COMMON_H_
19 
20 
21 /* -------------------------------------------------------------------------- */
22 /* -------------------- Definitions for common constants -------------------- */
23 /* -------------------------------------------------------------------------- */
24 
25 
26 #define ERROR -1
27 #define END_OF_STRING ((char)'\0')
28 #define MAX_LINE_LEN 132
29 #define ERROR_LONG (-1L)
30 #define ASC_EQUAL_SIGN '='
31 #define ASC_LEFT_ARRAY '['
34 /* -------------------------------------------------------------------------- */
35 /* --------------------- Definitions for common objects --------------------- */
36 /* -------------------------------------------------------------------------- */
37 
38 
39 typedef unsigned char BYTE;
40 typedef unsigned char BIT;
43 /* -------------------------------------------------------------------------- */
44 /* ----------------- Signal messages (used in CAN for now) ------------------ */
45 /* -------------------------------------------------------------------------- */
46 
47 
49 static int sig_list[] = {
50  SIGINT,
51  SIGQUIT,
52  SIGTERM,
53  SIGALRM, // for timer
54  ERROR
55 };
56 
57 
59 static jmp_buf exit_env;
60 
61 
67 static void sig_hand(int code) {
68  if (code == SIGALRM)
69  return;
70  else
71  longjmp(exit_env, code);
72 }
73 
74 
87 static void sig_ign(int *sig_list, void sig_hand(int sig)) {
88  int i = 0;
89  while (sig_list[i] != ERROR) {
90  signal(sig_list[i], sig_hand);
91  i++;
92  }
93 }
94 
95 
96 #endif /* INCLUDE_UTILS_COMMON_H_ */
unsigned char BYTE
Definition: common.h:39
#define ERROR
Definition: common.h:26
unsigned char BIT
Definition: common.h:40