This has been troubling me for some time; this function doesn’t even return, it just segfaults. I specify a correct file location, I check for errors at every possible point in the function, I don’t understand?
GLchar* getShaderString(const GLchar* file_path){
FILE* srcfile = NULL;
if(!(srcfile = fopen(file_path, "r")))
return(NULL);
fseek(srcfile, 0l, SEEK_END);
long len;
if((len = ftell(srcfile)) == -1)
return (NULL);
fseek(srcfile, 0l, SEEK_SET);
GLchar* buff;
if(!(buff = malloc(len + 1)))
return (NULL);
fread((GLvoid*)buff, len, 1, srcfile);
fclose(srcfile);
buff[len + 1] = '\0';
return (buff);
}
fopen works on
const char*notconst GLchar*.Also,
buff[len+1] = '\0';should bebuff[len] = '\0';.