2021-10-02 18:00:53 +00:00
|
|
|
/* Function to swap void* objects. */
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "swap_void.h"
|
|
|
|
|
|
|
|
/* This function swaps void* objects. */
|
|
|
|
/* Temp should be an allocated buffer, used to do the swap. */
|
|
|
|
/* Size should be > 0. */
|
|
|
|
/* Expect undefined behavior if conditions aren't met. */
|
2021-10-03 16:52:32 +00:00
|
|
|
extern inline void swap_void_ptr(void *first, void *second, void *temp, size_t size) {
|
2021-10-02 18:00:53 +00:00
|
|
|
/* Swap. */
|
|
|
|
memcpy(temp, first, size);
|
|
|
|
memcpy(first, second, size);
|
|
|
|
memcpy(second, temp, size);
|
|
|
|
}
|