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