return 0;
}
+
+int pakfire_log_buffer_dump(struct pakfire_log_buffer* buffer, char** result, size_t* length) {
+ struct pakfire_log_line* line = NULL;
+ char* s = NULL;
+ size_t l = 0;
+ int r;
+
+ // Check inputs
+ if (!result || !length)
+ return -EINVAL;
+
+ // Compute the total length of the buffer that we will need
+ STAILQ_FOREACH(line, &buffer->lines, nodes) {
+ l += line->length;
+ }
+
+ // Nothing to do if the buffer is empty
+ if (!l)
+ return 0;
+
+ // Allocate a buffer that can fit the entire content
+ s = malloc(l);
+ if (!s)
+ return -errno;
+
+ char* p = s;
+
+ // Copy the entire content into the buffer
+ STAILQ_FOREACH(line, &buffer->lines, nodes) {
+ memcpy(p, line->line, line->length);
+
+ p += line->length;
+ }
+
+ // Return the buffer
+ *result = s;
+ *length = l;
+
+ return 0;
+}
int pakfire_log_buffer_enqueue(struct pakfire_log_buffer* buffer, int priority, const char* line, ssize_t length);
int pakfire_log_buffer_dequeue(struct pakfire_log_buffer* buffer, int* priority, char** line, size_t* length);
+int pakfire_log_buffer_dump(struct pakfire_log_buffer* buffer, char** result, size_t* length);
+
#endif /* PAKFIRE_LOG_BUFFER_H */