fseek能处理2GB以上的文件吗?
(2012-04-10 03:08:23)
标签:
杂谈
fseek能处理2GB以上的文件吗?fseek函数中偏移量的参数是long int类型的,我机器上long
int是32位的,那么对于超过2GB文件的文件该怎么办呢?找找有没有类似fseeki64之类的函数BTW:
当初制定fseek的人应当受罚,怎么可以硬性定义为long int呢?
应当类似于
typedef long int fpos_t;
int fseek(FILE *stream, fpos_t offset, int whence);
这样当库的实现有能力处理4G以上长度时http://www.boomss.com,只需要修改fpos_t的定义,即fpos_t取决于平台能力。原帖由
ahocat 于 2009-7-7 16:32 发表
http://bbs3.chinaunix.net/images/common/back.gif
fseek函数中偏移量的参数是long int类型的,我机器上long
int是32位的,那么对于超过2GB文件的文件该怎么办呢?
不知道fseek底层是否是用lseek实现的
没有处理过大文件,突然发现自己对于TB级的文件不知道如何处理
翻了一下APUE2
3.6. lseek Function
#include
off_t lseek(int filedes, off_t offset, int whence);
……
Because the offset (off_t) is a signed data type (Figure 2.20), we
lose a factor of 2 in the maximum file size. If off_t is a 32-bit
integer, the maximum file size is 2^31-1 bytes.
……
The Single UNIX Specification provides a way for applications to
determine which environments are supported through the sysconf
function (Section 2.5.4.). Figure 3.3 summarizes the sysconf
constants that are defined.
……
The c99 compiler requires that we use the getconf(1) command to map
the desired data size model to the flags necessary to compile and
link our programs. Different flags and libraries might be needed,
depending on the environments supported by each platform.
Unfortunately, this is one area in which implementations haven't
caught up to the standards. Confusing things further is the name
changes that were made between Version 2 and Version 3 of the
Single UNIX Specification.
To get around this, applications can set the _FILE_OFFSET_BITS
constant to 64 to enable 64-bit offsets. Doing so changes the
definition of off_t to be a 64-bit signed integer. Setting
_FILE_OFFSET_BITS to 32 enables 32-bit file offsets. Be aware,
however, that although all four platforms discus
分享:
喜欢
0
赠金笔
加载中,请稍候......
评论加载中,请稍候...
发评论
登录名: 密码: 找回密码 注册记住登录状态
昵 称:
评论并转载此博文
发评论
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。