1#ifndef RM_CONFIG_H
2#define RM_CONFIG_H
3
4#define INSTALL_PREFIX "{INSTALL_PREFIX}"
5
6#define HAVE_BLKID         ({HAVE_BLKID})
7#define HAVE_LIBINTL       ({HAVE_LIBINTL})
8#define HAVE_LIBELF        ({HAVE_LIBELF})
9#define HAVE_JSON_GLIB     ({HAVE_JSON_GLIB})
10#define HAVE_GIO_UNIX      ({HAVE_GIO_UNIX})
11#define HAVE_FIEMAP        ({HAVE_FIEMAP})
12#define HAVE_XATTR         ({HAVE_XATTR})
13#define HAVE_LXATTR        ({HAVE_LXATTR})
14#define HAVE_SHA512        ({HAVE_SHA512})
15#define HAVE_BIGFILES      ({HAVE_BIGFILES})
16#define HAVE_STAT64        ({HAVE_STAT64})
17#define HAVE_BIG_OFF_T     ({HAVE_BIG_OFF_T})
18#define HAVE_SYSBLOCK      ({HAVE_SYSBLOCK})
19#define HAVE_LINUX_LIMITS  ({HAVE_LINUX_LIMITS})
20#define HAVE_POSIX_FADVISE ({HAVE_POSIX_FADVISE})
21#define HAVE_BTRFS_H       ({HAVE_BTRFS_H})
22#define HAVE_LINUX_FS_H    ({HAVE_LINUX_FS_H})
23#define HAVE_UNAME         ({HAVE_UNAME})
24#define HAVE_SYSMACROS_H   ({HAVE_SYSMACROS_H})
25#define HAVE_MM_CRC32_U64  ({HAVE_MM_CRC32_U64})
26#define HAVE_BUILTIN_CPU_SUPPORTS ({HAVE_BUILTIN_CPU_SUPPORTS})
27
28/* define here so rmlint and hash utility can both access */
29#define RM_DEFAULT_DIGEST RM_DIGEST_BLAKE2B
30
31#define RM_VERSION "{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}"
32#define RM_VERSION_MAJOR {VERSION_MAJOR}
33#define RM_VERSION_MINOR {VERSION_MINOR}
34#define RM_VERSION_PATCH {VERSION_PATCH}
35#define RM_VERSION_NAME  "{VERSION_NAME}"
36#define RM_VERSION_GIT_REVISION "{VERSION_GIT_REVISION}"
37
38#define RM_MANPAGE_USE_PAGER (1)
39
40/* Might come in useful */
41#define RM_CHECK_VERSION(X,Y,Z) (0  \
42    || X <= RM_VERSION_MAJOR        \
43    || Y <= RM_VERSION_MINOR        \
44    || Z <= RM_VERSION_MICRO        \
45)
46
47/* These colors should only be used with the rm_log_* macros below */
48#define RED    "\x1b[31;01m"
49#define YELLOW "\x1b[33;01m"
50#define RESET  "\x1b[0m"
51#define GREEN  "\x1b[32;01m"
52#define BLUE   "\x1b[34;01m"
53
54#include <errno.h>
55
56#if HAVE_LINUX_LIMITS
57#include <linux/limits.h>
58#else
59# ifndef PATH_MAX
60#  define PATH_MAX 4096
61# endif
62#endif
63
64#define rm_log_debug(...) \
65    g_log("rmlint", G_LOG_LEVEL_DEBUG, __VA_ARGS__)
66#define rm_log_info(...) \
67    g_log("rmlint", G_LOG_LEVEL_INFO, __VA_ARGS__)
68#define rm_log_warning(...) \
69    g_log("rmlint", G_LOG_LEVEL_WARNING, __VA_ARGS__)
70#define rm_log_error(...) \
71    g_log("rmlint", G_LOG_LEVEL_CRITICAL, __VA_ARGS__)
72
73#define rm_log_perror(message)                                                           \
74    if(errno) {{                                                                         \
75        rm_log_error_line("%s:%d: %s: %s", __FILE__, __LINE__, message, g_strerror(errno)); \
76    }}                                                                                   \
77
78#define rm_log_perrorf(message, ...)                                \
79    if(errno) {{                                                    \
80        int _errsv = errno;                                         \
81        char *msg = g_strdup_printf(message, __VA_ARGS__);          \
82        rm_log_error_line("%s:%d: %s: %s", __FILE__, __LINE__, msg, \
83                          g_strerror(_errsv));                      \
84        g_free(msg);                                                \
85    }}
86
87#define _UNUSED G_GNUC_UNUSED
88#define LLU G_GUINT64_FORMAT
89#define LLI G_GINT64_FORMAT
90
91
92#define RM_PLATFORM_32 (UINTPTR_MAX == 0xffffffff)
93#define RM_PLATFORM_64 (UINTPTR_MAX == 0xffffffffffffffff)
94
95#ifdef __APPLE__
96# ifdef __MACH__
97#  define RM_IS_APPLE 1
98# endif
99#endif
100
101#ifdef __CYGWIN__
102# define RM_IS_CYGWIN 1
103#endif
104
105#include <glib.h>
106
107/* Printf formatting for large integers */
108#include <inttypes.h>
109
110#define RM_GETTEXT_PACKAGE "rmlint"
111
112#if HAVE_LIBINTL
113#  define _(String) gettext (String)
114#  define gettext_noop(String) String
115#  define N_(String) gettext_noop (String)
116#  include <libintl.h>
117#else
118#  define _(String) (String)
119#  define gettext_noop(String) String
120#  define N_(String) gettext_noop (String)
121#endif
122
123static inline GMutex* rm_log_get_mutex(void) {{
124    static GMutex RM_LOG_MTX;
125    return &RM_LOG_MTX;
126}}
127
128#define RM_LOG_INIT \
129    g_mutex_init(rm_log_get_mutex());
130
131typedef guint64 RmOff;
132
133/* Stupid macros to make printing error lines easier */
134#define rm_log_error_prefix()    \
135    rm_log_error(RED);           \
136    rm_log_error(_("ERROR"));    \
137    rm_log_error(": "RESET);     \
138
139#define rm_log_warning_prefix()   \
140    rm_log_warning(YELLOW);       \
141    rm_log_warning(_("WARNING")); \
142    rm_log_warning(": "RESET);    \
143
144#define rm_log_info_prefix()      \
145    rm_log_warning(GREEN);        \
146    rm_log_warning(_("INFO"));    \
147    rm_log_warning(": "RESET);    \
148
149#define rm_log_debug_prefix()    \
150    rm_log_debug(BLUE);          \
151    rm_log_debug(_("DEBUG"));    \
152    rm_log_debug(": "RESET);     \
153
154///////////////
155
156#define rm_log_error_line(...)           \
157    g_mutex_lock(rm_log_get_mutex());    \
158    rm_log_error_prefix()                \
159    rm_log_error(__VA_ARGS__);           \
160    rm_log_error("\n");                  \
161    g_mutex_unlock(rm_log_get_mutex());  \
162
163#define rm_log_warning_line(...)         \
164    g_mutex_lock(rm_log_get_mutex());    \
165    rm_log_warning_prefix()              \
166    rm_log_warning(__VA_ARGS__);         \
167    rm_log_warning("\n");                \
168    g_mutex_unlock(rm_log_get_mutex());  \
169
170#define rm_log_info_line(...)            \
171    g_mutex_lock(rm_log_get_mutex());    \
172    rm_log_info_prefix()                 \
173    rm_log_warning(__VA_ARGS__);         \
174    rm_log_warning("\n");                \
175    g_mutex_unlock(rm_log_get_mutex());  \
176
177#define rm_log_debug_line(...)           \
178    g_mutex_lock(rm_log_get_mutex());    \
179    rm_log_debug_prefix()                \
180    rm_log_debug(__VA_ARGS__);           \
181    rm_log_debug("\n");                  \
182    g_mutex_unlock(rm_log_get_mutex());  \
183
184/* Domain for reporting errors. Needed by GOptions */
185#define RM_ERROR_QUARK (g_quark_from_static_string("rmlint"))
186
187#ifdef RM_DEBUG
188    #undef NDEBUG
189#else
190    #ifndef NDEBUG
191        #define NDEBUG
192    #endif
193    #ifdef __GNUC__
194        #define INLINE inline __attribute__((__always_inline__))
195    #elif defined(__CLANG__)
196        #if __has_attribute(__always_inline__)
197            #define INLINE inline __attribute__((__always_inline__))
198        #endif
199    #elif defined(_MSC_VER)
200        #define INLINE __forceinline
201    #endif
202#endif
203
204#ifndef INLINE
205    #define INLINE inline
206#endif
207
208#ifdef __GNUC__
209    #define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
210#elif defined(__CLANG__)
211    #define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
212#else
213    /* give up */
214    #define WARN_UNUSED_RESULT
215#endif
216
217#endif
218