Ruby: include/ruby/win32.h Source File

Ruby 3.3.4p94 (2024-07-09 revision be1089c8ec5ba40e09b1553e36b3174bf4014d9d)

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