This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ftruncate64() question?


> What's wrong with ftruncate?

ftruncate fails with files larger >= 2GB because off_t gets interpreted as
32 bit signed integer...

I can find some archived cygwin messages referencing bug fixes to
ftruncate64 in the cygwin.dll.  However, using ftruncate64 results in an
unresolved symbol.

In fact based on those messages, I inserted the following code in my program
as a workaround for a truncate64() function:

#if defined(__CYGWIN__)||defined(__GW32__)
__int64 truncate64(const char *filename,__int64 newFileSize)
{
  DWORD dw;
  HANDLE h=CreateFile(filename,GENERIC_WRITE,0,NULL,OPEN_ALWAYS,0,NULL);
  DeviceIoControl(h,FSCTL_SET_SPARSE,NULL,0,NULL,0,&dw,NULL);
  SetFilePointerEx(h,(LARGE_INTEGER)newFileSize,NULL,FILE_BEGIN);
  SetEndOfFile(h);
  CloseHandle(h);
  return newFileSize;
}
#endif

This seems to work up to file sizes of 16TeraBytes, which for my purposes is
more than adiquate.

                                                      Bill





--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]