I need to get the size of files. These files range in size from very small to 10's of gigabytes. Are there any c functions that work in both linux and windows to do this? I've seen fileinfo64 but that seems to be windows only and i haven't been able to determine the maximum size supported by stat.
A:
Mark
2009-11-02 03:33:41
The question and answers provided do not take into account large files. This question is specifically asking for the possibility of a cross-platform function that can be used to determine the size of potentially large files.
dreamlax
2009-11-02 03:38:49
+3
A:
Linux provides the stat64
call which should be the equivalent of fileinfo64
. I would simply use a #ifdef
to select the correct one.
In fact, a cursory google seems to indicate that stat64
is also available in Windows so it may be easier than you think.
paxdiablo
2009-11-02 03:34:59
+2
A:
In Windows, you can use GetFileSize()
. The first parameter to this function is a handle to the file, and the second parameter takes a reference to a DWORD, which upon return will contain the high 32-bits of the file's size. The function returns the low 32-bits of the file's size.
For example
DWORD dwFileSizeLow;
DWORD dwFileSizeHigh;
HANDLE hFile;
hFile = CreateFile (/* Enter the thousands of parameters required here */);
if (hFile != INVALID_HANDLE_VALUE)
dwFileSizeLow = GetFileSize (hFile, &dwFileSizeHigh);
unsigned __int64 fullSize = (((__int64) dwFileSizeHigh) << 32) | dwFileSizeLow
dreamlax
2009-11-02 03:43:36