It will be accesibe by anything if you declare a global pointer.
You can do the malloc anywhere, the pointer and the data will be valid until you free it up.
Just always check the buffer is valid (Not NULL) before accessing it.
uint8_t buf;
int allocate_buffer(void){
(...)
fileLen = ftell(binary);
buf=malloc(fileLen);
return(buf==NULL); // Always check for valid pointer. If NULL, buffer allocation failed, return 1.
}
int process_buffer(void){
if(buf==NULL) // It won't harm to check again the pointer is valid. As the program grows, new bugs are introduced, this might save your a$$ :)
return 1;
( do whatever with buffer )
free(buf); //Done
buf=NULL; // Good practice to clear the pointer after freeing it up.
}
int main(void){
if(allocate_buffer())
error();
else
process_buffer();
}