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