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