xy.h + `xy_str_swap` 帮助释放内存

This commit is contained in:
Mikachu2333 2025-10-06 01:37:28 +08:00
parent 0b4215f257
commit 5771a308a6

View File

@ -208,6 +208,27 @@ xy_malloc0 (size_t size)
* String
******************************************************/
/**
* @brief
*
* @param old_ptr (char **)
* @param new_str
*/
static inline void
xy_str_swap (char **old_ptr, char *new_str)
{
if (old_ptr && *old_ptr)
{
char *temp = *old_ptr;
*old_ptr = new_str;
free (temp);
}
else if (old_ptr)
{
*old_ptr = new_str;
}
}
/**
* @brief str pat replace
*