mirror of
https://github.com/systemd/systemd.git
synced 2024-11-05 06:52:22 +03:00
json: add json_parse_file_at() helper
This is an "at" function, similar to json_parse_file().
This commit is contained in:
parent
83bc6cb792
commit
f325aaf341
@ -2833,7 +2833,7 @@ int json_parse_continue(const char **p, JsonVariant **ret, unsigned *ret_line, u
|
||||
return json_parse_internal(p, NULL, ret, ret_line, ret_column, true);
|
||||
}
|
||||
|
||||
int json_parse_file(FILE *f, const char *path, JsonVariant **ret, unsigned *ret_line, unsigned *ret_column) {
|
||||
int json_parse_file_at(FILE *f, int dir_fd, const char *path, JsonVariant **ret, unsigned *ret_line, unsigned *ret_column) {
|
||||
_cleanup_(json_source_unrefp) JsonSource *source = NULL;
|
||||
_cleanup_free_ char *text = NULL;
|
||||
const char *p;
|
||||
@ -2842,7 +2842,7 @@ int json_parse_file(FILE *f, const char *path, JsonVariant **ret, unsigned *ret_
|
||||
if (f)
|
||||
r = read_full_stream(f, &text, NULL);
|
||||
else if (path)
|
||||
r = read_full_file(path, &text, NULL);
|
||||
r = read_full_file_full(dir_fd, path, 0, &text, NULL);
|
||||
else
|
||||
return -EINVAL;
|
||||
if (r < 0)
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@ -175,7 +176,11 @@ int json_variant_set_field(JsonVariant **v, const char *field, JsonVariant *valu
|
||||
|
||||
int json_parse(const char *string, JsonVariant **ret, unsigned *ret_line, unsigned *ret_column);
|
||||
int json_parse_continue(const char **p, JsonVariant **ret, unsigned *ret_line, unsigned *ret_column);
|
||||
int json_parse_file(FILE *f, const char *path, JsonVariant **ret, unsigned *ret_line, unsigned *ret_column);
|
||||
int json_parse_file_at(FILE *f, int dir_fd, const char *path, JsonVariant **ret, unsigned *ret_line, unsigned *ret_column);
|
||||
|
||||
static inline int json_parse_file(FILE *f, const char *path, JsonVariant **ret, unsigned *ret_line, unsigned *ret_column) {
|
||||
return json_parse_file_at(f, AT_FDCWD, path, ret, ret_line, ret_column);
|
||||
}
|
||||
|
||||
enum {
|
||||
_JSON_BUILD_STRING,
|
||||
|
Loading…
Reference in New Issue
Block a user