Ruby 4.1.0dev (2026-09-26 revision da3e1fcb685864a2f58f113e82d9dc67d7fe9197)
win32.h
1#ifndef RUBY_WIN32_H
2#define RUBY_WIN32_H 1
3
4#if defined(__cplusplus)
5extern "C" {
6#if 0
7} /* satisfy cc-mode */
8#endif
9#endif
10
11RUBY_SYMBOL_EXPORT_BEGIN
12
13/*
14 * Copyright (c) 1993, Intergraph Corporation
15 *
16 * You may distribute under the terms of either the GNU General Public
17 * License or the Artistic License, as specified in the perl README file.
18 *
19 */
20
21/*
22 * Ok now we can include the normal include files.
23 */
24
25/* #include <stdarg.h> conflict with varargs.h? */
26#if !defined(WSAAPI)
27#if defined(__cplusplus) && defined(_MSC_VER)
28extern "C++" { /* template without extern "C++" */
29#endif
30#if !defined(_WIN64) && !defined(WIN32)
31#define WIN32
32#endif
33#include <winsock2.h>
34#include <ws2tcpip.h>
35#include <mswsock.h>
36#include <iphlpapi.h>
37#if defined(__cplusplus) && defined(_MSC_VER)
38}
39#endif
40#endif
41
42/*
43 * We're not using Microsoft's "extensions" to C for
44 * Structured Exception Handling (SEH) so we can nuke these
45 */
46#undef try
47#undef except
48#undef finally
49#undef leave
50
51#include <stdio.h>
52#include <stdlib.h>
53#include <string.h>
54#include <direct.h>
55#include <process.h>
56#include <time.h>
57#include <math.h>
58#include <signal.h>
59#include <sys/stat.h>
60#include <sys/types.h>
61#ifdef HAVE_SYS_UTIME_H
62# include <sys/utime.h>
63#else
64# include <utime.h>
65#endif
66#include <io.h>
67#include <malloc.h>
68#include <stdint.h>
69#ifndef __MINGW32__
70# define mode_t int
71#endif
72#ifdef HAVE_UNISTD_H
73# include <unistd.h>
74#endif
75
76#define rb_w32_iswinnt() TRUE
77#define rb_w32_iswin95() FALSE
78
79#define WNOHANG -1
80
81#define O_SHARE_DELETE 0x20000000 /* for rb_w32_open(), rb_w32_wopen() */
82
83typedef int clockid_t;
84
85/*
86 * Since we use our versions in win32/win32.c, not to depend on yet
87 * another DLL, prefix our versions not to conflict with inline
88 * versions provided in time.h.
89 */
90#define clock_gettime rb_w32_clock_gettime
91#define clock_getres rb_w32_clock_getres
92
93#ifndef CLOCK_REALTIME
94# define CLOCK_REALTIME 0
95#endif
96#ifndef CLOCK_MONOTONIC
97# define CLOCK_MONOTONIC 1
98#endif
99#ifndef CLOCK_PROCESS_CPUTIME_ID
100# define CLOCK_PROCESS_CPUTIME_ID 2
101#endif
102#ifndef CLOCK_THREAD_CPUTIME_ID
103# define CLOCK_THREAD_CPUTIME_ID 3
104#endif
105#ifndef CLOCK_REALTIME_COARSE
106# define CLOCK_REALTIME_COARSE 4
107#endif
108
109#undef utime
110#undef lseek
111#undef stat
112#undef fstat
113#ifdef RUBY_EXPORT
114#define utime(_p, _t) rb_w32_uutime(_p, _t)
115#undef HAVE_UTIMES
116#define HAVE_UTIMES 1
117#define utimes(_p, _t) rb_w32_uutimes(_p, _t)
118#undef HAVE_UTIMENSAT
119#define HAVE_UTIMENSAT 1
120#define AT_FDCWD -100
121#define utimensat(_d, _p, _t, _f) rb_w32_uutimensat(_d, _p, _t, _f)
122#define lseek(_f, _o, _w) rb_w32_lseek(_f, _o, _w)
123
124#define pipe(p) rb_w32_pipe(p)
125#define open rb_w32_uopen
126#define close(h) rb_w32_close(h)
127#define fclose(f) rb_w32_fclose(f)
128#define read(f, b, s) rb_w32_read(f, b, s)
129#define write(f, b, s) rb_w32_write(f, b, s)
130#define pread(f, b, s, o) rb_w32_pread(f, b, s, o)
131#define pwrite(f, b, s, o) rb_w32_pwrite(f, b, s, o)
132#define getpid() rb_w32_getpid()
133#undef HAVE_GETPPID
134#define HAVE_GETPPID 1
135#define getppid() rb_w32_getppid()
136#define sleep(x) rb_w32_Sleep((x)*1000)
137#define Sleep(msec) (void)rb_w32_Sleep(msec)
138
139#undef HAVE_EXECV
140#define HAVE_EXECV 1
141#undef execv
142#define execv(path,argv) rb_w32_uaspawn(P_OVERLAY,path,argv)
143#undef isatty
144#define isatty(h) rb_w32_isatty(h)
145
146#undef mkdir
147#define mkdir(p, m) rb_w32_umkdir(p, m)
148#undef rmdir
149#define rmdir(p) rb_w32_urmdir(p)
150#undef unlink
151#define unlink(p) rb_w32_uunlink(p)
152#endif /* RUBY_EXPORT */
153
154/* same with stati64 except the size of st_ino and nanosecond timestamps */
155struct stati128 {
156 _dev_t st_dev;
157 unsigned __int64 st_ino;
158 __int64 st_inohigh;
159 unsigned short st_mode;
160 short st_nlink;
161 short st_uid;
162 short st_gid;
163 _dev_t st_rdev;
164 __int64 st_size;
165 __time64_t st_atime;
166 long st_atimensec;
167 __time64_t st_mtime;
168 long st_mtimensec;
169 __time64_t st_ctime;
170 long st_ctimensec;
171};
172
173#define stat stati128
174#undef SIZEOF_STRUCT_STAT_ST_INO
175#define SIZEOF_STRUCT_STAT_ST_INO sizeof(unsigned __int64)
176#define HAVE_STRUCT_STAT_ST_INOHIGH
177#define HAVE_STRUCT_STAT_ST_ATIMENSEC
178#define HAVE_STRUCT_STAT_ST_MTIMENSEC
179#define HAVE_STRUCT_STAT_ST_CTIMENSEC
180#define fstat(fd,st) rb_w32_fstati128(fd,st)
181#define stati128(path, st) rb_w32_ustati128(path,st)
182#define lstat(path,st) rb_w32_ulstati128(path,st)
183#define access(path,mode) rb_w32_uaccess(path,mode)
184
185#define strcasecmp _stricmp
186#define strncasecmp _strnicmp
187#define fsync _commit
188
189struct timezone;
190
191#ifdef __MINGW32__
192#undef isascii
193#define isascii __isascii
194#endif
195
196struct iovec {
197 void *iov_base;
198 size_t iov_len;
199};
200struct msghdr {
201 void *msg_name;
202 int msg_namelen;
203 struct iovec *msg_iov;
204 int msg_iovlen;
205 void *msg_control;
206 int msg_controllen;
207 int msg_flags;
208};
209
210/* for getifaddrs() and others */
211struct ifaddrs {
212 struct ifaddrs *ifa_next;
213 char *ifa_name;
214 u_int ifa_flags;
215 struct sockaddr *ifa_addr;
216 struct sockaddr *ifa_netmask;
217 struct sockaddr *ifa_broadaddr;
218 struct sockaddr *ifa_dstaddr;
219 void *ifa_data;
220};
221#ifdef IF_NAMESIZE
222#define IFNAMSIZ IF_NAMESIZE
223#else
224#define IFNAMSIZ 256
225#endif
226#ifdef IFF_POINTTOPOINT
227#define IFF_POINTOPOINT IFF_POINTTOPOINT
228#endif
229
230extern void rb_w32_sysinit(int *, char ***);
231extern int flock(int fd, int oper);
232extern int rb_w32_io_cancelable_p(int);
233extern int rb_w32_is_socket(int);
234extern int WSAAPI rb_w32_accept(int, struct sockaddr *, int *);
235extern int WSAAPI rb_w32_bind(int, const struct sockaddr *, int);
236extern int WSAAPI rb_w32_connect(int, const struct sockaddr *, int);
237extern void rb_w32_fdset(int, fd_set*);
238extern void rb_w32_fdclr(int, fd_set*);
239extern int rb_w32_fdisset(int, fd_set*);
240extern int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
241extern int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *);
242extern int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *);
243extern int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *);
244extern int WSAAPI rb_w32_ioctlsocket(int, long, u_long *);
245extern int WSAAPI rb_w32_listen(int, int);
246extern int WSAAPI rb_w32_recv(int, char *, int, int);
247extern int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *);
248extern int WSAAPI rb_w32_send(int, const char *, int, int);
249extern int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int);
250extern int recvmsg(int, struct msghdr *, int);
251extern int sendmsg(int, const struct msghdr *, int);
252extern int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int);
253extern int WSAAPI rb_w32_shutdown(int, int);
254extern int WSAAPI rb_w32_socket(int, int, int);
255extern SOCKET rb_w32_get_osfhandle(int);
256extern struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int);
257extern struct hostent *WSAAPI rb_w32_gethostbyname(const char *);
258extern int WSAAPI rb_w32_gethostname(char *, int);
259extern struct protoent *WSAAPI rb_w32_getprotobyname(const char *);
260extern struct protoent *WSAAPI rb_w32_getprotobynumber(int);
261extern struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *);
262extern struct servent *WSAAPI rb_w32_getservbyport(int, const char *);
263extern int socketpair(int, int, int, int *);
264extern int getifaddrs(struct ifaddrs **);
265extern void freeifaddrs(struct ifaddrs *);
266extern char * rb_w32_ugetcwd(char *, int);
267extern char * rb_w32_ugetenv(const char *);
268extern int rb_w32_urename(const char *, const char *);
269extern char **rb_w32_get_environ(void);
270extern void rb_w32_free_environ(char **);
271extern int rb_w32_map_errno(DWORD);
272extern const char *WSAAPI rb_w32_inet_ntop(int,const void *,char *,size_t);
273extern int WSAAPI rb_w32_inet_pton(int,const char *,void *);
274
275RBIMPL_ATTR_DEPRECATED(("as Windows 9x is not supported already"))
276static inline DWORD rb_w32_osid(void) {return VER_PLATFORM_WIN32_NT;}
277RBIMPL_ATTR_DEPRECATED(("by Windows Version Helper APIs"))
278extern DWORD rb_w32_osver(void);
279
280extern int rb_w32_uchown(const char *, int, int);
281extern int rb_w32_ulink(const char *, const char *);
282extern ssize_t rb_w32_ureadlink(const char *, char *, size_t);
283extern int rb_w32_usymlink(const char *src, const char *link);
284extern int gettimeofday(struct timeval *, struct timezone *);
285extern int clock_gettime(clockid_t, struct timespec *);
286extern int clock_getres(clockid_t, struct timespec *);
287extern rb_pid_t waitpid(rb_pid_t, int *, int);
288extern rb_pid_t wait(int *);
289extern rb_pid_t rb_w32_uspawn(int, const char *, const char*);
290extern rb_pid_t rb_w32_uaspawn(int, const char *, char *const *);
291extern rb_pid_t rb_w32_uaspawn_flags(int, const char *, char *const *, DWORD);
292#undef HAVE_KILL
293#define HAVE_KILL 1
294extern int kill(rb_pid_t, int);
295extern int fcntl(int, int, ...);
296extern int rb_w32_set_nonblock(int);
297extern rb_pid_t rb_w32_getpid(void);
298extern rb_pid_t rb_w32_getppid(void);
299extern int rb_w32_isatty(int);
300extern int rb_w32_uchdir(const char *);
301extern int rb_w32_umkdir(const char *, int);
302extern int rb_w32_urmdir(const char *);
303extern int rb_w32_uunlink(const char *);
304extern int rb_w32_uchmod(const char *, int);
305extern int rb_w32_ustati128(const char *, struct stati128 *);
306extern int rb_w32_ulstati128(const char *, struct stati128 *);
307extern int rb_w32_uaccess(const char *, int);
308extern char rb_w32_fd_is_text(int);
309extern int rb_w32_fstati128(int, struct stati128 *);
310extern int rb_w32_dup2(int, int);
311
312#include <float.h>
313
314#if defined _MSC_VER && defined INFINITY
315#pragma warning(push)
316#pragma warning(disable:4756)
317static inline float
318rb_infinity_float(void)
319{
320 return INFINITY;
321}
322#pragma warning(pop)
323#undef INFINITY
324#define INFINITY rb_infinity_float()
325#endif
326
327#if !defined __MINGW32__ || defined __NO_ISOCEXT
328#ifndef copysign
329#define copysign(a, b) _copysign(a, b)
330#endif
331static inline double
332scalb(double a, long b)
333{
334 return _scalb(a, b);
335}
336#endif
337
338#if !defined S_IFIFO && defined _S_IFIFO
339#define S_IFIFO _S_IFIFO
340#endif
341
342#if !defined S_IRUSR && !defined __MINGW32__
343#define S_IRUSR 0400
344#endif
345#ifndef S_IRGRP
346#define S_IRGRP 0040
347#endif
348#ifndef S_IROTH
349#define S_IROTH 0004
350#endif
351
352#if !defined S_IWUSR && !defined __MINGW32__
353#define S_IWUSR 0200
354#endif
355#ifndef S_IWGRP
356#define S_IWGRP 0020
357#endif
358#ifndef S_IWOTH
359#define S_IWOTH 0002
360#endif
361
362#if !defined S_IXUSR && !defined __MINGW32__
363#define S_IXUSR 0100
364#endif
365#ifndef S_IXGRP
366#define S_IXGRP 0010
367#endif
368#ifndef S_IXOTH
369#define S_IXOTH 0001
370#endif
371
372#define S_IFLNK 0xa000
373#define S_IFSOCK 0xc000
374
375/*
376 * define this so we can do inplace editing
377 */
378
379#define SUFFIX
380
381extern int rb_w32_ftruncate(int fd, rb_off_t length);
382extern int rb_w32_truncate(const char *path, rb_off_t length);
383extern int rb_w32_utruncate(const char *path, rb_off_t length);
384
385#undef HAVE_FTRUNCATE
386#define HAVE_FTRUNCATE 1
387#if defined HAVE_FTRUNCATE64
388#define ftruncate ftruncate64
389#else
390#define ftruncate rb_w32_ftruncate
391#endif
392
393#undef HAVE_TRUNCATE
394#define HAVE_TRUNCATE 1
395#define truncate rb_w32_utruncate
396
397/*
398 * stubs
399 */
400extern int ioctl (int, int, ...);
401extern rb_uid_t getuid (void);
402extern rb_uid_t geteuid (void);
403extern rb_gid_t getgid (void);
404extern rb_gid_t getegid (void);
405extern int setuid (rb_uid_t);
406extern int setgid (rb_gid_t);
407
408extern char *rb_w32_strerror(int);
409
410#ifdef RUBY_EXPORT
411#define strerror(e) rb_w32_strerror(e)
412#endif
413
414#define PIPE_BUF 1024
415
416#define LOCK_SH 1
417#define LOCK_EX 2
418#define LOCK_NB 4
419#define LOCK_UN 8
420
421
422#ifndef SIGINT
423#define SIGINT 2
424#endif
425#ifndef SIGKILL
426#define SIGKILL 9
427#endif
428
429
430/* #undef va_start */
431/* #undef va_end */
432
433/* winsock error map */
434#include <errno.h>
435
436#ifndef EWOULDBLOCK
437# define EWOULDBLOCK WSAEWOULDBLOCK
438#endif
439#ifndef EINPROGRESS
440# define EINPROGRESS WSAEINPROGRESS
441#endif
442#ifndef EALREADY
443# define EALREADY WSAEALREADY
444#endif
445#ifndef ENOTSOCK
446# define ENOTSOCK WSAENOTSOCK
447#endif
448#ifndef EDESTADDRREQ
449# define EDESTADDRREQ WSAEDESTADDRREQ
450#endif
451#ifndef EMSGSIZE
452# define EMSGSIZE WSAEMSGSIZE
453#endif
454#ifndef EPROTOTYPE
455# define EPROTOTYPE WSAEPROTOTYPE
456#endif
457#ifndef ENOPROTOOPT
458# define ENOPROTOOPT WSAENOPROTOOPT
459#endif
460#ifndef EPROTONOSUPPORT
461# define EPROTONOSUPPORT WSAEPROTONOSUPPORT
462#endif
463#ifndef ESOCKTNOSUPPORT
464# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
465#endif
466#ifndef EOPNOTSUPP
467# define EOPNOTSUPP WSAEOPNOTSUPP
468#endif
469#ifndef EPFNOSUPPORT
470# define EPFNOSUPPORT WSAEPFNOSUPPORT
471#endif
472#ifndef EAFNOSUPPORT
473# define EAFNOSUPPORT WSAEAFNOSUPPORT
474#endif
475#ifndef EADDRINUSE
476# define EADDRINUSE WSAEADDRINUSE
477#endif
478#ifndef EADDRNOTAVAIL
479# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
480#endif
481#ifndef ENETDOWN
482# define ENETDOWN WSAENETDOWN
483#endif
484#ifndef ENETUNREACH
485# define ENETUNREACH WSAENETUNREACH
486#endif
487#ifndef ENETRESET
488# define ENETRESET WSAENETRESET
489#endif
490#ifndef ECONNABORTED
491# define ECONNABORTED WSAECONNABORTED
492#endif
493#ifndef ECONNRESET
494# define ECONNRESET WSAECONNRESET
495#endif
496#ifndef ENOBUFS
497# define ENOBUFS WSAENOBUFS
498#endif
499#ifndef EISCONN
500# define EISCONN WSAEISCONN
501#endif
502#ifndef ENOTCONN
503# define ENOTCONN WSAENOTCONN
504#endif
505#ifndef ESHUTDOWN
506# define ESHUTDOWN WSAESHUTDOWN
507#endif
508#ifndef ETOOMANYREFS
509# define ETOOMANYREFS WSAETOOMANYREFS
510#endif
511#ifndef ETIMEDOUT
512# define ETIMEDOUT WSAETIMEDOUT
513#endif
514#ifndef ECONNREFUSED
515# define ECONNREFUSED WSAECONNREFUSED
516#endif
517#ifndef ELOOP
518# define ELOOP WSAELOOP
519#endif
520/*#define ENAMETOOLONG WSAENAMETOOLONG*/
521#ifndef EHOSTDOWN
522# define EHOSTDOWN WSAEHOSTDOWN
523#endif
524#ifndef EHOSTUNREACH
525# define EHOSTUNREACH WSAEHOSTUNREACH
526#endif
527/*#define ENOTEMPTY WSAENOTEMPTY*/
528#ifndef EPROCLIM
529# define EPROCLIM WSAEPROCLIM
530#endif
531#ifndef EUSERS
532# define EUSERS WSAEUSERS
533#endif
534#ifndef EDQUOT
535# define EDQUOT WSAEDQUOT
536#endif
537#ifndef ESTALE
538# define ESTALE WSAESTALE
539#endif
540#ifndef EREMOTE
541# define EREMOTE WSAEREMOTE
542#endif
543
544#define F_DUPFD 0
545#define F_GETFD 1
546#define F_SETFD 2
547#if 0
548#define F_GETFL 3
549#endif
550#define F_SETFL 4
551#define F_DUPFD_CLOEXEC 67
552#define FD_CLOEXEC 1 /* F_GETFD, F_SETFD */
553#define O_NONBLOCK 1
554
555#undef FD_SET
556#define FD_SET(fd, set) do {\
557 unsigned int i;\
558 SOCKET s = _get_osfhandle(fd);\
559\
560 for (i = 0; i < (set)->fd_count; i++) {\
561 if ((set)->fd_array[i] == s) {\
562 break;\
563 }\
564 }\
565 if (i == (set)->fd_count) {\
566 if ((set)->fd_count < FD_SETSIZE) {\
567 (set)->fd_array[i] = s;\
568 (set)->fd_count++;\
569 }\
570 }\
571} while(0)
572
573#undef FD_CLR
574#define FD_CLR(f, s) rb_w32_fdclr(f, s)
575
576#undef FD_ISSET
577#define FD_ISSET(f, s) rb_w32_fdisset(f, s)
578
579#ifdef RUBY_EXPORT
580#undef inet_ntop
581#define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l)
582
583#undef inet_pton
584#define inet_pton(f,s,d) rb_w32_inet_pton(f,s,d)
585
586#undef accept
587#define accept(s, a, l) rb_w32_accept(s, a, l)
588
589#undef bind
590#define bind(s, a, l) rb_w32_bind(s, a, l)
591
592#undef connect
593#define connect(s, a, l) rb_w32_connect(s, a, l)
594
595#undef select
596#define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t)
597
598#undef getpeername
599#define getpeername(s, a, l) rb_w32_getpeername(s, a, l)
600
601#undef getsockname
602#define getsockname(s, a, l) rb_w32_getsockname(s, a, l)
603
604#undef getsockopt
605#define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
606
607#undef ioctlsocket
608#define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a)
609
610#undef listen
611#define listen(s, b) rb_w32_listen(s, b)
612
613#undef recv
614#define recv(s, b, l, f) rb_w32_recv(s, b, l, f)
615
616#undef recvfrom
617#define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
618
619#undef send
620#define send(s, b, l, f) rb_w32_send(s, b, l, f)
621
622#undef sendto
623#define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
624
625#undef setsockopt
626#define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
627
628#undef HAVE_SHUTDOWN
629#define HAVE_SHUTDOWN 1
630#undef shutdown
631#define shutdown(s, h) rb_w32_shutdown(s, h)
632
633#undef socket
634#define socket(s, t, p) rb_w32_socket(s, t, p)
635
636#undef gethostbyaddr
637#define gethostbyaddr(a, l, t) rb_w32_gethostbyaddr(a, l, t)
638
639#undef gethostbyname
640#define gethostbyname(n) rb_w32_gethostbyname(n)
641
642#undef gethostname
643#define gethostname(n, l) rb_w32_gethostname(n, l)
644
645#undef getprotobyname
646#define getprotobyname(n) rb_w32_getprotobyname(n)
647
648#undef getprotobynumber
649#define getprotobynumber(n) rb_w32_getprotobynumber(n)
650
651#undef getservbyname
652#define getservbyname(n, p) rb_w32_getservbyname(n, p)
653
654#undef getservbyport
655#define getservbyport(p, pr) rb_w32_getservbyport(p, pr)
656
657#undef get_osfhandle
658#define get_osfhandle(h) rb_w32_get_osfhandle(h)
659
660#undef getcwd
661#define getcwd(b, s) rb_w32_ugetcwd(b, s)
662
663#undef getenv
664#define getenv(n) rb_w32_ugetenv(n)
665
666#undef rename
667#define rename(o, n) rb_w32_urename(o, n)
668
669#undef times
670#define times(t) rb_w32_times(t)
671
672#undef dup2
673#define dup2(o, n) rb_w32_dup2(o, n)
674#endif
675
676struct tms {
677 long tms_utime;
678 long tms_stime;
679 long tms_cutime;
680 long tms_cstime;
681};
682
683int rb_w32_times(struct tms *);
684
685struct tm *gmtime_r(const time_t *, struct tm *);
686struct tm *localtime_r(const time_t *, struct tm *);
687
688/* thread stuff */
689int rb_w32_sleep(unsigned long msec);
690int rb_w32_uopen(const char *, int, ...);
691int rb_w32_wopen(const WCHAR *, int, ...);
692int rb_w32_close(int);
693int rb_w32_fclose(FILE*);
694int rb_w32_pipe(int[2]);
695ssize_t rb_w32_read(int, void *, size_t);
696ssize_t rb_w32_write(int, const void *, size_t);
697ssize_t rb_w32_pread(int, void *, size_t, rb_off_t offset);
698ssize_t rb_w32_pwrite(int, const void *, size_t, rb_off_t offset);
699rb_off_t rb_w32_lseek(int, rb_off_t, int);
700int rb_w32_uutime(const char *, const struct utimbuf *);
701int rb_w32_uutimes(const char *, const struct timeval *);
702int rb_w32_uutimensat(int /* must be AT_FDCWD */, const char *, const struct timespec *, int /* must be 0 */);
703long rb_w32_write_console(uintptr_t, int); /* use uintptr_t instead of VALUE because it's not defined yet here */
704int WINAPI rb_w32_Sleep(unsigned long msec);
705int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout);
706int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait);
707int rb_w32_wrap_io_handle(HANDLE, int);
708int rb_w32_unwrap_io_handle(int);
709WCHAR *rb_w32_mbstr_to_wstr(UINT, const char *, int, long *);
710char *rb_w32_wstr_to_mbstr(UINT, const WCHAR *, int, long *);
711
712DEPRECATED_BY(rb_w32_ugetcwd, char *rb_w32_getcwd(char *, int));
713DEPRECATED_BY(rb_w32_ugetenv, char *rb_w32_getenv(const char *));
714DEPRECATED_BY(rb_w32_urename, int rb_w32_rename(const char *, const char *));
715DEPRECATED_BY(rb_w32_uopen, int rb_w32_open(const char *, int, ...));
716DEPRECATED_BY(rb_w32_uchown, int chown(const char *, int, int));
717DEPRECATED_BY(rb_w32_ulink, int link(const char *, const char *));
718DEPRECATED_BY(rb_w32_ureadlink, ssize_t readlink(const char *, char *, size_t));
719DEPRECATED_BY(rb_w32_usymlink, int symlink(const char *src, const char *link));
720DEPRECATED_BY(rb_w32_umkdir, int rb_w32_mkdir(const char *, int));
721DEPRECATED_BY(rb_w32_urmdir, int rb_w32_rmdir(const char *));
722DEPRECATED_BY(rb_w32_uunlink, int rb_w32_unlink(const char *));
723DEPRECATED_BY(rb_w32_uutime, int rb_w32_utime(const char *, const struct utimbuf *));
724DEPRECATED_BY(rb_w32_uutimes, int rb_w32_utimes(const char *, const struct timeval *));
725DEPRECATED_BY(rb_w32_uutimensat, int rb_w32_utimensat(int, const char *, const struct timespec *, int));
726DEPRECATED_BY(rb_w32_ustati128, int rb_w32_stati128(const char *, struct stati128 *));
727DEPRECATED_BY(rb_w32_ulstati128, int rb_w32_lstati128(const char *, struct stati128 *));
728DEPRECATED_BY(rb_w32_uaccess, int rb_w32_access(const char *, int));
729DEPRECATED_BY(rb_w32_uspawn, rb_pid_t rb_w32_spawn(int, const char *, const char*));
730DEPRECATED_BY(rb_w32_uaspawn, rb_pid_t rb_w32_aspawn(int, const char *, char *const *));
731DEPRECATED_BY(rb_w32_uaspawn_flags, rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD));
732
733/*
734== ***CAUTION***
735Since this function is very dangerous, ((*NEVER*))
736* lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
737* use anything like rb_thread_call_without_gvl,
738in asynchronous_func_t.
739*/
740typedef uintptr_t (*asynchronous_func_t)(uintptr_t self, int argc, uintptr_t* argv);
741uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t* argv, uintptr_t intrval);
742
743RUBY_SYMBOL_EXPORT_END
744
745#if (defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW64__)) && !defined(__cplusplus)
746#ifdef RUBY_MINGW64_BROKEN_FREXP_MODF
747/* License: Ruby's */
748/* get rid of bugs in math.h of mingw */
749#define frexp(_X, _Y) __extension__ ({\
750 int intpart_frexp_bug = intpart_frexp_bug;\
751 double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\
752 *(_Y) = intpart_frexp_bug;\
753 result_frexp_bug;\
754})
755/* License: Ruby's */
756#define modf(_X, _Y) __extension__ ({\
757 double intpart_modf_bug = intpart_modf_bug;\
758 double result_modf_bug = modf((_X), &intpart_modf_bug);\
759 *(_Y) = intpart_modf_bug;\
760 result_modf_bug;\
761})
762#endif
763
764#if defined(__MINGW64__)
765/*
766 * Use powl() instead of broken pow() of x86_64-w64-mingw32.
767 * This workaround will fix test failures in test_bignum.rb,
768 * test_fixnum.rb and test_float.rb etc.
769 */
770static inline double
771rb_w32_pow(double x, double y)
772{
773 return (double)powl(x, y);
774}
775#elif defined(__MINGW64_VERSION_MAJOR)
776double rb_w32_pow(double x, double y);
777#endif
778#define pow rb_w32_pow
779#endif
780
781// mmap tiny emulation
782#define MAP_FAILED ((void *)-1)
783
784#define PROT_READ 0x01
785#define PROT_WRITE 0x02
786#define PROT_EXEC 0x04
787
788#define MAP_PRIVATE 0x0002
789#define MAP_ANON 0x1000
790#define MAP_ANONYMOUS MAP_ANON
791
792extern void *rb_w32_mmap(void *, size_t, int, int, int, rb_off_t);
793extern int rb_w32_munmap(void *, size_t);
794extern int rb_w32_mprotect(void *, size_t, int);
795
796#define mmap(a, l, p, f, d, o) rb_w32_mmap(a, l, p, f, d, o)
797#define munmap(a, l) rb_w32_munmap(a, l)
798#define mprotect(a, l, prot) rb_w32_mprotect(a, l, prot)
799
800#if defined(__cplusplus)
801#if 0
802{ /* satisfy cc-mode */
803#endif
804} /* extern "C" { */
805#endif
806
807#endif /* RUBY_WIN32_H */
#define RBIMPL_ATTR_DEPRECATED(msg)
Wraps (or simulates) [[deprecated]]
Definition deprecated.h:64
Definition win32.h:196
Definition win32.h:676