Functions _(w)findfirst64 and _(w)findnext64 are available since
msvcr70.dll. For older msvcrt versions 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..4705240d934c
--- /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_fi_to_crt_find_data(success, fi, 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 { \
+ (find_data)->attrib = (fi)->dwFileAttributes == FILE_ATTRIBUTE_NORMAL
? 0 : (fi)->dwFileAttributes; \
+ (find_data)->time_create = filetime_to_time64(&(fi)->ftCreationTime); \
+ (find_data)->time_access =
filetime_to_time64(&(fi)->ftLastAccessTime); \
+ (find_data)->time_write = filetime_to_time64(&(fi)->ftLastWriteTime); \
+ (find_data)->size = ((unsigned long long)(fi)->nFileSizeHigh << 32) |
(fi)->nFileSizeLow; \
+ _Static_assert(sizeof((find_data)->name) == sizeof((fi)->cFileName),
"mismatch size of CRT finddata's name and WIN32_FIND_DATA's cFileName"); \
+ memcpy((find_data)->name, (fi)->cFileName, sizeof((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..e47ab85caf08
--- /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 fi;
+ HANDLE handle;
+
+ handle = FindFirstFileA(path, &fi);
+ win32_fi_to_crt_find_data(handle != INVALID_HANDLE_VALUE, &fi, 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..caf5176272d2
--- /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 fi;
+ BOOL success;
+
+ success = FindNextFileA((HANDLE)find_handle, &fi);
+ win32_fi_to_crt_find_data(success, &fi, 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..c8367750a62b
--- /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 fi;
+ HANDLE handle;
+
+ handle = FindFirstFileW(path, &fi);
+ win32_fi_to_crt_find_data(handle != INVALID_HANDLE_VALUE, &fi, 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..b252993d48e5
--- /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 fi;
+ BOOL success;
+
+ success = FindNextFileW((HANDLE)find_handle, &fi);
+ win32_fi_to_crt_find_data(success, &fi, 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