#include <stdlib.h>
#include <stdio.h>
#ifdef __linux__
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#endif
unsigned int GetFileLen(FILE *stream)
{
unsigned int curpos = 0;
unsigned int length = 0;
curpos = ftell(stream);//ftell用于获取当前指针相对于文件开头的偏移字节数
if(-1==fseek(stream, 0L, SEEK_END) //指向文件尾 偏离文件尾为0的地方
{
printf("fseek File SEEK_END Error!\n");
return 0;
}
length = ftell(stream);//获取文件长度
if(-1==fseek(stream, curpos, SEEK_SET))//重新将文件指针指向原来的位置curpos,恢复现场!!
{
printf("fseek File SEEK_SET Error!\n");
return 0;
}
return length;
}
/*获取以 ulAlign 对齐的文件长度,有可能存在文件对齐的要求*/
unsigned int BspAlignSize(unsigned int ulAlign, unsigned int ulSize)
{
if(ulSize & (ulAlign - 1))
{
return ((ulSize + ulAlign) & (~(ulAlign - 1)));
}
else
{
return ulSize;
}
}