W dniu 26.11.2018 o 23:30, Jacek Caban pisze:
> On 11/26/18 10:31 PM, Martin Storsjö wrote:
>> On Mon, 26 Nov 2018, Jacek Caban wrote:
>>
>>> Hi Mateusz,
>>>
>>>
>>> The patch looks mostly good to me.
>>>
>>>
>>> On 23/11/2018 22:37, Mateusz wrote:
>>>> --- a/mingw-w64-headers/crt/stdio.h
>>>> +++ b/mingw-w64-headers/crt/stdio.h
>>>> @@ -609,31 +609,20 @@ int vsnprintf (char *__stream, size_t __n, const
>>>> char *__format, __builtin_va_li
>>>> /* Shouldn't be any fseeko32 in glibc, 32bit to 64bit casting should
>>>> be fine */
>>>> /* int fseeko32(FILE* stream, _off_t offset, int whence);*/ /*
>>>> fseeko32 redirects to fseeko64 */
>>>> -#if __MSVCRT_VERSION__ >= 0x1400
>>>> +#if __MSVCRT_VERSION__ >= 0x900
>>>> // Mark these as _CRTIMP to avoid trying to link in the mingwex
>>>> versions.
>>>> _CRTIMP int __cdecl _fseeki64(FILE *_File,__int64 _Offset,int _Origin);
>>>> _CRTIMP __int64 __cdecl _ftelli64(FILE *_File);
>>>> - __mingw_static_ovr int fseeko(FILE *_File, _off_t _Offset, int _Origin)
>>>> {
>>>> - return fseek(_File, _Offset, _Origin);
>>>> - }
>>>> - __mingw_static_ovr int fseeko64(FILE *_File, _off64_t _Offset, int
>>>> _Origin) {
>>>> - return _fseeki64(_File, _Offset, _Origin);
>>>> - }
>>>> - __mingw_static_ovr _off_t ftello(FILE *_File) {
>>>> - return ftell(_File);
>>>> - }
>>>> - __mingw_static_ovr _off64_t ftello64(FILE *_File) {
>>>> - return _ftelli64(_File);
>>>> - }
>>>> #else
>>>> __MINGW_EXTENSION int __cdecl _fseeki64(FILE *_File,__int64
>>>> _Offset,int _Origin);
>>>> __MINGW_EXTENSION __int64 __cdecl _ftelli64(FILE *_File);
>>>> +#endif
>>>
>>> I would suggest to get rid of #if here and simply always use _CRTIMP
>>> without __MINGW_EXTENSION. This would require adding symbols with
>>> __MINGW_IMP_SYMBOL to symbols in fseeki64.c.
>>
>> I'm not quite sure I know all the nuances about the difference between e.g.
>> fseeko64 and _fseeki64 (looking at stdio/fseeko64.c, their implementation is
>> rather different), but... On one hand I'd like to keep inline versions in
>> the headers for ucrt, but on the other hand it is unnecessary if the
>> libmingwex versions work as well. If others prefer unifying it I don't mind.
>
>
> Actually I didn't notice that aspect, I concentrated on getting moving part
> right. Before changing that, it would at least deserve a reasoning. I'm not
> sure about nuances as well, so I don't know what's the best solution. I'd
> prefer to simply keep it out of this patch.
>
>
>>
>> In general the patch (the latest version) looks rather straightforward to
>> me, and I'm fine with it if Jacek is.
>
>
> With inline helpers kept for ucrt builds, I will be fine with the patch.
>
>
> Thanks,
>
> Jacek
OK, I've attached minimal version -- inline helpers kept for ucrt, only
_fseeki64 and _ftelli64 moved, I also removed 'DATA' guards for multiple
definition in libmsvcr90 and 100.
Regards,
Mateusz
From f809876dfa33350d713b465cc033e85095fafddc Mon Sep 17 00:00:00 2001
From: Mateusz Brzostek <[email protected]>
Date: Tue, 27 Nov 2018 09:21:36 +0100
Subject: [PATCH] move _fseeki64 and _ftelli64 functions from libmingwex to
libmsvcrt
_fseeki64 and _ftelli64 functions are already in libmsvcr90 and newer,
so we need to provide these functions only for libmsvcrt. In addition,
_ftelli64 function implementation is not compatible with ucrt.
Signed-off-by: Mateusz Brzostek <[email protected]>
---
mingw-w64-crt/Makefile.am | 1 +
mingw-w64-crt/lib32/msvcr100.def.in | 4 +-
mingw-w64-crt/lib32/msvcr90.def.in | 4 +-
mingw-w64-crt/lib64/msvcr100.def.in | 4 +-
mingw-w64-crt/lib64/msvcr90.def.in | 4 +-
mingw-w64-crt/stdio/fseeki64.c | 177 ++++++++++++++++++++++++++++++++++++
mingw-w64-crt/stdio/fseeko64.c | 131 --------------------------
mingw-w64-headers/crt/stdio.h | 5 +-
8 files changed, 187 insertions(+), 143 deletions(-)
create mode 100644 mingw-w64-crt/stdio/fseeki64.c
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 079dc5a..f8b0623 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -210,6 +210,7 @@ src_msvcrt=\
secapi/vsprintf_s.c \
secapi/wmemcpy_s.c \
secapi/wmemmove_s.c \
+ stdio/fseeki64.c \
stdio/mingw_lock.c
src_ucrtbase=\
diff --git a/mingw-w64-crt/lib32/msvcr100.def.in
b/mingw-w64-crt/lib32/msvcr100.def.in
index d103a2b..99a39c9 100644
--- a/mingw-w64-crt/lib32/msvcr100.def.in
+++ b/mingw-w64-crt/lib32/msvcr100.def.in
@@ -880,7 +880,7 @@ _freefls@4
_fscanf_l
_fscanf_s_l
_fseek_nolock
-_fseeki64 DATA
+_fseeki64
_fseeki64_nolock
_fsopen
_fstat32
@@ -890,7 +890,7 @@ _fstat32i64
_fstat64
_fstat64i32
_ftell_nolock
-_ftelli64 DATA
+_ftelli64
_ftelli64_nolock
_ftime32
_ftime32_s
diff --git a/mingw-w64-crt/lib32/msvcr90.def.in
b/mingw-w64-crt/lib32/msvcr90.def.in
index 861ce56..a055ce3 100644
--- a/mingw-w64-crt/lib32/msvcr90.def.in
+++ b/mingw-w64-crt/lib32/msvcr90.def.in
@@ -507,7 +507,7 @@ _freefls@4
_fscanf_l
_fscanf_s_l
_fseek_nolock
-_fseeki64 DATA
+_fseeki64
_fseeki64_nolock
_fsopen
_fstat32
@@ -517,7 +517,7 @@ _fstat32i64
_fstat64
_fstat64i32
_ftell_nolock
-_ftelli64 DATA
+_ftelli64
_ftelli64_nolock
_ftime32
_ftime32_s
diff --git a/mingw-w64-crt/lib64/msvcr100.def.in
b/mingw-w64-crt/lib64/msvcr100.def.in
index b3be302..b9929a6 100644
--- a/mingw-w64-crt/lib64/msvcr100.def.in
+++ b/mingw-w64-crt/lib64/msvcr100.def.in
@@ -837,7 +837,7 @@ _freefls
_fscanf_l
_fscanf_s_l
_fseek_nolock
-_fseeki64 DATA
+_fseeki64
_fseeki64_nolock
_fsopen
_fstat32
@@ -847,7 +847,7 @@ _fstat32i64
_fstat64
_fstat64i32
_ftell_nolock
-_ftelli64 DATA
+_ftelli64
_ftelli64_nolock
_ftime32
_ftime32_s
diff --git a/mingw-w64-crt/lib64/msvcr90.def.in
b/mingw-w64-crt/lib64/msvcr90.def.in
index f18166a..70a14f2 100644
--- a/mingw-w64-crt/lib64/msvcr90.def.in
+++ b/mingw-w64-crt/lib64/msvcr90.def.in
@@ -454,7 +454,7 @@ _freefls
_fscanf_l
_fscanf_s_l
_fseek_nolock
-_fseeki64 DATA
+_fseeki64
_fseeki64_nolock
_fsopen
_fstat32
@@ -464,7 +464,7 @@ _fstat32i64
_fstat64
_fstat64i32
_ftell_nolock
-_ftelli64 DATA
+_ftelli64
_ftelli64_nolock
_ftime32
_ftime32_s
diff --git a/mingw-w64-crt/stdio/fseeki64.c b/mingw-w64-crt/stdio/fseeki64.c
new file mode 100644
index 0000000..fdb8f1c
--- /dev/null
+++ b/mingw-w64-crt/stdio/fseeki64.c
@@ -0,0 +1,177 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <stdio.h>
+#include <io.h>
+#include <errno.h>
+#include <internal.h>
+
+#define _IOYOURBUF 0x0100
+#define _IOSETVBUF 0x0400
+#define _IOFEOF 0x0800
+#define _IOFLRTN 0x1000
+#define _IOCTRLZ 0x2000
+#define _IOCOMMIT 0x4000
+
+/* General use macros */
+
+#define inuse(s) ((s)->_flag & (_IOREAD|_IOWRT|_IORW))
+#define mbuf(s) ((s)->_flag & _IOMYBUF)
+#define nbuf(s) ((s)->_flag & _IONBF)
+#define ybuf(s) ((s)->_flag & _IOYOURBUF)
+#define bigbuf(s) ((s)->_flag & (_IOMYBUF|_IOYOURBUF))
+#define anybuf(s) ((s)->_flag & (_IOMYBUF|_IONBF|_IOYOURBUF))
+
+#define _INTERNAL_BUFSIZ 4096
+#define _SMALL_BUFSIZ 512
+
+#define FOPEN 0x01 /* file handle open */
+#define FEOFLAG 0x02 /* end of file has been encountered */
+#define FCRLF 0x04 /* CR-LF across read buffer (in text mode) */
+#define FPIPE 0x08 /* file handle refers to a pipe */
+#define FNOINHERIT 0x10 /* file handle opened _O_NOINHERIT */
+#define FAPPEND 0x20 /* file handle opened O_APPEND */
+#define FDEV 0x40 /* file handle refers to device */
+#define FTEXT 0x80 /* file handle is in text mode */
+
+_CRTIMP __int64 __cdecl _lseeki64(int fh,__int64 pos,int mthd);
+__int64 __cdecl _ftelli64(FILE *str);
+
+#if !defined(__arm__) && !defined(__aarch64__) /* we have F_ARM_ANY(_fseeki64)
in msvcrt.def.in */
+int __cdecl _flush (FILE *str);
+
+int __cdecl _flush (FILE *str)
+{
+ FILE *stream;
+ int rc = 0; /* assume good return */
+ __int64 nchar;
+
+ stream = str;
+ if ((stream->_flag & (_IOREAD | _IOWRT)) == _IOWRT && bigbuf(stream)
+ && (nchar = (__int64) (stream->_ptr - stream->_base)) > 0ll)
+ {
+ if ( _write(_fileno(stream), stream->_base, nchar) == nchar) {
+ if (_IORW & stream->_flag)
+ stream->_flag &= ~_IOWRT;
+ } else {
+ stream->_flag |= _IOERR;
+ rc = EOF;
+ }
+ }
+ stream->_ptr = stream->_base;
+ stream->_cnt = 0ll;
+ return rc;
+}
+
+int __cdecl _fseeki64(FILE *str,__int64 offset,int whence)
+{
+ FILE *stream;
+ /* Init stream pointer */
+ stream = str;
+ errno=0;
+ if(!stream || ((whence != SEEK_SET) && (whence != SEEK_CUR) && (whence
!= SEEK_END)))
+ {
+ errno=EINVAL;
+ return -1;
+ }
+ /* Clear EOF flag */
+ stream->_flag &= ~_IOEOF;
+
+ if (whence == SEEK_CUR) {
+ offset += _ftelli64(stream);
+ whence = SEEK_SET;
+ }
+ /* Flush buffer as necessary */
+ _flush(stream);
+
+ /* If file opened for read/write, clear flags since we don't know
+ what the user is going to do next. If the file was opened for
+ read access only, decrease _bufsiz so that the next _filbuf
+ won't cost quite so much */
+
+ if (stream->_flag & _IORW)
+ stream->_flag &= ~(_IOWRT|_IOREAD);
+ else if ( (stream->_flag & _IOREAD) && (stream->_flag & _IOMYBUF) &&
+ !(stream->_flag & _IOSETVBUF) )
+ stream->_bufsiz = _SMALL_BUFSIZ;
+
+ /* Seek to the desired locale and return. */
+
+ return (_lseeki64(_fileno(stream), offset, whence) == -1ll ? -1 : 0);
+}
+
+int __cdecl (*__MINGW_IMP_SYMBOL(_fseeki64))(FILE *, __int64, int) = _fseeki64;
+#endif /* !defined(__arm__) && !defined(__aarch64__) */
+
+__int64 __cdecl _ftelli64(FILE *str)
+{
+ FILE *stream;
+ size_t offset;
+ __int64 filepos;
+ register char *p;
+ char *max;
+ int fd;
+ size_t rdcnt = 0;
+
+ errno=0;
+ stream = str;
+ fd = _fileno(stream);
+ if (stream->_cnt < 0ll) stream->_cnt = 0ll;
+ if ((filepos = _lseeki64(fd, 0ll, SEEK_CUR)) < 0L)
+ return -1ll;
+
+ if (!bigbuf(stream)) /* _IONBF or no buffering designated */
+ return (filepos - (__int64) stream->_cnt);
+
+ offset = (size_t)(stream->_ptr - stream->_base);
+
+ if (stream->_flag & (_IOWRT|_IOREAD))
+ {
+ if (_osfile(fd) & FTEXT)
+ for (p = stream->_base; p < stream->_ptr; p++)
+ if (*p == '\n') /* adjust for '\r' */
+ offset++;
+ }
+ else if (!(stream->_flag & _IORW)) {
+ errno=EINVAL;
+ return -1ll;
+ }
+ if (filepos == 0ll)
+ return ((__int64)offset);
+
+ if (stream->_flag & _IOREAD) /* go to preceding sector */
+ {
+ if (stream->_cnt == 0ll) /* filepos holds correct location */
+ offset = 0ll;
+ else
+ {
+ rdcnt = ((size_t) stream->_cnt) + ((size_t)
(size_t)(stream->_ptr - stream->_base));
+ if (_osfile(fd) & FTEXT) {
+ if (_lseeki64(fd, 0ll, SEEK_END) == filepos) {
+ max = stream->_base + rdcnt;
+ for (p = stream->_base; p < max; p++)
+ if (*p == '\n') /* adjust for '\r' */
+ rdcnt++;
+ if (stream->_flag & _IOCTRLZ)
+ ++rdcnt;
+ } else {
+ _lseeki64(fd, filepos, SEEK_SET);
+ if ( (rdcnt <= _SMALL_BUFSIZ) && (stream->_flag &
_IOMYBUF) &&
+ !(stream->_flag & _IOSETVBUF))
+ rdcnt = _SMALL_BUFSIZ;
+ else
+ rdcnt = stream->_bufsiz;
+ if (_osfile(fd) & FCRLF)
+ ++rdcnt;
+ }
+ } /* end if FTEXT */
+ }
+ filepos -= (__int64)rdcnt;
+ } /* end else stream->_cnt != 0 */
+ return (filepos + (__int64)offset);
+}
+
+__int64 __cdecl (*__MINGW_IMP_SYMBOL(_ftelli64))(FILE *) = _ftelli64;
+
diff --git a/mingw-w64-crt/stdio/fseeko64.c b/mingw-w64-crt/stdio/fseeko64.c
index 5905aa2..99a54f7 100644
--- a/mingw-w64-crt/stdio/fseeko64.c
+++ b/mingw-w64-crt/stdio/fseeko64.c
@@ -76,33 +76,7 @@ static struct oserr_map local_errtab[] = {
{ ERROR_NOT_ENOUGH_QUOTA, ENOMEM }, { 0, -1 }
};
-_CRTIMP __int64 __cdecl _lseeki64(int fh,__int64 pos,int mthd);
-__int64 __cdecl _ftelli64(FILE *str);
void mingw_dosmaperr (unsigned long oserrno);
-int __cdecl _flush (FILE *str);
-
-int __cdecl _flush (FILE *str)
-{
- FILE *stream;
- int rc = 0; /* assume good return */
- __int64 nchar;
-
- stream = str;
- if ((stream->_flag & (_IOREAD | _IOWRT)) == _IOWRT && bigbuf(stream)
- && (nchar = (__int64) (stream->_ptr - stream->_base)) > 0ll)
- {
- if ( _write(_fileno(stream), stream->_base, nchar) == nchar) {
- if (_IORW & stream->_flag)
- stream->_flag &= ~_IOWRT;
- } else {
- stream->_flag |= _IOERR;
- rc = EOF;
- }
- }
- stream->_ptr = stream->_base;
- stream->_cnt = 0ll;
- return rc;
-}
int fseeko64 (FILE* stream, _off64_t offset, int whence)
{
@@ -130,111 +104,6 @@ int fseeko64 (FILE* stream, _off64_t offset, int whence)
return fsetpos (stream, &pos);
}
-int __cdecl _fseeki64(FILE *str,__int64 offset,int whence)
-{
- FILE *stream;
- /* Init stream pointer */
- stream = str;
- errno=0;
- if(!stream || ((whence != SEEK_SET) && (whence != SEEK_CUR) && (whence
!= SEEK_END)))
- {
- errno=EINVAL;
- return -1;
- }
- /* Clear EOF flag */
- stream->_flag &= ~_IOEOF;
-
- if (whence == SEEK_CUR) {
- offset += _ftelli64(stream);
- whence = SEEK_SET;
- }
- /* Flush buffer as necessary */
- _flush(stream);
-
- /* If file opened for read/write, clear flags since we don't know
- what the user is going to do next. If the file was opened for
- read access only, decrease _bufsiz so that the next _filbuf
- won't cost quite so much */
-
- if (stream->_flag & _IORW)
- stream->_flag &= ~(_IOWRT|_IOREAD);
- else if ( (stream->_flag & _IOREAD) && (stream->_flag & _IOMYBUF) &&
- !(stream->_flag & _IOSETVBUF) )
- stream->_bufsiz = _SMALL_BUFSIZ;
-
- /* Seek to the desired locale and return. */
-
- return (_lseeki64(_fileno(stream), offset, whence) == -1ll ? -1 : 0);
-}
-
-__int64 __cdecl _ftelli64(FILE *str)
-{
- FILE *stream;
- size_t offset;
- __int64 filepos;
- register char *p;
- char *max;
- int fd;
- size_t rdcnt = 0;
-
- errno=0;
- stream = str;
- fd = _fileno(stream);
- if (stream->_cnt < 0ll) stream->_cnt = 0ll;
- if ((filepos = _lseeki64(fd, 0ll, SEEK_CUR)) < 0L)
- return -1ll;
-
- if (!bigbuf(stream)) /* _IONBF or no buffering designated */
- return (filepos - (__int64) stream->_cnt);
-
- offset = (size_t)(stream->_ptr - stream->_base);
-
- if (stream->_flag & (_IOWRT|_IOREAD))
- {
- if (_osfile(fd) & FTEXT)
- for (p = stream->_base; p < stream->_ptr; p++)
- if (*p == '\n') /* adjust for '\r' */
- offset++;
- }
- else if (!(stream->_flag & _IORW)) {
- errno=EINVAL;
- return -1ll;
- }
- if (filepos == 0ll)
- return ((__int64)offset);
-
- if (stream->_flag & _IOREAD) /* go to preceding sector */
- {
- if (stream->_cnt == 0ll) /* filepos holds correct location */
- offset = 0ll;
- else
- {
- rdcnt = ((size_t) stream->_cnt) + ((size_t)
(size_t)(stream->_ptr - stream->_base));
- if (_osfile(fd) & FTEXT) {
- if (_lseeki64(fd, 0ll, SEEK_END) == filepos) {
- max = stream->_base + rdcnt;
- for (p = stream->_base; p < max; p++)
- if (*p == '\n') /* adjust for '\r' */
- rdcnt++;
- if (stream->_flag & _IOCTRLZ)
- ++rdcnt;
- } else {
- _lseeki64(fd, filepos, SEEK_SET);
- if ( (rdcnt <= _SMALL_BUFSIZ) && (stream->_flag &
_IOMYBUF) &&
- !(stream->_flag & _IOSETVBUF))
- rdcnt = _SMALL_BUFSIZ;
- else
- rdcnt = stream->_bufsiz;
- if (_osfile(fd) & FCRLF)
- ++rdcnt;
- }
- } /* end if FTEXT */
- }
- filepos -= (__int64)rdcnt;
- } /* end else stream->_cnt != 0 */
- return (filepos + (__int64)offset);
-}
-
void mingw_dosmaperr (unsigned long oserrno)
{
size_t i;
diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h
index c79d705..9c3d188 100644
--- a/mingw-w64-headers/crt/stdio.h
+++ b/mingw-w64-headers/crt/stdio.h
@@ -609,10 +609,9 @@ int vsnprintf (char *__stream, size_t __n, const char
*__format, __builtin_va_li
/* Shouldn't be any fseeko32 in glibc, 32bit to 64bit casting should be fine
*/
/* int fseeko32(FILE* stream, _off_t offset, int whence);*/ /* fseeko32
redirects to fseeko64 */
-#if __MSVCRT_VERSION__ >= 0x1400
- // Mark these as _CRTIMP to avoid trying to link in the mingwex versions.
_CRTIMP int __cdecl _fseeki64(FILE *_File,__int64 _Offset,int _Origin);
_CRTIMP __int64 __cdecl _ftelli64(FILE *_File);
+#if __MSVCRT_VERSION__ >= 0x1400
__mingw_static_ovr int fseeko(FILE *_File, _off_t _Offset, int _Origin) {
return fseek(_File, _Offset, _Origin);
}
@@ -626,8 +625,6 @@ int vsnprintf (char *__stream, size_t __n, const char
*__format, __builtin_va_li
return _ftelli64(_File);
}
#else
- __MINGW_EXTENSION int __cdecl _fseeki64(FILE *_File,__int64 _Offset,int
_Origin);
- __MINGW_EXTENSION __int64 __cdecl _ftelli64(FILE *_File);
int fseeko64(FILE* stream, _off64_t offset, int whence);
int fseeko(FILE* stream, _off_t offset, int whence);
/* Returns truncated 64bit off_t */
--
2.7.4
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public