uringmachine 0.16 → 0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.gitmodules +4 -0
  4. data/CHANGELOG.md +8 -0
  5. data/TODO.md +12 -3
  6. data/examples/bm_send.rb +86 -0
  7. data/ext/um/um.c +28 -1
  8. data/ext/um/um.h +3 -0
  9. data/ext/um/um_class.c +17 -0
  10. data/ext/um/um_utils.c +38 -15
  11. data/lib/uringmachine/version.rb +1 -1
  12. data/test/test_um.rb +76 -0
  13. data/vendor/libressl/.github/scripts/changelog.sh +74 -0
  14. data/vendor/libressl/.github/workflows/android.yml +35 -0
  15. data/vendor/libressl/.github/workflows/cifuzz.yml +33 -0
  16. data/vendor/libressl/.github/workflows/cmake-config.yml +98 -0
  17. data/vendor/libressl/.github/workflows/coverity.yml +69 -0
  18. data/vendor/libressl/.github/workflows/emscripten.yml +71 -0
  19. data/vendor/libressl/.github/workflows/fedora-rawhide.yml +39 -0
  20. data/vendor/libressl/.github/workflows/freebsd.yml +71 -0
  21. data/vendor/libressl/.github/workflows/linux.yml +71 -0
  22. data/vendor/libressl/.github/workflows/macos.yml +37 -0
  23. data/vendor/libressl/.github/workflows/release.yml +81 -0
  24. data/vendor/libressl/.github/workflows/rust-openssl.yml +47 -0
  25. data/vendor/libressl/.github/workflows/solaris.yml +37 -0
  26. data/vendor/libressl/.github/workflows/windows.yml +70 -0
  27. data/vendor/libressl/.gitignore +333 -0
  28. data/vendor/libressl/CMakeLists.txt +581 -0
  29. data/vendor/libressl/COPYING +133 -0
  30. data/vendor/libressl/ChangeLog +3280 -0
  31. data/vendor/libressl/FindLibreSSL.cmake +232 -0
  32. data/vendor/libressl/LibreSSLConfig.cmake.in +36 -0
  33. data/vendor/libressl/Makefile.am +60 -0
  34. data/vendor/libressl/Makefile.am.common +20 -0
  35. data/vendor/libressl/OPENBSD_BRANCH +1 -0
  36. data/vendor/libressl/README.md +238 -0
  37. data/vendor/libressl/README.mingw.md +43 -0
  38. data/vendor/libressl/apps/CMakeLists.txt +18 -0
  39. data/vendor/libressl/apps/Makefile.am +5 -0
  40. data/vendor/libressl/apps/nc/CMakeLists.txt +67 -0
  41. data/vendor/libressl/apps/nc/Makefile.am +64 -0
  42. data/vendor/libressl/apps/nc/compat/accept4.c +17 -0
  43. data/vendor/libressl/apps/nc/compat/readpassphrase.c +205 -0
  44. data/vendor/libressl/apps/nc/compat/socket.c +29 -0
  45. data/vendor/libressl/apps/nc/compat/sys/socket.h +30 -0
  46. data/vendor/libressl/apps/ocspcheck/CMakeLists.txt +44 -0
  47. data/vendor/libressl/apps/ocspcheck/Makefile.am +45 -0
  48. data/vendor/libressl/apps/ocspcheck/compat/.gitignore +0 -0
  49. data/vendor/libressl/apps/openssl/CMakeLists.txt +97 -0
  50. data/vendor/libressl/apps/openssl/Makefile.am +108 -0
  51. data/vendor/libressl/apps/openssl/apps_win.c +138 -0
  52. data/vendor/libressl/apps/openssl/certhash_win.c +13 -0
  53. data/vendor/libressl/apps/openssl/compat/clock_gettime_osx.c +26 -0
  54. data/vendor/libressl/apps/openssl/compat/poll_win.c +329 -0
  55. data/vendor/libressl/appveyor.yml +53 -0
  56. data/vendor/libressl/autogen.sh +15 -0
  57. data/vendor/libressl/check-release.sh +86 -0
  58. data/vendor/libressl/cmake_export_symbol.cmake +71 -0
  59. data/vendor/libressl/cmake_uninstall.cmake.in +36 -0
  60. data/vendor/libressl/config +17 -0
  61. data/vendor/libressl/configure.ac +165 -0
  62. data/vendor/libressl/crypto/CMakeLists.txt +863 -0
  63. data/vendor/libressl/crypto/Makefile.am +962 -0
  64. data/vendor/libressl/crypto/Makefile.am.arc4random +46 -0
  65. data/vendor/libressl/crypto/Makefile.am.elf-mips +14 -0
  66. data/vendor/libressl/crypto/Makefile.am.elf-mips64 +14 -0
  67. data/vendor/libressl/crypto/Makefile.am.elf-x86_64 +35 -0
  68. data/vendor/libressl/crypto/Makefile.am.macosx-x86_64 +35 -0
  69. data/vendor/libressl/crypto/Makefile.am.masm-x86_64 +22 -0
  70. data/vendor/libressl/crypto/Makefile.am.mingw64-x86_64 +23 -0
  71. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_darwin.c +60 -0
  72. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_linux.c +62 -0
  73. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_none.c +26 -0
  74. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_windows.c +36 -0
  75. data/vendor/libressl/crypto/arch/loongarch64/crypto_arch.h +21 -0
  76. data/vendor/libressl/crypto/arch/mips/crypto_arch.h +21 -0
  77. data/vendor/libressl/crypto/bn/arch/loongarch64/bn_arch.h +23 -0
  78. data/vendor/libressl/crypto/bn/arch/mips/bn_arch.h +24 -0
  79. data/vendor/libressl/crypto/compat/.gitignore +31 -0
  80. data/vendor/libressl/crypto/compat/arc4random.h +41 -0
  81. data/vendor/libressl/crypto/compat/b_win.c +55 -0
  82. data/vendor/libressl/crypto/compat/bsd-asprintf.c +96 -0
  83. data/vendor/libressl/crypto/compat/crypto_lock_win.c +56 -0
  84. data/vendor/libressl/crypto/compat/explicit_bzero_win.c +13 -0
  85. data/vendor/libressl/crypto/compat/freezero.c +32 -0
  86. data/vendor/libressl/crypto/compat/getdelim.c +78 -0
  87. data/vendor/libressl/crypto/compat/getline.c +40 -0
  88. data/vendor/libressl/crypto/compat/getopt_long.c +528 -0
  89. data/vendor/libressl/crypto/compat/getpagesize.c +18 -0
  90. data/vendor/libressl/crypto/compat/getprogname_linux.c +23 -0
  91. data/vendor/libressl/crypto/compat/getprogname_unimpl.c +7 -0
  92. data/vendor/libressl/crypto/compat/getprogname_windows.c +13 -0
  93. data/vendor/libressl/crypto/compat/posix_win.c +296 -0
  94. data/vendor/libressl/crypto/compat/syslog_r.c +19 -0
  95. data/vendor/libressl/crypto/compat/ui_openssl_win.c +334 -0
  96. data/vendor/libressl/dist.sh +22 -0
  97. data/vendor/libressl/gen-coverage-report.sh +58 -0
  98. data/vendor/libressl/gen-openbsd-tags.sh +20 -0
  99. data/vendor/libressl/include/CMakeLists.txt +61 -0
  100. data/vendor/libressl/include/Makefile.am +79 -0
  101. data/vendor/libressl/include/arch/loongarch64/opensslconf.h +150 -0
  102. data/vendor/libressl/include/arch/mips/opensslconf.h +150 -0
  103. data/vendor/libressl/include/compat/arpa/inet.h +15 -0
  104. data/vendor/libressl/include/compat/arpa/nameser.h +25 -0
  105. data/vendor/libressl/include/compat/cet.h +19 -0
  106. data/vendor/libressl/include/compat/dirent.h +17 -0
  107. data/vendor/libressl/include/compat/dirent_msvc.h +611 -0
  108. data/vendor/libressl/include/compat/endian.h +161 -0
  109. data/vendor/libressl/include/compat/err.h +95 -0
  110. data/vendor/libressl/include/compat/fcntl.h +32 -0
  111. data/vendor/libressl/include/compat/getopt.h +50 -0
  112. data/vendor/libressl/include/compat/limits.h +25 -0
  113. data/vendor/libressl/include/compat/netdb.h +10 -0
  114. data/vendor/libressl/include/compat/netinet/in.h +19 -0
  115. data/vendor/libressl/include/compat/netinet/ip.h +49 -0
  116. data/vendor/libressl/include/compat/netinet/tcp.h +10 -0
  117. data/vendor/libressl/include/compat/poll.h +63 -0
  118. data/vendor/libressl/include/compat/pthread.h +122 -0
  119. data/vendor/libressl/include/compat/readpassphrase.h +44 -0
  120. data/vendor/libressl/include/compat/resolv.h +24 -0
  121. data/vendor/libressl/include/compat/stdint.h +31 -0
  122. data/vendor/libressl/include/compat/stdio.h +65 -0
  123. data/vendor/libressl/include/compat/stdlib.h +57 -0
  124. data/vendor/libressl/include/compat/string.h +98 -0
  125. data/vendor/libressl/include/compat/sys/_null.h +18 -0
  126. data/vendor/libressl/include/compat/sys/ioctl.h +11 -0
  127. data/vendor/libressl/include/compat/sys/mman.h +19 -0
  128. data/vendor/libressl/include/compat/sys/param.h +15 -0
  129. data/vendor/libressl/include/compat/sys/queue.h +536 -0
  130. data/vendor/libressl/include/compat/sys/select.h +10 -0
  131. data/vendor/libressl/include/compat/sys/socket.h +18 -0
  132. data/vendor/libressl/include/compat/sys/stat.h +129 -0
  133. data/vendor/libressl/include/compat/sys/time.h +37 -0
  134. data/vendor/libressl/include/compat/sys/tree.h +1006 -0
  135. data/vendor/libressl/include/compat/sys/types.h +69 -0
  136. data/vendor/libressl/include/compat/sys/uio.h +17 -0
  137. data/vendor/libressl/include/compat/syslog.h +38 -0
  138. data/vendor/libressl/include/compat/time.h +59 -0
  139. data/vendor/libressl/include/compat/unistd.h +83 -0
  140. data/vendor/libressl/include/compat/win32netcompat.h +57 -0
  141. data/vendor/libressl/include/openssl/Makefile.am.tpl +45 -0
  142. data/vendor/libressl/libcrypto.pc.in +28 -0
  143. data/vendor/libressl/libressl.pub +2 -0
  144. data/vendor/libressl/libssl.pc.in +28 -0
  145. data/vendor/libressl/libtls.pc.in +28 -0
  146. data/vendor/libressl/m4/ax_add_fortify_source.m4 +80 -0
  147. data/vendor/libressl/m4/ax_check_compile_flag.m4 +53 -0
  148. data/vendor/libressl/m4/check-hardening-options.m4 +110 -0
  149. data/vendor/libressl/m4/check-libc.m4 +189 -0
  150. data/vendor/libressl/m4/check-os-options.m4 +181 -0
  151. data/vendor/libressl/m4/disable-compiler-warnings.m4 +44 -0
  152. data/vendor/libressl/man/CMakeLists.txt +26 -0
  153. data/vendor/libressl/man/links +2780 -0
  154. data/vendor/libressl/man/update_links.sh +25 -0
  155. data/vendor/libressl/openssl.pc.in +11 -0
  156. data/vendor/libressl/patches/bn_shift.patch +34 -0
  157. data/vendor/libressl/patches/crypto_arch.h.patch +34 -0
  158. data/vendor/libressl/patches/crypto_namespace.h.patch +22 -0
  159. data/vendor/libressl/patches/netcat.c.patch +178 -0
  160. data/vendor/libressl/patches/openssl.c.patch +12 -0
  161. data/vendor/libressl/patches/opensslfeatures.h.patch +49 -0
  162. data/vendor/libressl/patches/patch-amd64-crypto-cpu-caps.c.patch +20 -0
  163. data/vendor/libressl/patches/patch-i386-crypto-cpu-caps.c.patch +20 -0
  164. data/vendor/libressl/patches/speed.c.patch +114 -0
  165. data/vendor/libressl/patches/ssl_namespace.h.patch +21 -0
  166. data/vendor/libressl/patches/tls.h.patch +16 -0
  167. data/vendor/libressl/patches/tls_config.c.patch +15 -0
  168. data/vendor/libressl/patches/win32_amd64_bn_arch.h.patch +28 -0
  169. data/vendor/libressl/patches/windows_headers.patch +80 -0
  170. data/vendor/libressl/scripts/config.guess +1774 -0
  171. data/vendor/libressl/scripts/config.sub +1907 -0
  172. data/vendor/libressl/scripts/i686-w64-mingw32.cmake +9 -0
  173. data/vendor/libressl/scripts/test +210 -0
  174. data/vendor/libressl/scripts/wrap-compiler-for-flag-check +31 -0
  175. data/vendor/libressl/scripts/x86_64-w64-mingw32.cmake +9 -0
  176. data/vendor/libressl/ssl/CMakeLists.txt +183 -0
  177. data/vendor/libressl/ssl/Makefile.am +187 -0
  178. data/vendor/libressl/tests/CMakeLists.txt +970 -0
  179. data/vendor/libressl/tests/Makefile.am +944 -0
  180. data/vendor/libressl/tests/aeadtest.sh +30 -0
  181. data/vendor/libressl/tests/arc4randomforktest.sh +21 -0
  182. data/vendor/libressl/tests/asn1time_small.test +10 -0
  183. data/vendor/libressl/tests/cmake/CMakeLists.txt +52 -0
  184. data/vendor/libressl/tests/cmake/crypto.c +7 -0
  185. data/vendor/libressl/tests/cmake/ssl.c +6 -0
  186. data/vendor/libressl/tests/cmake/tls.c +6 -0
  187. data/vendor/libressl/tests/compat/pipe2.c +186 -0
  188. data/vendor/libressl/tests/dtlstest.sh +28 -0
  189. data/vendor/libressl/tests/evptest.sh +22 -0
  190. data/vendor/libressl/tests/keypairtest.sh +27 -0
  191. data/vendor/libressl/tests/mlkem_tests.sh +39 -0
  192. data/vendor/libressl/tests/ocsptest.bat +25 -0
  193. data/vendor/libressl/tests/ocsptest.sh +23 -0
  194. data/vendor/libressl/tests/openssl.cnf +29 -0
  195. data/vendor/libressl/tests/optionstest.c +381 -0
  196. data/vendor/libressl/tests/pidwraptest.c +85 -0
  197. data/vendor/libressl/tests/pidwraptest.sh +26 -0
  198. data/vendor/libressl/tests/quictest.bat +27 -0
  199. data/vendor/libressl/tests/quictest.sh +30 -0
  200. data/vendor/libressl/tests/renegotiation_test.bat +27 -0
  201. data/vendor/libressl/tests/renegotiation_test.sh +30 -0
  202. data/vendor/libressl/tests/rfc5280time_small.test +10 -0
  203. data/vendor/libressl/tests/servertest.bat +27 -0
  204. data/vendor/libressl/tests/servertest.sh +30 -0
  205. data/vendor/libressl/tests/shutdowntest.bat +27 -0
  206. data/vendor/libressl/tests/shutdowntest.sh +30 -0
  207. data/vendor/libressl/tests/ssltest.bat +32 -0
  208. data/vendor/libressl/tests/ssltest.sh +48 -0
  209. data/vendor/libressl/tests/testdsa.bat +47 -0
  210. data/vendor/libressl/tests/testdsa.sh +57 -0
  211. data/vendor/libressl/tests/testenc.bat +85 -0
  212. data/vendor/libressl/tests/testenc.sh +93 -0
  213. data/vendor/libressl/tests/testrsa.bat +47 -0
  214. data/vendor/libressl/tests/testrsa.sh +57 -0
  215. data/vendor/libressl/tests/testssl.bat +171 -0
  216. data/vendor/libressl/tests/tlstest.bat +27 -0
  217. data/vendor/libressl/tests/tlstest.sh +28 -0
  218. data/vendor/libressl/tls/CMakeLists.txt +125 -0
  219. data/vendor/libressl/tls/Makefile.am +76 -0
  220. data/vendor/libressl/tls/compat/ftruncate.c +17 -0
  221. data/vendor/libressl/tls/compat/pread.c +29 -0
  222. data/vendor/libressl/tls/compat/pwrite.c +29 -0
  223. data/vendor/libressl/update.sh +460 -0
  224. data/vendor/liburing/.github/workflows/ci.yml +8 -0
  225. data/vendor/liburing/configure +23 -2
  226. data/vendor/liburing/examples/helpers.c +1 -1
  227. data/vendor/liburing/examples/helpers.h +1 -1
  228. data/vendor/liburing/examples/reg-wait.c +3 -3
  229. data/vendor/liburing/examples/zcrx.c +5 -5
  230. data/vendor/liburing/liburing.spec +1 -1
  231. data/vendor/liburing/src/include/liburing/io_uring.h +16 -0
  232. data/vendor/liburing/src/include/liburing.h +20 -4
  233. data/vendor/liburing/src/lib.h +2 -4
  234. data/vendor/liburing/src/liburing-ffi.map +7 -0
  235. data/vendor/liburing/src/liburing.map +7 -0
  236. data/vendor/liburing/src/register.c +5 -0
  237. data/vendor/liburing/src/sanitize.c +5 -4
  238. data/vendor/liburing/src/setup.c +43 -28
  239. data/vendor/liburing/test/Makefile +7 -0
  240. data/vendor/liburing/test/cmd-discard.c +2 -2
  241. data/vendor/liburing/test/evfd-short-read.c +84 -0
  242. data/vendor/liburing/test/fdinfo-sqpoll.c +117 -0
  243. data/vendor/liburing/test/fdinfo.c +1 -1
  244. data/vendor/liburing/test/fixed-buf-merge.c +2 -2
  245. data/vendor/liburing/test/futex-kill.c +135 -0
  246. data/vendor/liburing/test/helpers.c +1 -1
  247. data/vendor/liburing/test/helpers.h +1 -1
  248. data/vendor/liburing/test/init-mem.c +50 -12
  249. data/vendor/liburing/test/io_uring_passthrough.c +25 -6
  250. data/vendor/liburing/test/msg-ring.c +123 -9
  251. data/vendor/liburing/test/recv-bundle-short-ooo.c +16 -1
  252. data/vendor/liburing/test/recv-inc-ooo.c +411 -0
  253. data/vendor/liburing/test/recv-mshot-fair.c +513 -0
  254. data/vendor/liburing/test/reg-wait.c +14 -14
  255. data/vendor/liburing/test/send-zerocopy.c +4 -4
  256. data/vendor/liburing/test/timerfd-short-read.c +81 -0
  257. data/vendor/liburing/test/timestamp.c +382 -0
  258. data/vendor/liburing/test/zcrx.c +22 -22
  259. metadata +222 -2
