-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented and documented
write8
function
- Loading branch information
1 parent
8d515bc
commit ae4b3d0
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdint.h> | ||
|
||
/** | ||
* @author cheng-alvin | ||
* @since v0.0.1 | ||
* | ||
* Writes 8 bits or a single byte to the specified `buffer` | ||
* pointer. Useful for generating machine code in executables. | ||
* | ||
* @param buffer The pointer for the buffer to write to. | ||
* @param value The value to write. | ||
* | ||
* @note Please note that the value should be 1 byte | ||
* or 8 bits wide when passing into this function. | ||
* | ||
* @returns The pointer to the buffer. | ||
*/ | ||
|
||
uint8_t *write8(uint8_t *buffer, uint8_t value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
uint8_t *write8(uint8_t *buffer, uint8_t value) { | ||
const int len = *buffer / sizeof(uint8_t); | ||
buffer = realloc(buffer, len + sizeof(uint8_t)); | ||
|
||
buffer[len] = value; | ||
|
||
return buffer; | ||
} |