vfprintf(stderr, fmt, argp); \
va_end(argp); \
}
+/**
+ * Define the standard log function and activate it.
+ *
+ * \param loglevel_barrier See \ref DEFINE_STDERR_LOGGER.
+ */
#define INIT_STDERR_LOGGING(loglevel_barrier) \
DEFINE_STDERR_LOGGER(stderr_log, loglevel_barrier); \
__printf_2_3 void (*para_log)(int, const char*, ...) = stderr_log;
int for_each_stat_item(char *item_buf, size_t num_bytes,
int (*item_handler)(int, char *));
-/**
- * Write a log message to a dynamically allocated string.
- *
- * \param fmt Usual format string.
- * \param p Result pointer.
- *
- * \sa printf(3). */
-#define PARA_VSPRINTF(fmt, p) \
-{ \
- int n; \
- size_t size = 100; \
- p = para_malloc(size); \
- while (1) { \
- va_list ap; \
- /* Try to print in the allocated space. */ \
- va_start(ap, fmt); \
- n = vsnprintf(p, size, fmt, ap); \
- va_end(ap); \
- /* If that worked, return the string. */ \
- if (n > -1 && n < size) \
- break; \
- /* Else try again with more space. */ \
- if (n > -1) /* glibc 2.1 */ \
- size = n + 1; /* precisely what is needed */ \
- else /* glibc 2.0 */ \
- size *= 2; /* twice the old size */ \
- p = para_realloc(p, size); \
- } \
-}
/**
- * Return a random non-negative integer in an interval.
+ * Return a random non-negative integer in an interval.
*
* \param max Determines maximal possible return value.
*
return ((max + 0.0) * (random() / (RAND_MAX + 1.0)));
}
+/**
+ * Simple sanity check for I/O vectors.
+ *
+ * \param iov Pointer to the I/O vector to check.
+ *
+ * \return True if \a iov points to a non-empty buffer.
+ */
+_static_inline_ bool iov_valid(const struct iovec *iov)
+{
+ return iov && iov->iov_len > 0 && iov->iov_base;
+}
+
/** Round up x to next multiple of y. */
#define ROUND_UP(x, y) ({ \
const typeof(y) _divisor = y; \