@@ -0,0 +1,611 @@
1
+ /*
2
+ * dirent.h - dirent API for Microsoft Visual Studio
3
+ *
4
+ * Copyright (C) 2006-2012 Toni Ronkko
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * ``Software''), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included
15
+ * in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
21
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ * OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * $Id: dirent.h,v 1.20 2014/03/19 17:52:23 tronkko Exp $
26
+ */
27
+ #ifndef DIRENT_MSVC_H
28
+ #define DIRENT_MSVC_H
29
+
30
+ #include <windows.h>
31
+
32
+ #if _MSC_VER >= 1900
33
+ #include <../ucrt/stdio.h>
34
+ #include <../ucrt/wchar.h>
35
+ #include <../ucrt/string.h>
36
+ #include <../ucrt/stdlib.h>
37
+ #include <../ucrt/sys/types.h>
38
+ #include <../ucrt/errno.h>
39
+ #else
40
+ #include <../include/stdio.h>
41
+ #include <../include/wchar.h>
42
+ #include <../include/string.h>
43
+ #include <../include/stdlib.h>
44
+ #include <../include/sys/types.h>
45
+ #include <../include/errno.h>
46
+ #endif
47
+
48
+ #include <stdarg.h>
49
+ #include <sys/stat.h>
50
+
51
+ /* Indicates that d_type field is available in dirent structure */
52
+ #define _DIRENT_HAVE_D_TYPE
53
+
54
+ /* Indicates that d_namlen field is available in dirent structure */
55
+ #define _DIRENT_HAVE_D_NAMLEN
56
+
57
+ /* Maximum length of file name */
58
+ #if !defined(PATH_MAX)
59
+ # define PATH_MAX MAX_PATH
60
+ #endif
61
+ #if !defined(FILENAME_MAX)
62
+ # define FILENAME_MAX MAX_PATH
63
+ #endif
64
+ #if !defined(NAME_MAX)
65
+ # define NAME_MAX FILENAME_MAX
66
+ #endif
67
+
68
+ /* Return the exact length of d_namlen without zero terminator */
69
+ #define _D_EXACT_NAMLEN(p)((p)->d_namlen)
70
+
71
+ /* Return number of bytes needed to store d_namlen */
72
+ #define _D_ALLOC_NAMLEN(p)(PATH_MAX)
73
+
74
+ /* Wide-character version */
75
+ struct _wdirent {
76
+ long d_ino; /* Always zero */
77
+ unsigned short d_reclen; /* Structure size */
78
+ size_t d_namlen; /* Length of name without \0 */
79
+ int d_type; /* File type */
80
+ wchar_t d_name[PATH_MAX]; /* File name */
81
+ };
82
+ typedef struct _wdirent _wdirent;
83
+
84
+ struct _WDIR {
85
+ struct _wdirent ent; /* Current directory entry */
86
+ WIN32_FIND_DATAW data; /* Private file data */
87
+ int cached; /* True if data is valid */
88
+ HANDLE handle; /* Win32 search handle */
89
+ wchar_t *patt; /* Initial directory name */
90
+ };
91
+ typedef struct _WDIR _WDIR;
92
+
93
+ static _WDIR *_wopendir(const wchar_t *dirname);
94
+ static struct _wdirent *_wreaddir(_WDIR *dirp);
95
+ static int _wclosedir(_WDIR *dirp);
96
+ static void _wrewinddir(_WDIR* dirp);
97
+
98
+ /* Multi-byte character versions */
99
+ struct dirent {
100
+ long d_ino; /* Always zero */
101
+ unsigned short d_reclen; /* Structure size */
102
+ size_t d_namlen; /* Length of name without \0 */
103
+ int d_type; /* File type */
104
+ char d_name[PATH_MAX]; /* File name */
105
+ };
106
+ typedef struct dirent dirent;
107
+
108
+ struct DIR {
109
+ struct dirent ent;
110
+ struct _WDIR *wdirp;
111
+ };
112
+ typedef struct DIR DIR;
113
+
114
+ static DIR *opendir(const char *dirname);
115
+ static struct dirent *readdir(DIR *dirp);
116
+ static int closedir(DIR *dirp);
117
+ static void rewinddir(DIR* dirp);
118
+
119
+ /* Internal utility functions */
120
+ static WIN32_FIND_DATAW *dirent_first(_WDIR *dirp);
121
+ static WIN32_FIND_DATAW *dirent_next(_WDIR *dirp);
122
+
123
+ static int dirent_mbstowcs_s(
124
+ size_t *pReturnValue,
125
+ wchar_t *wcstr,
126
+ size_t sizeInWords,
127
+ const char *mbstr,
128
+ size_t count);
129
+
130
+ static int dirent_wcstombs_s(
131
+ size_t *pReturnValue,
132
+ char *mbstr,
133
+ size_t sizeInBytes,
134
+ const wchar_t *wcstr,
135
+ size_t count);
136
+
137
+ /*
138
+ * Open directory stream DIRNAME for read and return a pointer to the
139
+ * internal working area that is used to retrieve individual directory
140
+ * entries.
141
+ */
142
+ static _WDIR*
143
+ _wopendir(const wchar_t *dirname)
144
+ {
145
+ _WDIR *dirp = NULL;
146
+ int error;
147
+
148
+ /* Must have directory name */
149
+ if (dirname == NULL || dirname[0] == '\0') {
150
+ _set_errno(ENOENT);
151
+ return NULL;
152
+ }
153
+
154
+ /* Allocate new _WDIR structure */
155
+ dirp =(_WDIR*) malloc(sizeof(struct _WDIR));
156
+ if (dirp != NULL) {
157
+ DWORD n;
158
+
159
+ /* Reset _WDIR structure */
160
+ dirp->handle = INVALID_HANDLE_VALUE;
161
+ dirp->patt = NULL;
162
+ dirp->cached = 0;
163
+
164
+ /* Compute the length of full path plus zero terminator */
165
+ n = GetFullPathNameW(dirname, 0, NULL, NULL);
166
+
167
+ /* Allocate room for absolute directory name and search pattern */
168
+ dirp->patt =(wchar_t*) malloc(sizeof(wchar_t) * n + 16);
169
+ if (dirp->patt) {
170
+
171
+ /*
172
+ * Convert relative directory name to an absolute one. This
173
+ * allows rewinddir() to function correctly even when current
174
+ * working directory is changed between opendir() and rewinddir().
175
+ */
176
+ n = GetFullPathNameW(dirname, n, dirp->patt, NULL);
177
+ if (n > 0) {
178
+ wchar_t *p;
179
+
180
+ /* Append search pattern \* to the directory name */
181
+ p = dirp->patt + n;
182
+ if (dirp->patt < p) {
183
+ switch(p[-1]) {
184
+ case '\\':
185
+ case '/':
186
+ case ':':
187
+ /* Directory ends in path separator, e.g. c:\temp\ */
188
+ /*NOP*/;
189
+ break;
190
+
191
+ default:
192
+ /* Directory name doesn't end in path separator */
193
+ *p++ = '\\';
194
+ }
195
+ }
196
+ *p++ = '*';
197
+ *p = '\0';
198
+
199
+ /* Open directory stream and retrieve the first entry */
200
+ if (dirent_first(dirp)) {
201
+ /* Directory stream opened successfully */
202
+ error = 0;
203
+ } else {
204
+ /* Cannot retrieve first entry */
205
+ error = 1;
206
+ _set_errno(ENOENT);
207
+ }
208
+
209
+ } else {
210
+ /* Cannot retrieve full path name */
211
+ _set_errno(ENOENT);
212
+ error = 1;
213
+ }
214
+
215
+ } else {
216
+ /* Cannot allocate memory for search pattern */
217
+ error = 1;
218
+ }
219
+
220
+ } else {
221
+ /* Cannot allocate _WDIR structure */
222
+ error = 1;
223
+ }
224
+
225
+ /* Clean up in case of error */
226
+ if (error && dirp) {
227
+ _wclosedir(dirp);
228
+ dirp = NULL;
229
+ }
230
+
231
+ return dirp;
232
+ }
233
+
234
+ /*
235
+ * Read next directory entry. The directory entry is returned in dirent
236
+ * structure in the d_name field. Individual directory entries returned by
237
+ * this function include regular files, sub-directories, pseudo-directories
238
+ * "." and ".." as well as volume labels, hidden files and system files.
239
+ */
240
+ static struct _wdirent*
241
+ _wreaddir(_WDIR *dirp)
242
+ {
243
+ WIN32_FIND_DATAW *datap;
244
+ struct _wdirent *entp;
245
+
246
+ /* Read next directory entry */
247
+ datap = dirent_next(dirp);
248
+ if (datap) {
249
+ size_t n;
250
+ DWORD attr;
251
+
252
+ /* Pointer to directory entry to return */
253
+ entp = &dirp->ent;
254
+
255
+ /*
256
+ * Copy file name as wide-character string. If the file name is too
257
+ * long to fit in to the destination buffer, then truncate file name
258
+ * to PATH_MAX characters and zero-terminate the buffer.
259
+ */
260
+ n = 0;
261
+ while(n + 1 < PATH_MAX && datap->cFileName[n] != 0) {
262
+ entp->d_name[n] = datap->cFileName[n];
263
+ n++;
264
+ }
265
+ dirp->ent.d_name[n] = 0;
266
+
267
+ /* Length of file name excluding zero terminator */
268
+ entp->d_namlen = n;
269
+
270
+ /* File type */
271
+ attr = datap->dwFileAttributes;
272
+ if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
273
+ entp->d_type = DT_CHR;
274
+ } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
275
+ entp->d_type = DT_DIR;
276
+ } else {
277
+ entp->d_type = DT_REG;
278
+ }
279
+
280
+ /* Reset dummy fields */
281
+ entp->d_ino = 0;
282
+ entp->d_reclen = sizeof(struct _wdirent);
283
+
284
+ } else {
285
+
286
+ /* Last directory entry read */
287
+ entp = NULL;
288
+
289
+ }
290
+
291
+ return entp;
292
+ }
293
+
294
+ /*
295
+ * Close directory stream opened by opendir() function. This invalidates the
296
+ * DIR structure as well as any directory entry read previously by
297
+ * _wreaddir().
298
+ */
299
+ static int
300
+ _wclosedir(_WDIR *dirp)
301
+ {
302
+ int ok;
303
+ if (dirp) {
304
+
305
+ /* Release search handle */
306
+ if (dirp->handle != INVALID_HANDLE_VALUE) {
307
+ FindClose(dirp->handle);
308
+ dirp->handle = INVALID_HANDLE_VALUE;
309
+ }
310
+
311
+ /* Release search pattern */
312
+ if (dirp->patt) {
313
+ free(dirp->patt);
314
+ dirp->patt = NULL;
315
+ }
316
+
317
+ /* Release directory structure */
318
+ free(dirp);
319
+ ok = /*success*/0;
320
+
321
+ } else {
322
+ /* Invalid directory stream */
323
+ _set_errno(EBADF);
324
+ ok = /*failure*/-1;
325
+ }
326
+ return ok;
327
+ }
328
+
329
+ /*
330
+ * Rewind directory stream such that _wreaddir() returns the very first
331
+ * file name again.
332
+ */
333
+ static void
334
+ _wrewinddir(_WDIR* dirp)
335
+ {
336
+ if (dirp) {
337
+ /* Release existing search handle */
338
+ if (dirp->handle != INVALID_HANDLE_VALUE) {
339
+ FindClose(dirp->handle);
340
+ }
341
+
342
+ /* Open new search handle */
343
+ dirent_first(dirp);
344
+ }
345
+ }
346
+
347
+ /* Get first directory entry(internal) */
348
+ static WIN32_FIND_DATAW*
349
+ dirent_first(_WDIR *dirp)
350
+ {
351
+ WIN32_FIND_DATAW *datap;
352
+
353
+ /* Open directory and retrieve the first entry */
354
+ dirp->handle = FindFirstFileW(dirp->patt, &dirp->data);
355
+ if (dirp->handle != INVALID_HANDLE_VALUE) {
356
+
357
+ /* a directory entry is now waiting in memory */
358
+ datap = &dirp->data;
359
+ dirp->cached = 1;
360
+
361
+ } else {
362
+
363
+ /* Failed to re-open directory: no directory entry in memory */
364
+ dirp->cached = 0;
365
+ datap = NULL;
366
+
367
+ }
368
+ return datap;
369
+ }
370
+
371
+ /* Get next directory entry(internal) */
372
+ static WIN32_FIND_DATAW*
373
+ dirent_next(_WDIR *dirp)
374
+ {
375
+ WIN32_FIND_DATAW *p;
376
+
377
+ /* Get next directory entry */
378
+ if (dirp->cached != 0) {
379
+
380
+ /* A valid directory entry already in memory */
381
+ p = &dirp->data;
382
+ dirp->cached = 0;
383
+
384
+ } else if (dirp->handle != INVALID_HANDLE_VALUE) {
385
+
386
+ /* Get the next directory entry from stream */
387
+ if (FindNextFileW(dirp->handle, &dirp->data) != FALSE) {
388
+ /* Got a file */
389
+ p = &dirp->data;
390
+ } else {
391
+ /* The very last entry has been processed or an error occured */
392
+ FindClose(dirp->handle);
393
+ dirp->handle = INVALID_HANDLE_VALUE;
394
+ p = NULL;
395
+ }
396
+
397
+ } else {
398
+
399
+ /* End of directory stream reached */
400
+ p = NULL;
401
+
402
+ }
403
+
404
+ return p;
405
+ }
406
+
407
+ /*
408
+ * Open directory stream using plain old C-string.
409
+ */
410
+ static DIR*
411
+ opendir(const char *dirname)
412
+ {
413
+ struct DIR *dirp;
414
+ int error;
415
+
416
+ /* Must have directory name */
417
+ if (dirname == NULL || dirname[0] == '\0') {
418
+ _set_errno(ENOENT);
419
+ return NULL;
420
+ }
421
+
422
+ /* Allocate memory for DIR structure */
423
+ dirp =(DIR*) malloc(sizeof(struct DIR));
424
+ if (dirp) {
425
+ wchar_t wname[PATH_MAX];
426
+ size_t n;
427
+
428
+ /* Convert directory name to wide-character string */
429
+ error = dirent_mbstowcs_s(&n, wname, PATH_MAX, dirname, PATH_MAX);
430
+ if (!error) {
431
+
432
+ /* Open directory stream using wide-character name */
433
+ dirp->wdirp = _wopendir(wname);
434
+ if (dirp->wdirp) {
435
+ /* Directory stream opened */
436
+ error = 0;
437
+ } else {
438
+ /* Failed to open directory stream */
439
+ error = 1;
440
+ }
441
+
442
+ } else {
443
+ /*
444
+ * Cannot convert file name to wide-character string. This
445
+ * occurs if the string contains invalid multi-byte sequences or
446
+ * the output buffer is too small to contain the resulting
447
+ * string.
448
+ */
449
+ error = 1;
450
+ }
451
+
452
+ } else {
453
+ /* Cannot allocate DIR structure */
454
+ error = 1;
455
+ }
456
+
457
+ /* Clean up in case of error */
458
+ if (error && dirp) {
459
+ free(dirp);
460
+ dirp = NULL;
461
+ }
462
+
463
+ return dirp;
464
+ }
465
+
466
+ /*
467
+ * Read next directory entry.
468
+ *
469
+ * When working with text consoles, please note that file names returned by
470
+ * readdir() are represented in the default ANSI code page while any output to
471
+ * console is typically formatted on another code page. Thus, non-ASCII
472
+ * characters in file names will not usually display correctly on console. The
473
+ * problem can be fixed in two ways:(1) change the character set of console
474
+ * to 1252 using chcp utility and use Lucida Console font, or(2) use
475
+ * _cprintf function when writing to console. The _cprinf() will re-encode
476
+ * ANSI strings to the console code page so many non-ASCII characters will
477
+ * display correcly.
478
+ */
479
+ static struct dirent*
480
+ readdir(DIR *dirp)
481
+ {
482
+ WIN32_FIND_DATAW *datap;
483
+ struct dirent *entp;
484
+
485
+ /* Read next directory entry */
486
+ datap = dirent_next(dirp->wdirp);
487
+ if (datap) {
488
+ size_t n;
489
+ int error;
490
+
491
+ /* Attempt to convert file name to multi-byte string */
492
+ error = dirent_wcstombs_s(
493
+ &n, dirp->ent.d_name, PATH_MAX, datap->cFileName, PATH_MAX);
494
+
495
+ /*
496
+ * If the file name cannot be represented by a multi-byte string,
497
+ * then attempt to use old 8+3 file name. This allows traditional
498
+ * Unix-code to access some file names despite of unicode
499
+ * characters, although file names may seem unfamiliar to the user.
500
+ *
501
+ * Be ware that the code below cannot come up with a short file
502
+ * name unless the file system provides one. At least
503
+ * VirtualBox shared folders fail to do this.
504
+ */
505
+ if (error && datap->cAlternateFileName[0] != '\0') {
506
+ error = dirent_wcstombs_s(
507
+ &n, dirp->ent.d_name, PATH_MAX,
508
+ datap->cAlternateFileName, PATH_MAX);
509
+ }
510
+
511
+ if (!error) {
512
+ DWORD attr;
513
+
514
+ /* Initialize directory entry for return */
515
+ entp = &dirp->ent;
516
+
517
+ /* Length of file name excluding zero terminator */
518
+ entp->d_namlen = n - 1;
519
+
520
+ /* File attributes */
521
+ attr = datap->dwFileAttributes;
522
+ if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
523
+ entp->d_type = DT_CHR;
524
+ } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
525
+ entp->d_type = DT_DIR;
526
+ } else {
527
+ entp->d_type = DT_REG;
528
+ }
529
+
530
+ /* Reset dummy fields */
531
+ entp->d_ino = 0;
532
+ entp->d_reclen = sizeof(struct dirent);
533
+
534
+ } else {
535
+ /*
536
+ * Cannot convert file name to multi-byte string so construct
537
+ * an errornous directory entry and return that. Note that
538
+ * we cannot return NULL as that would stop the processing
539
+ * of directory entries completely.
540
+ */
541
+ entp = &dirp->ent;
542
+ entp->d_name[0] = '?';
543
+ entp->d_name[1] = '\0';
544
+ entp->d_namlen = 1;
545
+ entp->d_type = DT_UNKNOWN;
546
+ entp->d_ino = 0;
547
+ entp->d_reclen = 0;
548
+ }
549
+
550
+ } else {
551
+ /* No more directory entries */
552
+ entp = NULL;
553
+ }
554
+
555
+ return entp;
556
+ }
557
+
558
+ /*
559
+ * Close directory stream.
560
+ */
561
+ static int
562
+ closedir(DIR *dirp)
563
+ {
564
+ int ok;
565
+ if (dirp) {
566
+
567
+ /* Close wide-character directory stream */
568
+ ok = _wclosedir(dirp->wdirp);
569
+ dirp->wdirp = NULL;
570
+
571
+ /* Release multi-byte character version */
572
+ free(dirp);
573
+
574
+ } else {
575
+
576
+ /* Invalid directory stream */
577
+ _set_errno(EBADF);
578
+ ok = /*failure*/-1;
579
+
580
+ }
581
+ return ok;
582
+ }
583
+
584
+ /*
585
+ * Rewind directory stream to beginning.
586
+ */
587
+ static void
588
+ rewinddir(DIR* dirp)
589
+ {
590
+ /* Rewind wide-character string directory stream */
591
+ _wrewinddir(dirp->wdirp);
592
+ }
593
+
594
+ /* Convert multi-byte string to wide character string */
595
+ static int
596
+ dirent_mbstowcs_s(size_t *pReturnValue, wchar_t *wcstr,
597
+ size_t sizeInWords, const char *mbstr, size_t count)
598
+ {
599
+ return mbstowcs_s(pReturnValue, wcstr, sizeInWords, mbstr, count);
600
+ }
601
+
602
+ /* Convert wide-character string to multi-byte string */
603
+ static int
604
+ dirent_wcstombs_s(size_t *pReturnValue, char *mbstr,
605
+ size_t sizeInBytes, /* max size of mbstr */
606
+ const wchar_t *wcstr, size_t count)
607
+ {
608
+ return wcstombs_s(pReturnValue, mbstr, sizeInBytes, wcstr, count);
609
+ }
610
+
611
+ #endif /*DIRENT_H*/