spa: add some more functions

This commit is contained in:
Wim Taymans 2024-11-26 12:21:05 +01:00
parent d966a36fdd
commit 9fc33a6142
2 changed files with 28 additions and 8 deletions

View file

@ -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 }) #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 }) #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 /** 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. */ * 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) SPA_API_JSON int spa_json_next(struct spa_json * iter, const char **value)

View file

@ -19,8 +19,18 @@ extern "C" {
* \{ * \{
*/ */
#include <errno.h>
#include <spa/utils/defs.h> #include <spa/utils/defs.h>
#include <spa/utils/list.h>
#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_BIT (1 << 30)
#define SPA_ASYNC_SEQ_MASK (SPA_ASYNC_BIT - 1) #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_ASYNC_SEQ(res) ((res) & SPA_ASYNC_SEQ_MASK)
#define SPA_RESULT_RETURN_ASYNC(seq) (SPA_ASYNC_BIT | SPA_RESULT_ASYNC_SEQ(seq)) #define SPA_RESULT_RETURN_ASYNC(seq) (SPA_ASYNC_BIT | SPA_RESULT_ASYNC_SEQ(seq))
#define spa_strerror(err) \ SPA_API_RESULT const char *spa_strerror(int err)
({ \ {
int _err = -(err); \ int _err = -(err);
if (SPA_RESULT_IS_ASYNC(err)) \ if (SPA_RESULT_IS_ASYNC(err))
_err = EINPROGRESS; \ _err = EINPROGRESS;
strerror(_err); \ return strerror(_err);
}) }
/** /**
* \} * \}