When writing portable code, you should look to create your own wrapper functions around the variable functionality.
Eg.
Code:
#ifdef WIN32
// Windows
long long myGetFileSize ( const char *filename ) {
long long result = -1;
LARGE_INTEGER answer;
HANDLE hFile = CreateFile( filename, ... );
if ( GetFileSizeEx(hFile,&answer) ) {
result = (long long)answer;
}
CloseHandle(hFile);
return result;
}
#else
// assume POSIX
long long myGetFileSize ( const char *filename ) {
long long result = -1;
int fd = open(filename,O_RDONLY);
if ( fd >= 0 ) {
result = lseek64(fd, 0, SEEK_END);
}
close(fd);
return result;
}
#endif
In a larger project, you'll end up with several of these, so it make sense to have
- porting.h containing all the prototypes
- porting_win32.c containing all the win32 stuff
- porting_posix.c containing all the posix stuff
So you compile all your code, and whichever of the porting.... files makes sense for the platform you're using.