Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large file support in C++

64bit file API is different on each platform.

in windows: _fseeki64
in linux: fseeko
in freebsd: yet another similar call ...

How can I most effectively make it more convenient and portable? Are there any useful examples?

like image 356
Mad Fish Avatar asked Jun 08 '09 16:06

Mad Fish


People also ask

Which file system supports large files?

Advantages of the NTFS system Allows you to set disk quotas format volumes up to 2TB. You can use the NTFS file system with Mac OS X and Linux operating systems. This file system helps you to minimize the number of accesses to find a file. It supports large files, and it nearly has no realistic partition size limit.

What is large file system?

Large-file support (LFS) is the term frequently applied to the ability to create files larger than either 2 or 4 GiB on 32-bit filesystems.


1 Answers

Most POSIX-based platforms support the "_FILE_OFFSET_BITS" preprocessor symbol. Setting it to 64 will cause the off_t type to be 64 bits instead of 32, and file manipulation functions like lseek() will automatically support the 64 bit offset through some preprocessor magic. From a compile-time point of view adding 64 bit file offset support in this manner is fairly transparent, assuming you are correctly using the relevant typedefs. Naturally, your ABI will change if you're exposing interfaces that use the off_t type. Ideally you should define it on the command line, e.g.:

cxx -D_FILE_OFFSET_BITS=64

to make sure it applies to all OS headers included by your code.

Unfortunately, Windows doesn't support this preprocessor symbol so you'll either have to handle it yourself, or rely on a library that provides cross-platform large file support. ACE is one such library (both POSIX based and Windows platforms - just define _FILE_OFFSET_BITS=64 in both cases). I know that Boost.filesystem also supports large files on POSIX based platforms, but I'm not sure about Windows. Other cross-platform libraries likely provide similar support.

like image 151
Void Avatar answered Sep 20 '22 04:09

Void