【发布时间】:2014-04-23 23:28:26
【问题描述】:
简而言之: C 中的跨操作系统、大文件支持非常可怕。
目标:我正在尝试使用“一种方式”(最有可能基于宏)来允许 32 位和 64 位支持大文件。理想情况下,使用 typedef、#ifdef、#(n)defined 等,宏包装器可以允许以 #include 库或一组已定义宏的形式支持基本的大文件。
研究: POSIX 的文件操作在 32 位和 64 位 IO 的 BSD/Mac/Linux 上表现出色,文件大于典型的 2^31 大小,但即使在 Windows 上使用 clang 或 mingw由于 M$ 对 POSIX 的愚蠢实现,我无法利用这些调用(如果这就是我们想要调用的......)。我倾向于在 Windows 上使用 CreateFile()、ReadFile()、WriteFile(),但这在方法和数据类型方面与 POSIX 的 open()/read()/write()/close()/etc 完全不同用过。
问题:在敲了敲键盘和几本教科书之后,我决定对你们所有人进行投票,看看:你们是如何完成跨操作系统文件的支持大文件的 I/O?
附:我有研究链接:
- http://msdn.microsoft.com/en-us/library/windows/desktop/bb540534(v=vs.85).aspx
- Portable way to get file size in C/C++
- How can I portably turn on large file support?
- http://mingw-users.1079350.n2.nabble.com/not-obvious-how-to-compile-programs-for-large-files-td5699144.html
- http://www.viva64.com/en/l/full/
- https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/64bitPorting/HighLevelAPIs/HighLevelAPIs.html
- https://www.securecoding.cert.org/confluence/display/c/FIO19-C.+Do+not+use+fseek%28%29+and+ftell%28%29+to+compute+the+size+of+a+regular+file
- https://www.securecoding.cert.org/confluence/display/c/FIO03-C.+Do+not+make+assumptions+about+fopen%28%29+and+file+creation
- https://en.wikipedia.org/wiki/Large_file_support
【问题讨论】: