sd-json: add SD_JSON_PARSE_SEEK0 flag

This commit is contained in:
Lennart Poettering
2026-05-18 08:51:09 +02:00
parent c91ddaf1ee
commit 584ee9ffe5
2 changed files with 6 additions and 2 deletions
+5 -2
View File
@@ -3502,9 +3502,12 @@ _public_ int sd_json_parse_file_at(
_cleanup_free_ char *text = NULL;
int r;
if (f)
if (f) {
if (FLAGS_SET(flags, SD_JSON_PARSE_SEEK0) && fseek(f, /* offset= */ 0, SEEK_SET) < 0)
return -errno;
r = read_full_stream(f, &text, NULL);
else
} else
r = read_full_file_full(dir_fd, path, UINT64_MAX, SIZE_MAX, 0, NULL, &text, NULL);
if (r < 0)
return r;
+1
View File
@@ -184,6 +184,7 @@ __extension__ typedef enum _SD_ENUM_TYPE_S64(sd_json_parse_flags_t) {
SD_JSON_PARSE_SENSITIVE = 1 << 0, /* mark variant as "sensitive", i.e. something containing secret key material or such */
SD_JSON_PARSE_MUST_BE_OBJECT = 1 << 1, /* refuse parsing if top-level is not an object */
SD_JSON_PARSE_MUST_BE_ARRAY = 1 << 2, /* refuse parsing if top-level is not an array */
SD_JSON_PARSE_SEEK0 = 1 << 3, /* seek to offset 0 before reading */
_SD_ENUM_FORCE_S64(JSON_PARSE_FLAGS)
} sd_json_parse_flags_t;