View Single Post
Old 23rd November 2014, 13:43   #21  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
Quote:
Originally Posted by TheFluff View Post
_fseeki64() and _ftelli64() are what you want but who knows if they're available in your ancient runtime
(looks like they're not, VS2005 or newer I think)
Either that, or just use the _fstati64() function, which avoids having to move the file pointer around. Also you don't need to go down to the Win32 API this way.

It appears to be available in VS 6.0:
http://msdn.microsoft.com/en-us/libr...=vs.60%29.aspx
Code:
#include <sys/stat.h>

__int64 getFileSize64(FILE *const fp)
{
	struct _stati64 stat;
	if(_fstati64(_fileno(fp), &stat) != 0)
	{
		return -1; /*some error occurred*/
	}
	return stat.st_size;
}

Quote:
Originally Posted by StainlessS View Post
I'm not altogether happy about mixing eg file handles and FILE*, but will investigate all things suggested.
On Windows, each FILE* has an associated "native" operating system HANDLE, which you can get via _get_osfhandle(), if you really need to.

It is returned as an intptr_t, but you can typecast to HANDLE safely. I would still prefer the fstat()-based solution, since it's cross-platform.
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 23rd November 2014 at 14:02.
LoRd_MuldeR is offline   Reply With Quote