Ruby: include/ruby/win32.h Source File

Ruby 4.0.6p0 (2026-07-14 revision 03b6d3f8898a28604fe6cb00eae3226b821168f4)

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