From 9fc33a614299c9f2446fcce78500864981aedb34 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 26 Nov 2024 12:21:05 +0100 Subject: [PATCH] spa: add some more functions --- spa/include/spa/utils/json-core.h | 10 ++++++++++ spa/include/spa/utils/result.h | 26 ++++++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/spa/include/spa/utils/json-core.h b/spa/include/spa/utils/json-core.h index 7a15e4bd9..31bf772f1 100644 --- a/spa/include/spa/utils/json-core.h +++ b/spa/include/spa/utils/json-core.h @@ -62,8 +62,18 @@ SPA_API_JSON void spa_json_enter(struct spa_json * iter, struct spa_json * sub) #define SPA_JSON_SAVE(iter) ((struct spa_json) { (iter)->cur, (iter)->end, NULL, (iter)->state, 0 }) +SPA_API_JSON void spa_json_save(struct spa_json * iter, struct spa_json * save) +{ + *save = SPA_JSON_SAVE(iter); +} + #define SPA_JSON_START(iter,p) ((struct spa_json) { (p), (iter)->end, NULL, 0, 0 }) +SPA_API_JSON void spa_json_start(struct spa_json * iter, struct spa_json * sub, const char *pos) +{ + *sub = SPA_JSON_START(iter,pos); +} + /** Get the next token. \a value points to the token and the return value * is the length. Returns -1 on parse error, 0 on end of input. */ SPA_API_JSON int spa_json_next(struct spa_json * iter, const char **value) diff --git a/spa/include/spa/utils/result.h b/spa/include/spa/utils/result.h index 7f389c2c8..312a6bb0c 100644 --- a/spa/include/spa/utils/result.h +++ b/spa/include/spa/utils/result.h @@ -19,8 +19,18 @@ extern "C" { * \{ */ +#include + #include -#include + +#ifndef SPA_API_RESULT + #ifdef SPA_API_IMPL + #define SPA_API_RESULT SPA_API_IMPL + #else + #define SPA_API_RESULT static inline + #endif +#endif + #define SPA_ASYNC_BIT (1 << 30) #define SPA_ASYNC_SEQ_MASK (SPA_ASYNC_BIT - 1) @@ -33,13 +43,13 @@ extern "C" { #define SPA_RESULT_ASYNC_SEQ(res) ((res) & SPA_ASYNC_SEQ_MASK) #define SPA_RESULT_RETURN_ASYNC(seq) (SPA_ASYNC_BIT | SPA_RESULT_ASYNC_SEQ(seq)) -#define spa_strerror(err) \ -({ \ - int _err = -(err); \ - if (SPA_RESULT_IS_ASYNC(err)) \ - _err = EINPROGRESS; \ - strerror(_err); \ -}) +SPA_API_RESULT const char *spa_strerror(int err) +{ + int _err = -(err); + if (SPA_RESULT_IS_ASYNC(err)) + _err = EINPROGRESS; + return strerror(_err); +} /** * \}