MCPcopy Create free account
hub / github.com/defold/defold / ReadFile

Function ReadFile

engine/modelc/src/modelimporter_debug.cpp:24–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22{
23
24void* ReadFile(const char* path, uint32_t* file_size)
25{
26 FILE* file = fopen(path, "rb");
27 if (!file)
28 {
29 printf("Failed to load %s\n", path);
30 return 0;
31 }
32
33 fseek(file, 0, SEEK_END);
34 size_t size = (size_t)ftell(file);
35 fseek(file, 0, SEEK_SET);
36
37 void* mem = malloc(size);
38
39 size_t nread = fread(mem, 1, size, file);
40 fclose(file);
41
42 if (nread != size)
43 {
44 printf("Failed to read %u bytes from %s\n", (uint32_t)size, path);
45 free(mem);
46 return 0;
47 }
48
49 if (file_size)
50 *file_size = size;
51
52 return mem;
53}
54
55static void OutputIndent(int indent)
56{

Callers 5

BufferResolveUriFunction · 0.70
LoadFromPathFunction · 0.70
BufferResolveUriFunction · 0.50
LoadSceneFunction · 0.50
TESTFunction · 0.50

Calls 2

mallocFunction · 0.85
freeFunction · 0.85

Tested by 3

BufferResolveUriFunction · 0.40
LoadSceneFunction · 0.40
TESTFunction · 0.40