/src/shared/load_data.cpp
https://bitbucket.org/vivkin/gam3b00bs/ · C++ · 45 lines · 36 code · 7 blank · 2 comment · 5 complexity · d80c86f1ff928d6bc5df9614668dcefe MD5 · raw file
- #include "load_data.h"
- #include "log.h"
- #include "common.h"
- #include <stdio.h>
- #include <stdlib.h>
- //-----------------------------------------------------------------------------
-
- uint32 load_data( const char* path, uint8** out_data, uint32* out_size )
- {
- ASSERT(path);
- ASSERT(out_data);
- ASSERT(out_size);
-
- FILE* file = fopen(path, "rb");
- if( !file )
- {
- log_write("Error: unable to open file %s for reading");
- return 1;
- }
-
- fseek(file, 0, SEEK_END);
- *out_size = ftell(file);
- rewind(file);
-
- if( *out_size == 0 )
- {
- fclose(file);
- log_write("Error: file %s is empty");
- return 2;
- }
-
- *out_data = (uint8*)malloc(*out_size);
- if( fread(*out_data, *out_size, 1, file) != 1 )
- {
- fclose(file);
- free(out_data);
- log_write("Error: unable to read %s");
- return 3;
- }
-
- fclose(file);
-
- return 0;
- }
- //-----------------------------------------------------------------------------