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

Function ReadFile

engine/shaderc/src/test/test_shaderc.cpp:31–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29#endif
30
31static void* ReadFile(const char* path, uint32_t* file_size)
32{
33 FILE* file = fopen(path, "rb");
34 if (!file)
35 {
36 printf("Failed to load %s\n", path);
37 return 0;
38 }
39
40 fseek(file, 0, SEEK_END);
41 size_t size = (size_t)ftell(file);
42 fseek(file, 0, SEEK_SET);
43
44 void* mem = malloc(size);
45
46 size_t nread = fread(mem, 1, size, file);
47 fclose(file);
48
49 if (nread != size)
50 {
51 printf("Failed to read %u bytes from %s\n", (uint32_t)size, path);
52 free(mem);
53 return 0;
54 }
55
56 if (file_size)
57 {
58 *file_size = size;
59 }
60
61 return mem;
62}
63
64TEST(Shaderc, TestSimpleShader)
65{

Callers 2

TESTFunction · 0.70
TestStandaloneFunction · 0.70

Calls 2

mallocFunction · 0.85
freeFunction · 0.85

Tested by

no test coverage detected