相关疑难解决方法(0)

32位Windows和2GB文件大小限制(C与fseek和ftell)

我试图将一个小型数据分析程序从64位UNIX移植到32位Windows XP系统(不要问:)).但是现在我遇到了2GB文件大小限制的问题(在这个平台上长时间不是64位).

我搜索了这个网站和其他人可能的解决方案,但找不到任何可以直接翻译我的问题.问题在于使用fseek和ftell.

有没有人知道对以下两个函数的修改,使它们可以在32位Windows XP上运行大于2GB的文件(实际上是100GB).

至关重要的是,nsamples的返回类型是64位整数(可能是int64_t).

long nsamples(char* filename)
{
  FILE *fp;
  long n;

  /* Open file */
  fp = fopen(filename, "rb");

  /* Find end of file */
  fseek(fp, 0L, SEEK_END);

  /* Get number of samples */
  n = ftell(fp) / sizeof(short);

  /* Close file */
  fclose(fp);

  /* Return number of samples in file */
  return n;
}
Run Code Online (Sandbox Code Playgroud)

void readdata(char* filename, short* data, long start, int n)
{
  FILE *fp;

  /* Open file */
  fp = fopen(filename, "rb");

  /* …
Run Code Online (Sandbox Code Playgroud)

c windows porting c99 large-files

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

c ×1

c99 ×1

large-files ×1

porting ×1

windows ×1