简而言之:C 中的跨操作系统、大文件支持非常糟糕。
目标:我正在尝试使用“一种方式”(很可能是基于宏的方式)来允许 32 位和 64 位具有大文件支持。理想情况下,使用 typedef、#ifdef、#(n)defined 等,宏包装器可以以#include 库或一组定义的宏的形式允许基本的大文件支持。
研究:POSIX 的文件操作在 BSD/Mac/Linux 上的 32 位和 64 位 IO 上表现良好,文件大于典型的 2^31 大小,但即使在 Windows 上使用 clang 或 mingw由于 M$ 对 POSIX 的愚蠢实现,我无法利用这些调用(如果我们想这样调用它...)。我倾向于在 Windows 上使用 CreateFile()、ReadFile()、WriteFile(),但这在方法和数据类型方面与 POSIX 的 open()/read()/write()/close()/等完全不同用过。
问题:在我的头撞到我的键盘和几本教科书之后,我决定对你们所有人进行投票,看看:你们如何完成跨操作系统文件支持大文件的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
最佳答案
关于c - 如何 : Cross-Operating-System Large File IO in C?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23257025/