MCPcopy Create free account
hub / github.com/DacoTaco/priiloader / ReadFile

Function ReadFile

tools/bootloader/source/bootloader.cpp:68–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68int ReadFile(FileInfo* info)
69{
70 if (info == NULL || info->Filename.size() == 0)
71 return -1;
72
73 FILE* file;
74 unsigned char* data = NULL;
75 unsigned int size = 0;
76#ifdef DEBUG
77 printf("reading %s ...\r\n", info.Filename.c_str());
78#endif
79
80 file = fopen(info->Filename.c_str(), "rb");
81 if (!file)
82 return -2;
83
84 fseek(file, 0, SEEK_END);
85 size = ftell(file);
86 rewind(file);
87
88 // allocate memory to contain the whole file:
89 data = (unsigned char*)malloc(size);
90 if (data == NULL)
91 {
92 printf("Memory error\r\n");
93 fclose(file);
94 return -3;
95 }
96 memset(data, 0, size);
97 //copy the file into the buffer:
98 if (fread(data, 1, size, file) != size)
99 {
100 fclose(file);
101 free(data);
102 return -4;
103 }
104 fclose(file);
105
106 info->Data = data;
107 info->FileSize = size;
108
109 return 1;
110}
111
112void ShowHelp()
113{

Callers 1

mainFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected