-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.c
More file actions
42 lines (33 loc) · 927 Bytes
/
basic.c
File metadata and controls
42 lines (33 loc) · 927 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef float f32;
typedef double f64;
typedef bool b8;
u8* load_file(const char* filename, u32* file_size) {
FILE* file = fopen(filename, "rb");
fseek(file, 0, SEEK_END);
*file_size = ftell(file);
fseek(file, 0, SEEK_SET);
u8* buffer = (u8*)malloc(*file_size + 1);
fread(buffer, 1, *file_size, file);
buffer[*file_size] = '\0';
return buffer;
}
u8* load_file_wh(const char* filename, u32* file_size, u32* width, u32* height) {
u8* buffer = load_file(filename, file_size);
for (u32 i = 0; i < *file_size; i++) {
if (buffer[i] == '\n') { *width = i+1; break; }
}
*height = *file_size / *width;
return buffer;
}