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