2022-09-02 01:00:37 +00:00
|
|
|
#include "core/lmem.h"
|
2022-01-24 03:28:16 +00:00
|
|
|
|
2022-09-02 01:00:37 +00:00
|
|
|
#include "core/lerror.h"
|
2022-06-27 23:57:00 +00:00
|
|
|
|
|
|
|
void *laikaM_realloc(void *buf, size_t sz)
|
|
|
|
{
|
2022-01-24 03:28:16 +00:00
|
|
|
void *newBuf;
|
|
|
|
|
|
|
|
/* are we free'ing the buffer? */
|
|
|
|
if (sz == 0) {
|
2022-04-08 04:21:09 +00:00
|
|
|
free(buf);
|
2022-01-24 03:28:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if NULL is passed, realloc() acts like malloc() */
|
|
|
|
if ((newBuf = realloc(buf, sz)) == NULL)
|
2022-01-25 03:46:29 +00:00
|
|
|
LAIKA_ERROR("failed to allocate memory!\n");
|
2022-01-24 03:28:16 +00:00
|
|
|
|
|
|
|
return newBuf;
|
2022-04-08 04:21:09 +00:00
|
|
|
}
|
2022-09-07 21:53:14 +00:00
|
|
|
|
|
|
|
bool laikaM_isBigEndian(void)
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
uint8_t c[4];
|
|
|
|
} _indxint = {0xDEADB33F};
|
|
|
|
|
|
|
|
return _indxint.c[0] == 0xDE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void laikaM_reverse(uint8_t *buf, size_t sz)
|
|
|
|
{
|
|
|
|
int k;
|
|
|
|
|
|
|
|
/* swap bytes, reversing the buffer */
|
|
|
|
for (k = 0; k < (sz / 2); k++) {
|
|
|
|
uint8_t tmp = buf[k];
|
|
|
|
buf[k] = buf[sz - k - 1];
|
|
|
|
buf[sz - k - 1] = tmp;
|
|
|
|
}
|
|
|
|
}
|