Skip to content

Commit

Permalink
Update write.c
Browse files Browse the repository at this point in the history
  • Loading branch information
cheng-alvin committed Nov 2, 2023
1 parent 5c7b7e7 commit 068d8f0
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/write.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
#include "write.h"
#include "endian.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

uint8_t *write8(uint8_t *buffer, uint8_t value) {
const int len = *buffer / sizeof(uint8_t);
buffer = realloc(buffer, len + sizeof(uint8_t));
uint8_t *write8(uint8_t *buffer, uint8_t value, int *len) {
buffer = realloc(buffer, (*len) + sizeof(uint8_t));

buffer[len] = value;
buffer[(*len)] = value;
(*len) += sizeof(uint8_t);

return buffer;
}

uint8_t *write16(uint8_t *buffer, uint16_t value) {
const int len = *buffer / sizeof(uint16_t);
buffer = realloc(buffer, len + sizeof(uint16_t));

uint8_t *write16(uint8_t *buffer, uint16_t value, int *len) {
buffer = realloc(buffer, (*len) + sizeof(uint16_t));
value = little_endian16(value);
buffer[len] = value;

buffer[(*len)] = (value >> 8) & 0xFF;
buffer[(*len) + 1] = value & 0xFF;
(*len) += sizeof(uint16_t);

return buffer;
}
}

0 comments on commit 068d8f0

Please sign in to comment.