diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2020-10-08 08:44:33 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2020-10-08 11:24:31 +0200 |
| commit | 083eca5323a57f22847c578916e956321491a332 (patch) | |
| tree | 496d6104f863135bf1f680a7823ed2377991e03c /include | |
| parent | 3e9016f23f38a3243213badaa954725518fb9509 (diff) | |
Move convenience macros down for readability
Diffstat (limited to 'include')
| -rw-r--r-- | include/dynstr.h | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/include/dynstr.h b/include/dynstr.h index 72ebb4a..b2e102c 100644 --- a/include/dynstr.h +++ b/include/dynstr.h @@ -25,75 +25,6 @@ #include <stddef.h> #include <stdbool.h> -/* Since dynstr_append() might fail (as it is based on dynamic memory - * allocation), these macros can be used to avoid boilerplate code. */ - -/** - * Convenience macro that calls dynstr_append and returns NULL if failed. - */ -#define dynstr_append_or_ret_null(...) \ - do {if (dynstr_append(__VA_ARGS__) != DYNSTR_OK) return NULL;} while (0) - -/** - * Convenience macro that calls dynstr_append and returns false if failed. - */ -#define dynstr_append_or_ret_false(...) \ - do {if (dynstr_append(__VA_ARGS__) != DYNSTR_OK) return false;} while (0) - -/** - * Convenience macro that calls dynstr_append and returns its error code if failed. - */ -#define dynstr_append_or_ret(...) \ - { \ - const enum dynstr_err err = dynstr_append(__VA_ARGS__); \ - if (err != DYNSTR_OK) return err; \ - } - -/** - * Convenience macro that calls dynstr_append and returns zero if failed. - */ -#define dynstr_append_or_ret_zero(...) \ - do {if (dynstr_append(__VA_ARGS__) != DYNSTR_OK) return 0;} while (0) - -/** - * Convenience macro that calls dynstr_append and returns one if failed. - */ -#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 @@ -213,4 +144,73 @@ enum dynstr_err dynstr_dup(struct dynstr *dst, const struct dynstr *src); */ void dynstr_free(struct dynstr *d); +/* Since dynstr_append() might fail (as it is based on dynamic memory + * allocation), these macros can be used to avoid boilerplate code. */ + +/** + * Convenience macro that calls dynstr_append and returns NULL if failed. + */ +#define dynstr_append_or_ret_null(...) \ + do {if (dynstr_append(__VA_ARGS__) != DYNSTR_OK) return NULL;} while (0) + +/** + * Convenience macro that calls dynstr_append and returns false if failed. + */ +#define dynstr_append_or_ret_false(...) \ + do {if (dynstr_append(__VA_ARGS__) != DYNSTR_OK) return false;} while (0) + +/** + * Convenience macro that calls dynstr_append and returns its error code if failed. + */ +#define dynstr_append_or_ret(...) \ + { \ + const enum dynstr_err err = dynstr_append(__VA_ARGS__); \ + if (err != DYNSTR_OK) return err; \ + } + +/** + * Convenience macro that calls dynstr_append and returns zero if failed. + */ +#define dynstr_append_or_ret_zero(...) \ + do {if (dynstr_append(__VA_ARGS__) != DYNSTR_OK) return 0;} while (0) + +/** + * Convenience macro that calls dynstr_append and returns one if failed. + */ +#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) + #endif /* DYNSTR_H */ |
