[Patch, libfortran] PR 40812 Large file support on MinGW
Kai Tietz
ktietz70@googlemail.com
Thu Dec 3 10:41:00 GMT 2009
Interesting was that my last patch just worked as the restoration seek
use SEEK_CUR, which puzzled me a bit. Finally I found the real issue
here in the patch.
First I cleaned up this this temporary variable for comparison with
INVALID_HANDLE_VALUE. This define is a pointer already, and so no
scalar cast is necessary here.
Secondly for the seek to position to be truncated, FILE_CUR was used,
but of course it has to be seeked from beginning of file by
FILE_BEGIN.
This code I've tested for x86_64-pc-mingw32, i686-pc-mingw32. For w64
version and for mingw.org's version. The failed test Danny noticed,
works now well.
Cheers,
Kai
static int
raw_truncate (unix_stream * s, gfc_offset length)
{
#ifdef __MINGW32__
LARGE_INTEGER tmp;
HANDLE h;
gfc_offset old;
if (isatty (s->fd))
{
errno = EBADF;
return -1;
}
old = lseek (s->fd, 0, SEEK_CUR);
h = _get_osfhandle (s->fd);
if (h == INVALID_HANDLE_VALUE)
{
runtime_error ("Couldn't get handle from fd");
return -1;
}
tmp.QuadPart = length;
if (!SetFilePointerEx (h, tmp, NULL, FILE_BEGIN))
{
runtime_error ("Couldn't seek to specified position for truncation");
return -1;
}
if (!SetEndOfFile (h))
{
runtime_error ("Couldn't truncate file");
return -1;
}
lseek (s->fd, old, SEEK_SET);
return 0;
#elif defined HAVE_FTRUNCATE
return ftruncate (s->fd, length);
#elif defined HAVE_CHSIZE
return chsize (s->fd, length);
#else
runtime_error ("required ftruncate or chsize support not present");
return -1;
#endif
}
--
| (\_/) This is Bunny. Copy and paste
| (='.'=) Bunny into your signature to help
| (")_(") him gain world domination
More information about the Fortran
mailing list