iovec-wrapper: introduce iovw_compare() and iovw_equal()
This commit is contained in:
@@ -23,6 +23,28 @@ void iovw_done_free(struct iovec_wrapper *iovw) {
|
||||
iovw_done(iovw);
|
||||
}
|
||||
|
||||
int iovw_compare(const struct iovec_wrapper *a, const struct iovec_wrapper *b) {
|
||||
int r;
|
||||
|
||||
if (a == b)
|
||||
return 0;
|
||||
|
||||
if (!a || !b)
|
||||
return CMP(!!a, !!b);
|
||||
|
||||
/* Note, this performs structural (element-by-element) comparison, not content-based comparison.
|
||||
* Two wrappers with identical concatenated content but different element boundaries
|
||||
* (e.g., ["fo","o"] vs ["f","oo"]) will not compare as equal. */
|
||||
|
||||
for (size_t i = 0, n = MIN(a->count, b->count); i < n; i++) {
|
||||
r = iovec_memcmp(a->iovec + i, b->iovec + i);
|
||||
if (r != 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return CMP(a->count, b->count);
|
||||
}
|
||||
|
||||
int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len) {
|
||||
assert(iovw);
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@ struct iovec_wrapper {
|
||||
void iovw_done_free(struct iovec_wrapper *iovw);
|
||||
void iovw_done(struct iovec_wrapper *iovw);
|
||||
|
||||
int iovw_compare(const struct iovec_wrapper *a, const struct iovec_wrapper *b) _pure_;
|
||||
static inline bool iovw_equal(const struct iovec_wrapper *a, const struct iovec_wrapper *b) {
|
||||
return iovw_compare(a, b) == 0;
|
||||
}
|
||||
|
||||
int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len);
|
||||
int iovw_consume(struct iovec_wrapper *iovw, void *data, size_t len);
|
||||
int iovw_append(struct iovec_wrapper *iovw, const void *data, size_t len);
|
||||
|
||||
Reference in New Issue
Block a user