Add convenience macros for dynstr_prepend

This commit is contained in:
Xavier Del Campo Romero 2020-10-08 08:41:46 +02:00
parent c862d84d0b
commit 3e9016f23f
1 changed files with 33 additions and 0 deletions

View File

@ -61,6 +61,39 @@
#define dynstr_append_or_ret_nonzero(...) \
do {if (dynstr_append(__VA_ARGS__) != DYNSTR_OK) return 1;} while (0)
/**
* Convenience macro that calls dynstr_prepend and returns NULL if failed.
*/
#define dynstr_prepend_or_ret_null(...) \
do {if (dynstr_prepend(__VA_ARGS__) != DYNSTR_OK) return NULL;} while (0)
/**
* Convenience macro that calls dynstr_prepend and returns false if failed.
*/
#define dynstr_prepend_or_ret_false(...) \
do {if (dynstr_prepend(__VA_ARGS__) != DYNSTR_OK) return false;} while (0)
/**
* Convenience macro that calls dynstr_prepend and returns its error code if failed.
*/
#define dynstr_prepend_or_ret(...) \
{ \
const enum dynstr_err err = dynstr_prepend(__VA_ARGS__); \
if (err != DYNSTR_OK) return err; \
}
/**
* Convenience macro that calls dynstr_prepend and returns zero if failed.
*/
#define dynstr_prepend_or_ret_zero(...) \
do {if (dynstr_prepend(__VA_ARGS__) != DYNSTR_OK) return 0;} while (0)
/**
* Convenience macro that calls dynstr_prepend and returns one if failed.
*/
#define dynstr_prepend_or_ret_nonzero(...) \
do {if (dynstr_prepend(__VA_ARGS__) != DYNSTR_OK) return 1;} while (0)
/**
* Dynamic string type used for this library.
* @note If needed, members can be safely read but should not be modified