2 * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file adu.h \brief Global definitions. */
14 #include <time.h> /* time(), localtime() */
23 #include "gcc-compat.h"
24 #include "portable_io.h"
26 /** debug loglevel, gets really noisy */
28 /** still noisy, but won't fill your disk */
30 /** normal, but significant event */
32 /** unexpected event that can be handled */
34 /** unhandled error condition */
36 /** system might be unreliable */
38 /** last message before exit */
41 /** Log messages with lower priority than that will not be compiled in. */
42 #define COMPILE_TIME_LOGLEVEL 0
45 * A variant of static inline that requires the object being documented.
47 * If doxygen finds the \p static keyword in any context, that part will not be
48 * included in the documentation. However, we want static inline functions in
49 * header files to be documented while static functions in C files and
50 * statically declared variables should be left out. As a workaround for this
51 * flaw we use \p _static_inline_ for static inline functions declared in
54 #define _static_inline_ static inline
57 #if DEBUG > COMPILE_TIME_LOGLEVEL
58 #define DEBUG_LOG(f,...) __log(DEBUG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
60 #define DEBUG_LOG(...) do {;} while (0)
63 #if INFO > COMPILE_TIME_LOGLEVEL
64 #define INFO_LOG(f,...) __log(INFO, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
66 #define INFO_LOG(...) do {;} while (0)
69 #if NOTICE > COMPILE_TIME_LOGLEVEL
70 #define NOTICE_LOG(f,...) __log(NOTICE, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
72 #define NOTICE_LOG(...) do {;} while (0)
75 #if WARNING > COMPILE_TIME_LOGLEVEL
76 #define WARNING_LOG(f,...) __log(WARNING, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
78 #define WARNING_LOG(...) do {;} while (0)
81 #if ERROR > COMPILE_TIME_LOGLEVEL
82 #define ERROR_LOG(f,...) __log(ERROR, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
84 #define ERROR_LOG(...) do {;} while (0)
87 #if CRIT > COMPILE_TIME_LOGLEVEL
88 #define CRIT_LOG(f,...) __log(CRIT, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
90 #define CRIT_LOG(...) do {;} while (0)
93 #if EMERG > COMPILE_TIME_LOGLEVEL
94 #define EMERG_LOG(f,...) __log(EMERG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
96 #define EMERG_LOG(...)
101 * Write a log message to a dynamically allocated string.
103 * \param fmt Usual format string.
104 * \param p Result pointer.
107 #define VSPRINTF(fmt, p) \
111 p = adu_malloc(size); \
114 /* Try to print in the allocated space. */ \
116 n = vsnprintf(p, size, fmt, ap); \
118 /* If that worked, return the string. */ \
119 if (n > -1 && n < size) \
121 /* Else try again with more space. */ \
122 if (n > -1) /* glibc 2.1 */ \
123 size = n + 1; /* precisely what is needed */ \
124 else /* glibc 2.0 */ \
125 size *= 2; /* twice the old size */ \
126 p = adu_realloc(p, size); \
130 /** Evaluates to 1 if x < y, to -1 if x > y and to 0 if x == y. */
131 #define NUM_COMPARE(x, y) ((int)((x) < (y)) - (int)((x) > (y)))
133 /** The columns of the directory table. */
134 enum dir_table_columns {
135 /** The name of the directory. */
137 /** The dir count number. */
139 /** The number of the parent directory. */
141 /** The number of bytes of all regular files. */
143 /** The number of all regular files. */
145 /** Number of columns in this table. */
149 extern struct osl_table *dir_table;
151 /** The adu command line options. */
152 extern struct gengetopt_args_info conf;
155 * The select command line options.
157 * Either given at the command line, or via the \a set command
158 * in interactive mode.
160 extern struct select_args_info select_conf;
163 * Compare two osl objects pointing to unsigned integers of 64 bit size.
165 * \param obj1 Pointer to the first integer.
166 * \param obj2 Pointer to the second integer.
168 * \return The values required for an osl compare function.
170 * \sa osl_compare_func, osl_hash_compare().
172 _static_inline_ int uint64_compare(const struct osl_object *obj1,
173 const struct osl_object *obj2)
175 uint64_t d1 = read_u64((const char *)obj1->data);
176 uint64_t d2 = read_u64((const char *)obj2->data);
186 * Compare the size of two directories
188 * \param obj1 Pointer to the first object.
189 * \param obj2 Pointer to the second object.
191 * This function first compares the size values as usual integers. If they compare as
192 * equal, the address of \a obj1 and \a obj2 are compared. So this compare function
193 * returns zero if and only if \a obj1 and \a obj2 point to the same memory area.
195 _static_inline_ int size_compare(const struct osl_object *obj1, const struct osl_object *obj2)
197 uint64_t d1 = *(uint64_t *)obj1->data;
198 uint64_t d2 = *(uint64_t *)obj2->data;
199 int ret = NUM_COMPARE(d2, d1);
203 //INFO_LOG("addresses: %p, %p\n", obj1->data, obj2->data);
204 return NUM_COMPARE(obj2->data, obj1->data);
208 __printf_2_3 void __log(int, const char*, ...);
209 int open_dir_table(int create);
210 void check_signals(void);
212 int com_create(void);
215 void print_interactive_help(void);
216 int com_interactive(void);