Here is currently what I am using. Needs a bit more error checking but you can get the gist of it:
#ifdef WIN32 // Not defined in windows, translated to use SetEndOfFile function
int truncate( const char *path, const long long &length ) {
HANDLE hFile = CreateFileA( path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
LARGE_INTEGER li;
li.QuadPart = length;
int ret = -1;
if( SetFilePointer( hFile, li.LowPart, &li.HighPart, FILE_BEGIN ) != INVALID_SET_FILE_POINTER ) {
SetEndOfFile( hFile );
ret = 0;
}
CloseHandle( hFile );
return ret;
}
#endif
No comments:
Post a Comment