forked from PterodonRecovery/pterodon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.h
134 lines (100 loc) · 3.86 KB
/
constants.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
Pterodon - Macro definitions
Copyright (C) <2019> ATGDroid <[email protected]>
This file is part of Pterodon Recovery
Pterodon is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Pterodon is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Pterodon. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _PTERO_CONSTANTS_H
#define _PTERO_CONSTANTS_H
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <unistd.h> // TEMP_FAILURE_RETRY
#include <stdio.h>
#include "common.h"
/* enable for debugging */
#define PTERODON_DEBUG_MODE
/* enable for debugging of the AOSP property api */
//#define PTERODON_PROPERTYSERVICE_DEBUG
// #include <boost/date_time/posix_time/posix_time.hpp>
/* DEFINE "VARIABLE FUNCTIONS" */
#ifndef TEMP_FAILURE_RETRY
#define TEMP_FAILURE_RETRY(exp) \
({ \
decltype(exp) _rc; \
do { \
_rc = (exp); \
} while (_rc == -1 && errno == EINTR); \
_rc; \
})
#endif
/* Pterodon logging system */
#define LOGE(...) \
fprintf(stdout,"[E]: " __VA_ARGS__); \
putc('\n', stdout);
#define LOGI(...) \
fprintf(stdout,"[I]: " __VA_ARGS__); \
putc('\n', stdout);
#define LOGW(...) \
fprintf(stdout,"[W]: " __VA_ARGS__); \
putc('\n', stdout);
#ifdef PTERODON_DEBUG_MODE
#define LOGD(...) \
fprintf(stdout,"[D]: " __VA_ARGS__); \
putc('\n', stdout);
#else
//#define LOGD(...) do {} while (0)
#define LOGD(...)
#endif
#define STRINGIFY(x) #x
#define EXPAND(x) STRINGIFY(x)
#define PTERO_SQUARE(a) ((a)*(a))
#define PTERO_MAX(a, b) (a>b ? a : b)
#define PTERO_MIN(a, b) (a>b ? b : a)
#define PTERO_TO_PB(a) ((a) / (1024) / (1024) / (1024) / (1024) / (1024))
#define PTERO_TO_TB(a) ((a) / (1024) / (1024) / (1024) / (1024))
#define PTERO_TO_GB(a) ((a) / (1024) / (1024) / (1024))
#define PTERO_TO_MB(a) ((a) / (1024) / (1024))
#define PTERO_TO_KB(a) ((a) / (1024))
#define ptero_bit(x) (1 << x)
#define ptero_isSpace(c) ((c) == ' ' || (c) == '\t')
#define ptero_isAlpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
#define ptero_isDigit(c) ((uint8_t)(c) - '0' <= 9)
#define ptero_isAlphaDigit(c) ((c) >= 'a' && (c) <= 'f')
#define ptero_isHexDigit(c) (isDigit(c) || isAlphaDigit(c))
#define ptero_isAlphaNumeric(c) (isAlpha(c) || isDigit(c) || ((c) == '-'))
/* DEFINE environment paths to specific objects */
#define PTERO_COMMAND_FILE "/cache/recovery/command"
#define PTERO_CMDLINE_PATH "/proc/cmdline"
#define PTERO_TMP_LOG "/tmp/recovery.log"
#define PTERO_TMP_SIDELOAD "/tmp/sideload"
#define PTERO_LAST_LOGFILE "/cache/recovery/last_log"
#define PTERO_UPDATED_LOGFILE "/cache/recovery/log"
#define PTERO_MOUNT_ENTRY "/proc/mounts"
/* Handle ifdefs */
#ifndef PTERO_VIBRATION_DRIVER_PATH
#define PTERO_VIBRATION_DRIVER_PATH "/sys/class/timed_output/vibrator/enable"
#endif
#ifndef PTERO_USB_DRIVER_STATE
#define PTERO_USB_DRIVER_STATE "/sys/class/android_usb/android0/state"
#endif
#ifndef PTERO_MOUNT_ENTRY_FILE
#define PTERO_MOUNT_ENTRY_FILE "/proc/mounts"
#endif
#ifndef PTERO_LEDS_PATH
#define PTERO_LEDS_PATH "/sys/class/leds/green"
#endif
#ifndef PTERO_BATTERY_DRIVER_PATH
#define PTERO_BATTERY_DRIVER_PATH "/sys/class/power_supply/battery"
#endif
/* DEFINE recovery specific variables */
#endif // _PTERO_CONSTANTS_H