Text Wrapping Complete

This commit is contained in:
2021-05-25 07:52:53 -07:00
parent ad8b1ccd3e
commit 6e6497ca43
6 changed files with 182 additions and 6 deletions

23
src/util/mem.c Normal file
View File

@ -0,0 +1,23 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "mem.h"
void * memBufferResize(void *oldBuffer, int32_t oldSize, int32_t newSize,
size_t size
) {
// Malloc a new buffer
void *newBuffer = malloc(size * newSize);
// Copy old data
memcpy(newBuffer, oldBuffer, size * oldSize);
// Clear old buffer
free(oldBuffer);
return newBuffer;
}

26
src/util/mem.h Normal file
View File

@ -0,0 +1,26 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
/**
* Resizes a buffer to hold new amounts of data. Essentially a 3 step process of
* - Malloc (new buffer)
* - Memcpy (from old buffer)
* - Free (old buffer)
* - Return (new buffer)
*
* @param oldBuffer The old buffer.
* @param oldSize The current size of the old buffer.
* @param newSize Size of the new buffer.
* @param size Size of the elements within the buffer.
* @return The new buffer.
*/
void * memBufferResize(void *oldBuffer, int32_t oldSize, int32_t newSize,
size_t size
);