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

Function FontReadFile

engine/font/src/util.cpp:36–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

FontLoadFromPathFunction · 0.85

Calls 2

mallocFunction · 0.85
freeFunction · 0.85

Tested by

no test coverage detected