I have found a “solution” to this problem. I put this in quotations because I feel it is more of a workaround. Also, I am going to expose the functions and the way in which I used them to make a copy of a file because this was kind of ridiculous.
// Get data from a file and return buffer address //
// ARG1: FILE* readFile -> Pass in a file object that has been open with reading capabilities
// ARG2: int64_t *fileLen -> Pass in an allocated integer, this will hold the size of the data buffer
// RETURN: char * -> Address to the data buffer
char *getFileData(FILE *readFile, int64_t *fileLen)
{
int tempChar;
char *buffer;
int64_t iter = 0;
if (readFile == NULL)
Brain::printf("getFileData(): Read file returned NULL");
fseek(readFile, 0, SEEK_END);
*fileLen = ftell(readFile);
buffer = (char *)malloc((*fileLen) * sizeof(char));
fseek(readFile, 0, SEEK_SET);
while ((tempChar = fgetc(readFile)) != EOF)
{
buffer[iter++] = tempChar;
}
fclose(readFile);
return buffer;
}
// Write data to a file given the buffer address and length //
// ARG1: FILE *writeFile -> Pass in a file object that has been open with write capabilities
// ARG2: char *buffer -> Pass in a data buffer to write to the file
// ARG3: int64_t -> bufferLen -> Length of the allocated buffer
void writeFileData(FILE *writeFile, char *buffer, int64_t bufferLen)
{
if (writeFile == NULL)
Brain::printf("writeFileData(): Write file returned NULL");
for (int64_t i = 0; i < bufferLen; i++)
{
fputc(buffer[i], writeFile);
}
fclose(writeFile);
}
// Using two functions to make a copy of a file //
void someFunction(void)
{
int64_t fileSize;
char *dataBuffer;
FILE *readFile = fopen(fileName, "r");
dataBuffer = getFileData(readFile, &fileSize);
fclose(readFile);
FILE *writeFile = fopen("/usd/test2.dat", "w");
writeFileData(writeFile, dataBuffer, fileSize);
fclose(writeFile);
}
This is the current solution I have found and I will use this unless another more simple method is found.