sd-json: add SD_JSON_PARSE_SEEK0 flag
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user