从一个文件中读取数据到一块buffer中
fp = fopen(file_path, "r");
if(fp == NULL)
return -1;
fseek(fp, 0, SEEK_END);
unsigned int length = ftell(fp);
rewind(fp);
if(!(buf = malloc(length)))
{
printf("malloc failed\n");
fclose(fp);
return -1;
}
if(fread(buf, 1, length, fp) != length)
{
printf("read failed\n");
fclose(fp);
free(buf);
return -1;
}
fclose(fp);