I am attempting to read a binary file into a buffer but the file contains nulls (it's a TIFF file). I need to keep the nulls but the buffer is getting null-terminated as soon as it encounters one. How do I keep the nulls in the buffer and everything that comes after them?
Code:
// Read the file into a buffer
unsigned char *fileBuf;
FILE *ucmFile = NULL;
int fileSize, result;
if ((ucmFile = fopen(szFileNamePath, "rb")) == NULL) {
iRet = 8;
strcpy(outResponse, "Error: Unable to open ");
strcat(outResponse, szFileNamePath);
} else {
fileSize = getFileSize(ucmFile);
fileBuf = (unsigned char*) malloc(sizeof(char)*fileSize);
result = fread(fileBuf, 1, fileSize, ucmFile);
if (result != fileSize) {
iRet = 8;
strcpy(outResponse, "Error: Unable to read ");
strcat(outResponse, szFileNamePath);
}
fclose(ucmFile);
}
I didn't show all of the field definitions or the getFileSize method. The fread command is reading into fileBuf, which is defined as an unsigned char*. fileBuf only contains data up until the first null.
Thanks for your help!