Laurence Lundblade | 6ed3422 | 2018-12-18 09:46:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * useful_buf.h |
| 3 | * |
| 4 | * Copyright 2019, Laurence Lundblade |
| 5 | * |
| 6 | * SPDX-License-Identifier: BSD-3-Clause |
| 7 | * |
| 8 | * See BSD-3-Clause license in README.mdE. |
| 9 | */ |
| 10 | |
| 11 | |
| 12 | #ifndef __USEFUL_BUF_H__ |
| 13 | #define __USEFUL_BUF_H__ |
| 14 | |
| 15 | #include "UsefulBuf.h" |
| 16 | |
| 17 | |
| 18 | /** |
| 19 | * \file useful_buf.h |
| 20 | * |
| 21 | * \brief This is a TF-M coding style version of UsefulBuf. |
| 22 | * See UsefulBuf for documentation of these functions. |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #define NULL_USEFUL_BUF_C NULLUsefulBufC |
| 27 | |
| 28 | #define NULL_USEFUL_BUF NULLUsefulBuf |
| 29 | |
| 30 | |
| 31 | static inline int useful_buf_c_is_null(struct useful_buf_c in) |
| 32 | { |
| 33 | return UsefulBuf_IsNULLC(in); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | static inline int useful_buf_is_null(struct useful_buf in) |
| 38 | { |
| 39 | return UsefulBuf_IsNULL(in); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | static inline int useful_buf_c_is_empty(struct useful_buf_c in) |
| 44 | { |
| 45 | return UsefulBuf_IsEmptyC(in); |
| 46 | } |
| 47 | |
| 48 | static inline int useful_buf_is_empty(struct useful_buf in) |
| 49 | { |
| 50 | return UsefulBuf_IsEmpty(in); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | static inline int useful_buf_is_null_or_empty(struct useful_buf in) |
| 55 | { |
| 56 | return UsefulBuf_IsNULLOrEmpty(in); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | static inline int useful_buf_c_is_null_or_empty(struct useful_buf_c in) |
| 61 | { |
| 62 | return UsefulBuf_IsNULLOrEmptyC(in); |
| 63 | } |
| 64 | |
| 65 | |
| 66 | static inline struct useful_buf useful_buf_unconst(struct useful_buf_c in) |
| 67 | { |
| 68 | return UsefulBuf_Unconst(in); |
| 69 | } |
| 70 | |
| 71 | #define USEFUL_BUF_FROM_SZ_LITERAL UsefulBuf_FROM_SZ_LITERAL |
| 72 | |
| 73 | #define USEFUL_BUF_FROM_BYTE_ARRAY_LITERAL UsefulBuf_FROM_BYTE_ARRAY_LITERAL |
| 74 | |
| 75 | #define USEFUL_BUF_MAKE_STACK_UB UsefulBuf_MAKE_STACK_UB |
| 76 | |
| 77 | #define USEFUL_BUF_FROM_BYTE_ARRAY UsefulBuf_FROM_BYTE_ARRAY |
| 78 | |
| 79 | |
| 80 | static inline struct useful_buf_c useful_buf_from_sz(const char *string) |
| 81 | { |
| 82 | return UsefulBuf_FromSZ(string); |
| 83 | } |
| 84 | |
| 85 | static inline struct |
| 86 | useful_buf_c useful_buf_copy_offset(struct useful_buf dest, |
| 87 | size_t offset, |
| 88 | struct useful_buf_c src) |
| 89 | { |
| 90 | return UsefulBuf_CopyOffset(dest, offset, src); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | |
| 95 | static inline struct useful_buf_c useful_buf_copy(struct useful_buf dest, |
| 96 | struct useful_buf_c src) |
| 97 | { |
| 98 | return UsefulBuf_Copy(dest, src); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | static inline struct useful_buf_c useful_buf_set(struct useful_buf dest, |
| 103 | uint8_t value) |
| 104 | { |
| 105 | return UsefulBuf_Set(dest, value); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | static inline struct useful_buf_c useful_buf_copy_ptr(struct useful_buf dest, |
| 110 | const void *ptr, |
| 111 | size_t len) |
| 112 | { |
| 113 | return UsefulBuf_CopyPtr(dest, ptr, len); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | static inline struct useful_buf_c useful_buf_head(struct useful_buf_c buf, |
| 118 | size_t amount) |
| 119 | { |
| 120 | return UsefulBuf_Head(buf, amount); |
| 121 | } |
| 122 | |
| 123 | static inline struct useful_buf_c useful_buf_tail(struct useful_buf_c buf, |
| 124 | size_t amount) |
| 125 | { |
| 126 | return UsefulBuf_Tail(buf, amount); |
| 127 | } |
| 128 | |
| 129 | static inline int useful_buf_compare(const struct useful_buf_c buf1, |
| 130 | const struct useful_buf_c buf2) |
| 131 | { |
| 132 | return UsefulBuf_Compare(buf1, buf2); |
| 133 | } |
| 134 | |
| 135 | static inline size_t |
| 136 | useful_buf_find_bytes(const struct useful_buf_c bytes_to_search, |
| 137 | const struct useful_buf_c bytes_to_find) |
| 138 | { |
| 139 | return UsefulBuf_FindBytes(bytes_to_search, bytes_to_find); |
| 140 | } |
| 141 | |
| 142 | |
| 143 | #endif /* __USEFUL_BUF_H__ */ |