#include <stdlib.h>
#include <string.h>
+#include <systemd/sd-json.h>
+
#include "ctx.h"
#include "file.h"
#include "string.h"
return __td_file_parse(self->ctx, self, 0, line, length, parser);
}
+int td_file_parse_json(td_file* self, sd_json_variant** ret, sd_json_parse_flags_t flags) {
+ unsigned int column = 0;
+ unsigned int line = 0;
+ int r;
+
+ // Parse the file
+ r = sd_json_parse_file(self->f, NULL, flags, ret, &line, &column);
+ if (r < 0) {
+ ERROR(self->ctx, "Failed to parse JSON output in line %u:%u\n", line, column);
+ return r;
+ }
+
+ return 0;
+}
+
int td_read_uint64(td_ctx* ctx, const char* path, uint64_t* number) {
td_file* file = NULL;
int r;
#include <stdint.h>
+#include <systemd/sd-json.h>
+
typedef struct td_file td_file;
#include "buffer.h"
int td_file_parse(td_file* self, td_file_parser* parser);
int td_file_parse_line(td_file* self, td_file_parser* parser, char* line, size_t length);
+// Parse JSON
+int td_file_parse_json(td_file* self, sd_json_variant** json, sd_json_parse_flags_t flags);
+
// Shorthands
int td_read_uint64(td_ctx* ctx, const char* path, uint64_t* number);