Just an internal utility func., not to be published via API!
| 44 | |
| 45 | // Just an internal utility func., not to be published via API! |
| 46 | file_buffer file_to_buffer(const char *path) { |
| 47 | file_buffer fb; |
| 48 | fb.buffer = nullptr; |
| 49 | fb.file_len = 0; |
| 50 | |
| 51 | NULL_CHECK(fb, path); |
| 52 | FILE *fileptr; |
| 53 | uint8_t *buffer; |
| 54 | size_t filelen; |
| 55 | |
| 56 | fileptr = fopen(path, "rb"); |
| 57 | NULL_CHECK(fb, fileptr); |
| 58 | |
| 59 | fseek(fileptr, 0, SEEK_END); |
| 60 | filelen = ftell(fileptr); |
| 61 | rewind(fileptr); |
| 62 | |
| 63 | buffer = (uint8_t *)malloc((filelen+1)*sizeof(uint8_t)); // Enough memory for file + \0 |
| 64 | const size_t read_result = fread(buffer, filelen, 1, fileptr); |
| 65 | fclose(fileptr); |
| 66 | |
| 67 | if (read_result != 1) { |
| 68 | free(buffer); |
| 69 | return fb; |
| 70 | } |
| 71 | |
| 72 | fb.buffer = buffer; |
| 73 | fb.file_len = filelen; |
| 74 | return fb; |
| 75 | } |
| 76 | |
| 77 | int API_INITIALIZER::initialized = initialize_api(); |
| 78 |
no outgoing calls
no test coverage detected