-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOutfile.c
62 lines (55 loc) · 1.16 KB
/
Outfile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "Outfile.h"
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
static FILE* outFile;
static FILE* outFileData;
bool Outfile_TryOpen(char* path)
{
outFile = fopen(path, "w");
if (outFile == NULL)
return false;
outFileData = fopen("data.bin", "w");
if (outFileData == NULL)
return false;
return true;
}
void Outfile_CloseFiles()
{
fclose(outFile);
fclose(outFileData);
}
void OutWrite(const char* format, ...)
{
#ifndef CUSTOM_COMP
va_list args;
va_start(args, format);
vfprintf(outFile, format, args);
// vprintf(format, args);
va_end(args);
#endif
#ifdef CUSTOM_COMP
vfprintf(outFile, format, (void*)(format - 1));
#endif
}
#ifndef CUSTOM_COMP
void OutWriteData(const uint8_t* data, size_t len)
{
fwrite(data, sizeof(uint8_t), len, outFileData);
}
#endif
#ifdef CUSTOM_COMP
void OutWriteData(const uint16_t* data, size_t len)
{
fwrite(data, sizeof(uint16_t), len, outFileData);
}
#endif
void OutWriteZeros(size_t size)
{
// Yeah, this is slow...
uint16_t zero = 0;
while (size--)
fwrite(&zero, sizeof(uint16_t), 1, outFileData);
}