+
+int sd_journal_get_realtime_usec(sd_journal *j, uint64_t *ret) {
+ Object *o;
+ JournalFile *f;
+ int r;
+
+ assert(j);
+ assert(ret);
+
+ f = j->current_file;
+ if (!f)
+ return 0;
+
+ if (f->current_offset <= 0)
+ return 0;
+
+ r = journal_file_move_to_object(f, f->current_offset, OBJECT_ENTRY, &o);
+ if (r < 0)
+ return r;
+
+ *ret = le64toh(o->entry.realtime);
+ return 1;
+}
+
+int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret) {
+ Object *o;
+ JournalFile *f;
+ int r;
+ sd_id128_t id;
+
+ assert(j);
+ assert(ret);
+
+ f = j->current_file;
+ if (!f)
+ return 0;
+
+ if (f->current_offset <= 0)
+ return 0;
+
+ r = sd_id128_get_machine(&id);
+ if (r < 0)
+ return r;
+
+ r = journal_file_move_to_object(f, f->current_offset, OBJECT_ENTRY, &o);
+ if (r < 0)
+ return r;
+
+ if (!sd_id128_equal(id, o->entry.boot_id))
+ return 0;
+
+ *ret = le64toh(o->entry.monotonic);
+ return 1;
+
+}
+
+int sd_journal_get_field(sd_journal *j, const char *field, const void **data, size_t *size) {
+ JournalFile *f;
+ uint64_t i, n;
+ size_t field_length;
+ int r;
+ Object *o;
+
+ assert(j);
+ assert(field);
+ assert(data);
+ assert(size);
+
+ if (isempty(field) || strchr(field, '='))
+ return -EINVAL;
+
+ f = j->current_file;
+ if (!f)
+ return 0;
+
+ if (f->current_offset <= 0)
+ return 0;
+
+ r = journal_file_move_to_object(f, f->current_offset, OBJECT_ENTRY, &o);
+ if (r < 0)
+ return r;
+
+ field_length = strlen(field);
+
+ n = journal_file_entry_n_items(o);
+ for (i = 0; i < n; i++) {
+ uint64_t p, l;
+ size_t t;
+
+ p = le64toh(o->entry.items[i].object_offset);
+ r = journal_file_move_to_object(f, p, OBJECT_DATA, &o);
+ if (r < 0)
+ return r;
+
+ l = le64toh(o->object.size) - offsetof(Object, data.payload);
+
+ if (field_length+1 > l)
+ continue;
+
+ if (memcmp(o->data.payload, field, field_length) ||
+ o->data.payload[field_length] != '=')
+ continue;
+
+ t = (size_t) l;
+
+ if ((uint64_t) t != l)
+ return -E2BIG;
+
+ *data = o->data.payload;
+ *size = t;
+
+ return 1;
+ }
+
+ return 0;
+}
+
+int sd_journal_iterate_fields(sd_journal *j, const void **data, size_t *size) {
+ JournalFile *f;
+ uint64_t p, l, n;
+ size_t t;
+ int r;
+ Object *o;
+
+ assert(j);
+ assert(data);
+ assert(size);
+
+ f = j->current_file;
+ if (!f)
+ return 0;
+
+ if (f->current_offset <= 0)
+ return 0;
+
+ r = journal_file_move_to_object(f, f->current_offset, OBJECT_ENTRY, &o);
+ if (r < 0)
+ return r;
+
+ n = journal_file_entry_n_items(o);
+ if (f->current_field >= n)
+ return 0;
+
+ p = le64toh(o->entry.items[f->current_field].object_offset);
+ r = journal_file_move_to_object(f, p, OBJECT_DATA, &o);
+ if (r < 0)
+ return r;
+
+ l = le64toh(o->object.size) - offsetof(Object, data.payload);
+ t = (size_t) l;
+
+ /* We can't read objects larger than 4G on a 32bit machine */
+ if ((uint64_t) t != l)
+ return -E2BIG;
+
+ *data = o->data.payload;
+ *size = t;
+
+ f->current_field ++;
+
+ return 1;
+}