Ruby: include/ruby/win32.h Source File

Ruby 3.4.5p51 (2025-07-16 revision 20cda200d3ce092571d0b5d342dadca69636cb0f)

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