获取用C文件尺寸较大 [英] Get Large File Size in C

查看:162
本文介绍了获取用C文件尺寸较大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在有人抱怨的重复,我已经检查SO相当彻底,但似乎没有干净的答案,虽然看起来问题很简单。

Before anyone complains of "duplicate", I've been checking SO quite thoroughly, but there seem to be no clean answer yet, although the question looks quite simple.

我在寻找一个可移植的C code ,这是能够提供文件的大小,即使这样的文件大于4GB的。

I'm looking for a portable C code, which is able to provide the size of a file, even if such a file is bigger than 4GB.

通常的方法(fseek的,FTELL)工作正常,只要文件保持< 2GB。这是相当良好的支持无处不在,所以我试图找到一些相当于

The usual method (fseek, ftell) works fine, as long as the file remains < 2GB. It's fairly well supported everywhere, so I'm trying to find something equivalent.

不幸的是,已更新的方法(fseeko,ftello)不被所有的编译器支持。例如,MinGW的想念它(显然MSVC)。此外,一些评论让我相信,新的返回类型(off_t)不一定支持大小> 2GB,这可能取决于某些外部参数,进行检查。

Unfortunately, the updated methods (fseeko, ftello) are not supported by all compilers. For example, MinGW miss it (and obviously MSVC). Furthermore, some comments make me believe that the new return type (off_t) does not necessarily support size > 2GB, it may depend on some external parameters, to be checked.

的明确方法(位置fseeko64,ftello64​​)不受MSVC的支持。 MS提供等效的,_fseeki64&安培; _ftelli64。这已经是坏,但它变得更差:一些Linux的配置似乎在运行时非常支持这些功能。例如,我的Debian挤压PowerPC上,使用GCC 4.4,会产生使用的位置fseeko64一个文件大小的方法,它总是返回0(虽然它工作正常Ubuntu64)。 MinGW的似乎回答2GB以上的一些随机的垃圾。

The unambiguous methods (fseeko64, ftello64) are not supported by MSVC. MS provides their equivalent, _fseeki64 & _ftelli64. This is already bad, but it becomes worse : some Linux configurations seem to badly support these functions during run time. For example, my Debian Squeeze on PowerPC, using GCC 4.4, will produce a "filesize" method using fseeko64 which always return 0 (while it works fine for Ubuntu64). MinGW seems to answer some random garbage above 2GB.

好吧,我是一个有点无能尽可能便携性而言。如果我需要做一大堆的#if #else伪的,那么为什么不直接到OS&放大器;编译器的细节在首位)为MSVC方法,如GetFileSize(例如

Well, I'm a bit clueless as far as portability is concerned. And if I need to make a bunch of #if #else, then why not go straight to the OS & compilers specifics methods in the first place, such as GetFileSize() for MSVC for example.

推荐答案

您说的那样:没有可移植的方法;如果我是你,我会刚刚与 GetFileSize 走在Windows和统计的POSIX。

You said it: there's no portable method; if I were you I'd just go with GetFileSize on Windows and stat on POSIX.

这篇关于获取用C文件尺寸较大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