static inline void __attribute__((always_inline, format(printf, 2, 3)))
pakfire_log_null(struct pakfire* pakfire, const char *format, ...) {}
-#define pakfire_log_condition(pakfire, prio, arg...) \
+#define pakfire_log_condition(pakfire, prio, r, arg...) \
do { \
if (pakfire_log_get_priority(pakfire) >= prio) \
- pakfire_log(pakfire, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \
+ pakfire_log(pakfire, prio, r, __FILE__, __LINE__, __FUNCTION__, ## arg); \
} while (0)
-#define INFO(pakfire, arg...) pakfire_log_condition(pakfire, LOG_INFO, ## arg)
-#define ERROR(pakfire, arg...) pakfire_log_condition(pakfire, LOG_ERR, ## arg)
+#define INFO(pakfire, arg...) pakfire_log_condition(pakfire, LOG_INFO, 0, ## arg)
+#define ERROR(pakfire, arg...) pakfire_log_condition(pakfire, LOG_ERR, 0, ## arg)
+
+#define INFO_ERRNO(pakfire, r, arg...) pakfire_log_condition(pakfire, LOG_INFO, r, ## arg)
+#define ERROR_ERRNO(pakfire, r, arg...) pakfire_log_condition(pakfire, LOG_ERR, r, ## arg)
#ifdef ENABLE_DEBUG
-# define DEBUG(pakfire, arg...) pakfire_log_condition(pakfire, LOG_DEBUG, ## arg)
+# define DEBUG(pakfire, arg...) pakfire_log_condition(pakfire, LOG_DEBUG, 0, ## arg)
+# define DEBUG_ERRNO(pakfire, r, arg...) pakfire_log_condition(pakfire, LOG_DEBUG, r, ## arg)
#else
# define DEBUG pakfire_log_null
+# define DEBUG_ERRNO pakfire_log_null
#endif
#endif /* PAKFIRE_PRIVATE */
const struct pakfire_subid* pakfire_subuid(struct pakfire* pakfire);
const struct pakfire_subid* pakfire_subgid(struct pakfire* pakfire);
-void pakfire_log(struct pakfire* pakfire, int priority, const char *file,
+void pakfire_log(struct pakfire* pakfire, int priority, int r, const char *file,
int line, const char *fn, const char *format, ...)
- __attribute__((format(printf, 6, 7)));
+ __attribute__((format(printf, 7, 8)));
int pakfire_has_flag(struct pakfire* pakfire, int flag);
pakfire->callbacks.log_data = data;
}
-void pakfire_log(struct pakfire* pakfire, int priority, const char* file, int line,
- const char* fn, const char* format, ...) {
+void pakfire_log(struct pakfire* pakfire, int priority, int r,
+ const char* file, int line, const char* fn, const char* format, ...) {
va_list args;
// Do not do anything if callback isn't set
// Save errno
int saved_errno = errno;
+ if (r)
+ errno = r;
va_start(args, format);
pakfire->callbacks.log(pakfire->callbacks.log_data,