mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MINOR: ist: Add struct ist istdup(const struct ist)
istdup() performs the equivalent of strdup() on a `struct ist`.
This commit is contained in:
parent
ed5263739b
commit
9576ab7640
@ -756,6 +756,27 @@ static inline void istfree(struct ist *ist)
|
|||||||
free(ist->ptr);
|
free(ist->ptr);
|
||||||
*ist = IST_NULL;
|
*ist = IST_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This function performs the equivalent of strdup() on the given <src>.
|
||||||
|
*
|
||||||
|
* If this function fails to allocate memory the return value is equivalent
|
||||||
|
* to IST_NULL.
|
||||||
|
*/
|
||||||
|
static inline struct ist istdup(const struct ist src)
|
||||||
|
{
|
||||||
|
const size_t src_size = src.len;
|
||||||
|
|
||||||
|
/* Allocate at least 1 byte to allow duplicating an empty string with
|
||||||
|
* malloc implementations that return NULL for a 0-size allocation.
|
||||||
|
*/
|
||||||
|
struct ist dst = istalloc(MAX(src_size, 1));
|
||||||
|
|
||||||
|
if (isttest(dst)) {
|
||||||
|
istcpy(&dst, src, src_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user