Functions _(w)findfirst64 and _(w)findnext64 are available since
msvcr70.dll. They are available also in all non-i386 system os msvcrt.dll
versions. They are not available in older i386 msvcrt.dll versions. For
older msvcrt versions and system os i386 msvcrt.dll version provide
mingw-w64 emulation via WinAPI FindFirstFileA()/FindFirstFileW() and
WinAPI FindNextFileA()/FindNextFileW() functions.
---
mingw-w64-crt/Makefile.am | 8 +++++++
mingw-w64-crt/lib-common/msvcrt.def.in | 8 +++----
mingw-w64-crt/stdio/_findX.h | 33 ++++++++++++++++++++++++++
mingw-w64-crt/stdio/_findfirst64.c | 29 ++++++++++++++++++++++
mingw-w64-crt/stdio/_findnext64.c | 29 ++++++++++++++++++++++
mingw-w64-crt/stdio/_wfindfirst64.c | 30 +++++++++++++++++++++++
mingw-w64-crt/stdio/_wfindnext64.c | 29 ++++++++++++++++++++++
7 files changed, 162 insertions(+), 4 deletions(-)
create mode 100644 mingw-w64-crt/stdio/_findX.h
create mode 100644 mingw-w64-crt/stdio/_findfirst64.c
create mode 100644 mingw-w64-crt/stdio/_findnext64.c
create mode 100644 mingw-w64-crt/stdio/_wfindfirst64.c
create mode 100644 mingw-w64-crt/stdio/_wfindnext64.c
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 2497a456f559..de45a2591cdc 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -606,6 +606,8 @@ src_msvcrt32=\
misc/wcstoimax.c \
misc/wcstoumax.c \
secapi/wcstok_s.c \
+ stdio/_findfirst64.c \
+ stdio/_findnext64.c \
stdio/_fseeki64.c \
stdio/_fstat64.c \
stdio/_fstat64i32.c \
@@ -615,6 +617,8 @@ src_msvcrt32=\
stdio/_stat64i32.c \
stdio/_vscprintf.c \
stdio/_vscwprintf.c \
+ stdio/_wfindfirst64.c \
+ stdio/_wfindnext64.c \
stdio/_wstat64.c \
stdio/_wstat64i32.c \
string/msvcr80pre_wcstok.c
@@ -912,12 +916,16 @@ src_pre_msvcr70=\
misc/strtoumax.c \
misc/wcstoimax.c \
misc/wcstoumax.c \
+ stdio/_findfirst64.c \
+ stdio/_findnext64.c \
stdio/_fstat64.c \
stdio/_scprintf.c \
stdio/_scwprintf.c \
stdio/_stat64.c \
stdio/_vscprintf.c \
stdio/_vscwprintf.c \
+ stdio/_wfindfirst64.c \
+ stdio/_wfindnext64.c \
stdio/_wstat64.c
src_pre_msvcr71=\
diff --git a/mingw-w64-crt/lib-common/msvcrt.def.in
b/mingw-w64-crt/lib-common/msvcrt.def.in
index 71054e1c2d22..a4343bb765e0 100644
--- a/mingw-w64-crt/lib-common/msvcrt.def.in
+++ b/mingw-w64-crt/lib-common/msvcrt.def.in
@@ -1151,8 +1151,8 @@ F_I386(_chkesp)
??_V@YAXPAX@Z
#endif
F_NON_I386(_ctime64) ; i386 _ctime64 replaced by emu
-_findfirst64
-_findnext64
+F_NON_I386(_findfirst64) ; i386 _findfirst64 replaced by emu
+F_NON_I386(_findnext64) ; i386 _findnext64 replaced by emu
F_NON_I386(_fstat64) ; i386 _fstat64 replaced by emu
F_NON_I386(_ftime64) ; i386 _ftime64 replaced by emu
F_NON_I386(_futime64) ; i386 _futime64 replaced by emu
@@ -1164,8 +1164,8 @@ F_NON_I386(_stat64) ; i386 _stat64 replaced by emu
F_NON_I386(_time64) ; i386 _time64 replaced by emu
F_NON_I386(_utime64) ; i386 _utime64 replaced by emu
F_NON_I386(_wctime64) ; i386 _wctime64 replaced by emu
-_wfindfirst64
-_wfindnext64
+F_NON_I386(_wfindfirst64) ; i386 _wfindfirst64 replaced by emu
+F_NON_I386(_wfindnext64) ; i386 _wfindnext64 replaced by emu
F_NON_I386(_wstat64) ; i386 _wstat64 replaced by emu
F_NON_I386(_wutime64) ; i386 _wutime64 replaced by emu
diff --git a/mingw-w64-crt/stdio/_findX.h b/mingw-w64-crt/stdio/_findX.h
new file mode 100644
index 000000000000..d95d9f8c383e
--- /dev/null
+++ b/mingw-w64-crt/stdio/_findX.h
@@ -0,0 +1,33 @@
+/**
+ * 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 "filetime_to_time64.h"
+
+#define win32_find_data_to_crt_find_data(success, win32_find_data,
crt_find_data) do { \
+ if (!(success)) { \
+ switch (GetLastError()) { \
+ case ERROR_FILE_NOT_FOUND: \
+ case ERROR_PATH_NOT_FOUND: \
+ case ERROR_NO_MORE_FILES: \
+ errno = ENOENT; \
+ break; \
+ case ERROR_NOT_ENOUGH_MEMORY: \
+ errno = ENOMEM; \
+ break; \
+ default: \
+ errno = EINVAL; \
+ break; \
+ } \
+ } else { \
+ (crt_find_data)->attrib = (win32_find_data)->dwFileAttributes ==
FILE_ATTRIBUTE_NORMAL ? 0 : (win32_find_data)->dwFileAttributes; \
+ (crt_find_data)->time_create =
filetime_to_time64(&(win32_find_data)->ftCreationTime); \
+ (crt_find_data)->time_access =
filetime_to_time64(&(win32_find_data)->ftLastAccessTime); \
+ (crt_find_data)->time_write =
filetime_to_time64(&(win32_find_data)->ftLastWriteTime); \
+ (crt_find_data)->size = ((unsigned long
long)(win32_find_data)->nFileSizeHigh << 32) | (win32_find_data)->nFileSizeLow;
\
+ _Static_assert(sizeof((crt_find_data)->name) ==
sizeof((win32_find_data)->cFileName), "mismatch size of CRT finddata's name and
WIN32_FIND_DATA's cFileName"); \
+ memcpy((crt_find_data)->name, (win32_find_data)->cFileName,
sizeof((crt_find_data)->name)); \
+ } \
+} while (0)
diff --git a/mingw-w64-crt/stdio/_findfirst64.c
b/mingw-w64-crt/stdio/_findfirst64.c
new file mode 100644
index 000000000000..594c394ac35b
--- /dev/null
+++ b/mingw-w64-crt/stdio/_findfirst64.c
@@ -0,0 +1,29 @@
+/**
+ * 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 <io.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <windows.h>
+
+#include "_findX.h"
+
+static intptr_t __cdecl emu__findfirst64(const char *path, struct
__finddata64_t *find_data)
+{
+ WIN32_FIND_DATAA win32_find_data;
+ HANDLE handle;
+
+ handle = FindFirstFileA(path, &win32_find_data);
+ win32_find_data_to_crt_find_data(handle != INVALID_HANDLE_VALUE,
&win32_find_data, find_data);
+ return (intptr_t)handle;
+}
+
+#define RETT intptr_t
+#define FUNC _findfirst64
+#define ARGS const char *path, struct __finddata64_t *find_data
+#define CALL path, find_data
+#include "msvcrt_or_emu_glue.h"
diff --git a/mingw-w64-crt/stdio/_findnext64.c
b/mingw-w64-crt/stdio/_findnext64.c
new file mode 100644
index 000000000000..80f64d5ed09b
--- /dev/null
+++ b/mingw-w64-crt/stdio/_findnext64.c
@@ -0,0 +1,29 @@
+/**
+ * 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 <io.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <windows.h>
+
+#include "_findX.h"
+
+static int __cdecl emu__findnext64(intptr_t find_handle, struct __finddata64_t
*find_data)
+{
+ WIN32_FIND_DATAA win32_find_data;
+ BOOL success;
+
+ success = FindNextFileA((HANDLE)find_handle, &win32_find_data);
+ win32_find_data_to_crt_find_data(success, &win32_find_data, find_data);
+ return success ? 0 : -1;
+}
+
+#define RETT int
+#define FUNC _findnext64
+#define ARGS intptr_t find_handle, struct __finddata64_t *find_data
+#define CALL find_handle, find_data
+#include "msvcrt_or_emu_glue.h"
diff --git a/mingw-w64-crt/stdio/_wfindfirst64.c
b/mingw-w64-crt/stdio/_wfindfirst64.c
new file mode 100644
index 000000000000..e8b1c8d6d064
--- /dev/null
+++ b/mingw-w64-crt/stdio/_wfindfirst64.c
@@ -0,0 +1,30 @@
+/**
+ * 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 <io.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <wchar.h>
+#include <windows.h>
+
+#include "_findX.h"
+
+static intptr_t __cdecl emu__wfindfirst64(const wchar_t *path, struct
_wfinddata64_t *find_data)
+{
+ WIN32_FIND_DATAW win32_find_data;
+ HANDLE handle;
+
+ handle = FindFirstFileW(path, &win32_find_data);
+ win32_find_data_to_crt_find_data(handle != INVALID_HANDLE_VALUE,
&win32_find_data, find_data);
+ return (intptr_t)handle;
+}
+
+#define RETT intptr_t
+#define FUNC _wfindfirst64
+#define ARGS const wchar_t *path, struct _wfinddata64_t *find_data
+#define CALL path, find_data
+#include "msvcrt_or_emu_glue.h"
diff --git a/mingw-w64-crt/stdio/_wfindnext64.c
b/mingw-w64-crt/stdio/_wfindnext64.c
new file mode 100644
index 000000000000..17800ffd87f5
--- /dev/null
+++ b/mingw-w64-crt/stdio/_wfindnext64.c
@@ -0,0 +1,29 @@
+/**
+ * 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 <io.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <windows.h>
+
+#include "_findX.h"
+
+static int __cdecl emu__wfindnext64(intptr_t find_handle, struct
_wfinddata64_t *find_data)
+{
+ WIN32_FIND_DATAW win32_find_data;
+ BOOL success;
+
+ success = FindNextFileW((HANDLE)find_handle, &win32_find_data);
+ win32_find_data_to_crt_find_data(success, &win32_find_data, find_data);
+ return success ? 0 : -1;
+}
+
+#define RETT int
+#define FUNC _wfindnext64
+#define ARGS intptr_t find_handle, struct _wfinddata64_t *find_data
+#define CALL find_handle, find_data
+#include "msvcrt_or_emu_glue.h"
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public