NO

Author Topic: _ftruncate64 on large files?  (Read 4130 times)

Offline drhoule

  • Member
  • *
  • Posts: 10
_ftruncate64 on large files?
« on: September 24, 2013, 08:15:27 PM »
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.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: _ftruncate64 on large files?
« Reply #1 on: September 24, 2013, 10:23:37 PM »
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.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: _ftruncate64 on large files?
« Reply #2 on: September 25, 2013, 05:57:42 AM »
_ftruncate uses an _off_t type that is a long long.
just in x64

sys\types.h
Code: [Select]
#if __POCC_TARGET__ == 3
typedef long long _off_t;
#else
typedef long _off_t;
« Last Edit: September 25, 2013, 06:12:27 AM by timovjl »
May the source be with you

Offline drhoule

  • Member
  • *
  • Posts: 10
Re: _ftruncate64 on large files?
« Reply #3 on: September 25, 2013, 12:31:29 PM »
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

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: _ftruncate64 on large files?
« Reply #4 on: September 25, 2013, 01:18:13 PM »
Try this:
 
Code: [Select]
#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.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline drhoule

  • Member
  • *
  • Posts: 10
Re: _ftruncate64 on large files?
« Reply #5 on: September 25, 2013, 02:18:24 PM »
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.

Offline drhoule

  • Member
  • *
  • Posts: 10
Re: _ftruncate64 on large files?
« Reply #6 on: September 25, 2013, 06:39:23 PM »
Tested. Confirmed!

Your proposed solution is good.
Thank you very much.

Dr

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: _ftruncate64 on large files?
« Reply #7 on: September 26, 2013, 03:01:02 PM »
Good  8)
You're welcome
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

zohanx747

  • Guest
Re: _ftruncate64 on large files?
« Reply #8 on: October 30, 2013, 11:24:39 AM »
I will test it and or modify it as needed, in the comming months as I work on this small project.