iovec-util: introduce iovec_done_and_memdup()
It is similar to free_and_strdup(), but for struct iovec.
This commit is contained in:
committed by
Luca Boccassi
parent
fa9b3b26c7
commit
5b10b58358
@@ -129,6 +129,21 @@ struct iovec* iovec_memdup(const struct iovec *source, struct iovec *ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int iovec_done_and_memdup(struct iovec *iovec, const struct iovec *source) {
|
||||
assert(iovec);
|
||||
|
||||
if (iovec_equal(iovec, source))
|
||||
return 0;
|
||||
|
||||
struct iovec copy;
|
||||
if (!iovec_memdup(source, ©))
|
||||
return -ENOMEM;
|
||||
|
||||
iovec_done(iovec);
|
||||
*iovec = copy;
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct iovec* iovec_append(struct iovec *iovec, const struct iovec *append) {
|
||||
assert(iovec_is_valid(iovec));
|
||||
|
||||
|
||||
@@ -43,5 +43,6 @@ static inline bool iovec_equal(const struct iovec *a, const struct iovec *b) {
|
||||
}
|
||||
|
||||
struct iovec* iovec_memdup(const struct iovec *source, struct iovec *ret);
|
||||
int iovec_done_and_memdup(struct iovec *iovec, const struct iovec *source);
|
||||
|
||||
struct iovec* iovec_append(struct iovec *iovec, const struct iovec *append);
|
||||
|
||||
Reference in New Issue
Block a user