I am dealing with long files...
I can use _ftruncate on short files but not long ones.
_ftruncate uses a long int.
a long long int is required.
How can I code / use _ftruncate with long files?
Any help would be nice.
Thank you in advance!
Dr.
Dindn't understand the question.
_ftruncate uses an _off_t type that is a long long.
The function doesn't care of the size of the file. You can use it on short and large files.
Quote from: frankie on September 24, 2013, 10:23:37 PM
_ftruncate uses an _off_t type that is a long long.
just in x64
sys\types.h
#if __POCC_TARGET__ == 3
typedef long long _off_t;
#else
typedef long _off_t;
More info,
MS VC has this function ...
errno_t _chsize_s( int fd, __int64 size );
but it is not implemented with Pelles C only int _chsize(int handle, long int size);
Dr
Try this:
#include <stdio.h>
#include <io.h>
BOOL SetFileLength(int fd, long long pos)
{
HANDLE fh = (HANDLE)_get_osfhandle(fd);
if (!SetFilePointerEx(fh, *((LARGE_INTEGER *)&pos), NULL, FILE_BEGIN))
return FALSE;
return SetEndOfFile(fh);
}
BOOL fset_file_len(FILE *fp, long long pos)
{
return SetFileLength(_fileno(fp), pos);
}
I had no time to test, but should work.
Your solution looks good.
I accept this as a reasonable fix.
I will test it and or modify it as needed, in the comming months as I work on this small project.
Thank you.
Tested. Confirmed!
Your proposed solution is good.
Thank you very much.
Dr
Good 8)
You're welcome
I will test it and or modify it as needed, in the comming months as I work on this small project.