+2009-12-04 Janne Blomqvist <jb@gcc.gnu.org>
+
+ PR libfortran/40812
+ * libgfortran.h: typedef gfc_offset differently for MinGW.
+ * io/unix.h (struct stream): Change function pointers to use
+ gfc_offset instead of off_t.
+ (sseek): Change prototype to use gfc_offset instead of off_t.
+ (stell): Likewise.
+ (struncate): Likewise.
+ * io/unix.c: Redefine lseek() for mingw.
+ (raw_seek): Use gfc_offset instead of off_t.
+ (raw_tell): Likewise.
+ (buf_seek): Likewise.
+ (buf_tell): Likewise.
+ (buf_truncate): Likewise.
+ (mem_seek): Likewise.
+ (mem_tell): Likewise.
+ (mem_truncate): Likewise.
+ (fd_to_stream): Likewise.
+ (file_length): Likewise.
+ (raw_truncate): Use gfc_offset instead of off_t, add large file
+ capable implementation for MinGW.
+
2009-11-30 Janus Weil <janus@gcc.gnu.org>
* gfortran.map: Add _gfortran_is_extension_of.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#define lseek _lseeki64
+
static uint64_t
id_from_handle (HANDLE hFile)
{
return nbyte - bytes_left;
}
-static off_t
-raw_seek (unix_stream * s, off_t offset, int whence)
+static gfc_offset
+raw_seek (unix_stream * s, gfc_offset offset, int whence)
{
return lseek (s->fd, offset, whence);
}
-static off_t
+static gfc_offset
raw_tell (unix_stream * s)
{
return lseek (s->fd, 0, SEEK_CUR);
}
static int
-raw_truncate (unix_stream * s, off_t length)
+raw_truncate (unix_stream * s, gfc_offset length)
{
-#ifdef HAVE_FTRUNCATE
+#ifdef __MINGW32__
+ HANDLE h;
+ gfc_offset cur;
+
+ if (isatty (s->fd))
+ {
+ errno = EBADF;
+ return -1;
+ }
+ h = _get_osfhandle (s->fd);
+ if (h == INVALID_HANDLE_VALUE)
+ {
+ errno = EBADF;
+ return -1;
+ }
+ cur = lseek (s->fd, 0, SEEK_CUR);
+ if (cur == -1)
+ return -1;
+ if (lseek (s->fd, length, SEEK_SET) == -1)
+ goto error;
+ if (!SetEndOfFile (h))
+ {
+ errno = EBADF;
+ goto error;
+ }
+ if (lseek (s->fd, cur, SEEK_SET) == -1)
+ return -1;
+ return 0;
+ error:
+ lseek (s->fd, cur, SEEK_SET);
+ return -1;
+#elif defined HAVE_FTRUNCATE
return ftruncate (s->fd, length);
#elif defined HAVE_CHSIZE
return chsize (s->fd, length);
return nbyte;
}
-static off_t
-buf_seek (unix_stream * s, off_t offset, int whence)
+static gfc_offset
+buf_seek (unix_stream * s, gfc_offset offset, int whence)
{
switch (whence)
{
return offset;
}
-static off_t
+static gfc_offset
buf_tell (unix_stream * s)
{
return s->logical_offset;
}
static int
-buf_truncate (unix_stream * s, off_t length)
+buf_truncate (unix_stream * s, gfc_offset length)
{
int r;
}
-static off_t
-mem_seek (stream * strm, off_t offset, int whence)
+static gfc_offset
+mem_seek (stream * strm, gfc_offset offset, int whence)
{
unix_stream * s = (unix_stream *) strm;
switch (whence)
}
-static off_t
+static gfc_offset
mem_tell (stream * s)
{
return ((unix_stream *)s)->logical_offset;
static int
mem_truncate (unix_stream * s __attribute__ ((unused)),
- off_t length __attribute__ ((unused)))
+ gfc_offset length __attribute__ ((unused)))
{
return 0;
}
fstat (fd, &statbuf);
- if (lseek (fd, 0, SEEK_CUR) == (off_t) -1)
+ if (lseek (fd, 0, SEEK_CUR) == (gfc_offset) -1)
s->file_length = -1;
else
s->file_length = S_ISREG (statbuf.st_mode) ? statbuf.st_size : -1;
gfc_offset
file_length (stream * s)
{
- off_t curr, end;
+ gfc_offset curr, end;
if (!is_seekable (s))
return -1;
curr = stell (s);
{
ssize_t (*read) (struct stream *, void *, ssize_t);
ssize_t (*write) (struct stream *, const void *, ssize_t);
- off_t (*seek) (struct stream *, off_t, int);
- off_t (*tell) (struct stream *);
+ gfc_offset (*seek) (struct stream *, gfc_offset, int);
+ gfc_offset (*tell) (struct stream *);
/* Avoid keyword truncate due to AIX namespace collision. */
- int (*trunc) (struct stream *, off_t);
+ int (*trunc) (struct stream *, gfc_offset);
int (*flush) (struct stream *);
int (*close) (struct stream *);
};
return s->write (s, buf, nbyte);
}
-static inline off_t
-sseek (stream * s, off_t offset, int whence)
+static inline gfc_offset
+sseek (stream * s, gfc_offset offset, int whence)
{
return s->seek (s, offset, whence);
}
-static inline off_t
+static inline gfc_offset
stell (stream * s)
{
return s->tell (s);
}
static inline int
-struncate (stream * s, off_t length)
+struncate (stream * s, gfc_offset length)
{
return s->trunc (s, length);
}