I’ve written an Ada program which encrypts files. It reads them block by block to conserve memory on the target machine. Unfortunately Ada’s Directories library reads filesizes in a Long_Integer, limiting the read to almost 2GB files. When trying to read files over 2GB, the program fails at runtime getting a stack overflow error.
The documentation for it here is the origin of my understanding above. How can I read a filesize into a type I define myself? One I can make requiring something like 25 bytes to increase the cap to 100GB.
I just posted GCC bug 55119 on this.
While you’re waiting (!), the code below works on Mac OS X Mountain Lion. On Windows, it’s more complicated; see
adainclude/adaint.{c,h}.The Ada spec:
and body (copied in part from
Ada.Directories):and the C interface:
You might need to use
struct stat64andstat64()on other Unix systems.Compile the C interface as normal, then add
-largs large_files_interface.oto your gnatmake command line.EDIT: on Mac OS X (and Debian), which are x86_64 machines,
sizeof(long)is 8 bytes; so the comment inadaint.cis misleading andAda.Directories.Sizecan return up to 2**63-1.