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