calcite/src/kernel/utility.c

47 lines
1.4 KiB
C

/* Calcite, src/kernel/utility.c
* Copyright 2025 Benji Dial
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "utility.h"
#include "heap.h"
int strequ(const char *str1, const char *str2) {
while (1) {
if (!*str1 && !*str2)
return 1;
if (*str1 != *str2)
return 0;
++str1;
++str2;
}
}
uint32_t end_swap_u32(uint32_t value) {
return
(value >> 24) |
(((value >> 16) & 0xff) << 8) |
(((value >> 8) & 0xff) << 16) |
((value & 0xff) << 24);
}
void double_buffer_zero(void **buffer, int *length, uint64_t bytes_per_entry) {
void *new_buffer = heap_alloc(2 * *length * bytes_per_entry);
memcpy(new_buffer, *buffer, *length * bytes_per_entry);
heap_dealloc(*buffer, *length * bytes_per_entry);
memzero(new_buffer + *length * bytes_per_entry, *length * bytes_per_entry);
*buffer = new_buffer;
*length *= 2;
}