int fseek(FILE *stream, long offset, int whence);
long ftell(FILE *stream);
int fseeko(FILE
*stream, off_t offset, int whence);//off_t 爲64位整數
off_t ftello(FILE *stream);
fseeko64 和 ftello64:確定大型文件的位置和復位大型文件
fseeko64 和 ftello64 是 fseek 和 ftell 的“大型文件”版本。它們採用並返回 INTEGER*8 的文件位置偏移值。(“大型文件”是指大於 2 GB 的文件,因此字節位置必須以 64 位整型值表示。)可使用這些函數確定大型文件的位置和/或復位大型文件int freadall(FILE *stream, char **pbuf, size_t *psize) {
int rt;rt = fseeko(stream, 0L, SEEK_END);
if (rt != 0)
return -1;
off64_t size = ftello64(stream);
if (size < 0)
return -1;
rewind(stream);
void *p = malloc(size);
if (p == NULL)
return -1;
size_t s = fread(p, 1, size, stream);
if ((off64_t)s != size) {
free(p);
return -1;
}
*pbuf = (char *)p;
*psize = size;
return 0;
}