From 8c164074bea6bef3e2450c3ed27a07191b580da9 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 17 May 2026 08:56:56 +0200 Subject: [PATCH] man: add documentation for new sd-json features --- man/rules/meson.build | 6 +++- man/sd_json_parse.xml | 67 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/man/rules/meson.build b/man/rules/meson.build index c42a8d47f8..e0a99b1a21 100644 --- a/man/rules/meson.build +++ b/man/rules/meson.build @@ -869,10 +869,14 @@ manpages = [ ''], ['sd_json_parse', '3', - ['SD_JSON_PARSE_MUST_BE_ARRAY', + ['SD_JSON_PARSE_DONATE_FD', + 'SD_JSON_PARSE_MUST_BE_ARRAY', 'SD_JSON_PARSE_MUST_BE_OBJECT', + 'SD_JSON_PARSE_REOPEN_FD', + 'SD_JSON_PARSE_SEEK0', 'SD_JSON_PARSE_SENSITIVE', 'sd_json_parse_continue', + 'sd_json_parse_fd', 'sd_json_parse_file', 'sd_json_parse_file_at', 'sd_json_parse_with_source', diff --git a/man/sd_json_parse.xml b/man/sd_json_parse.xml index c5234734da..73089853a2 100644 --- a/man/sd_json_parse.xml +++ b/man/sd_json_parse.xml @@ -22,9 +22,13 @@ sd_json_parse_with_source_continue sd_json_parse_file sd_json_parse_file_at + sd_json_parse_fd SD_JSON_PARSE_SENSITIVE SD_JSON_PARSE_MUST_BE_OBJECT SD_JSON_PARSE_MUST_BE_ARRAY + SD_JSON_PARSE_SEEK0 + SD_JSON_PARSE_DONATE_FD + SD_JSON_PARSE_REOPEN_FD Parse JSON strings and files into JSON variant objects @@ -91,6 +95,16 @@ unsigned *reterr_line unsigned *reterr_column + + + int sd_json_parse_fd + const char *path + int fd + sd_json_parse_flags_t flags + sd_json_variant **ret + unsigned *reterr_line + unsigned *reterr_column + @@ -146,6 +160,16 @@ against the current working directory, which is the default behaviour of sd_json_parse_file(). + sd_json_parse_fd() reads and parses a JSON value from the file referenced by + the file descriptor fd. By default the file descriptor is internally duplicated + and the caller's descriptor is left untouched (the current file offset will be shared with the original + file descriptor however); the JSON text is read starting at the descriptor's current file offset. This + behaviour may be modified via the SD_JSON_PARSE_SEEK0, + SD_JSON_PARSE_DONATE_FD and SD_JSON_PARSE_REOPEN_FD flags, see + below. The path argument is not used to open anything in this case; it is only + recorded as source information in the resulting JSON variant (see above) and may be passed as + NULL. + The flags argument is a bitmask of zero or more of the following flags: @@ -179,6 +203,44 @@ + + + SD_JSON_PARSE_SEEK0 + + Before reading, seek the input to its beginning (i.e. file offset 0). This flag has + no effect when parsing from a string. When used together with + SD_JSON_PARSE_REOPEN_FD in sd_json_parse_fd() it is + redundant, since a freshly reopened file descriptor starts at offset 0 anyway. + + + + + + SD_JSON_PARSE_DONATE_FD + + Only has an effect on sd_json_parse_fd(). If set, ownership of + the file descriptor passed in fd is transferred into the call: the descriptor + is consumed and closed before the function returns, including in the error path. If not set (the + default), the caller retains ownership of fd and the function operates on an + internally duplicated descriptor instead. This flag may not be combined with + SD_JSON_PARSE_REOPEN_FD. + + + + + + SD_JSON_PARSE_REOPEN_FD + + Only has an effect on sd_json_parse_fd(). If set, the file + descriptor passed in fd is reopened (read-only) before reading, instead of + being duplicated. This is primarily useful to obtain an independent file offset (positioned at the + beginning of the file) and a clean, read-only access mode, even if the original descriptor was opened + differently (for example with O_PATH). The caller retains ownership of the + original descriptor, which is left untouched. This flag may not be combined with + SD_JSON_PARSE_DONATE_FD. + + + If both SD_JSON_PARSE_MUST_BE_OBJECT and @@ -232,6 +294,11 @@ sd_json_parse_with_source_continue(), sd_json_parse_file(), and sd_json_parse_file_at() were added in version 257. + + sd_json_parse_fd() and the SD_JSON_PARSE_MUST_BE_OBJECT, + SD_JSON_PARSE_MUST_BE_ARRAY, SD_JSON_PARSE_SEEK0, + SD_JSON_PARSE_DONATE_FD and SD_JSON_PARSE_REOPEN_FD flags were + added in version 261.