Use fwrite and fputs instead of multiple putc

This commit is contained in:
Rangi42
2024-03-07 12:24:03 -05:00
parent 7663a777d5
commit 184957c0ed

View File

@@ -43,18 +43,20 @@ static std::deque<Assertion> assertions;
static std::deque<FileStackNode *> fileStackNodes; static std::deque<FileStackNode *> fileStackNodes;
// Write a long to a file (little-endian) // Write a long to a file (little-endian)
static void putlong(uint32_t i, FILE *f) { static void putlong(uint32_t n, FILE *f) {
putc(i, f); uint8_t bytes[] = {
putc(i >> 8, f); (uint8_t)n,
putc(i >> 16, f); (uint8_t)(n >> 8),
putc(i >> 24, f); (uint8_t)(n >> 16),
(uint8_t)(n >> 24),
};
fwrite(bytes, 1, sizeof(bytes), f);
} }
// Write a NUL-terminated string to a file // Write a NUL-terminated string to a file
static void putstring(std::string const &s, FILE *f) { static void putstring(std::string const &s, FILE *f) {
for (char c : s) fputs(s.c_str(), f);
putc(c, f); putc('\0', f);
putc(0, f);
} }
void out_RegisterNode(FileStackNode *node) { void out_RegisterNode(FileStackNode *node) {