Ruby  1.9.3p547(2014-05-14revision45962)
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 
11 #if defined __GNUC__ && __GNUC__ >= 4
12 #pragma GCC visibility push(default)
13 #endif
14 
15 /*
16  * Copyright (c) 1993, Intergraph Corporation
17  *
18  * You may distribute under the terms of either the GNU General Public
19  * License or the Artistic License, as specified in the perl README file.
20  *
21  */
22 
23 //
24 // Definitions for NT port of Perl
25 //
26 
27 
28 //
29 // Ok now we can include the normal include files.
30 //
31 
32 // #include <stdarg.h> conflict with varargs.h?
33 #if !defined(WSAAPI)
34 #if defined(__cplusplus) && defined(_MSC_VER)
35 extern "C++" { /* template without extern "C++" */
36 #endif
37 #if !defined(_WIN64) && !defined(WIN32)
38 #define WIN32
39 #endif
40 #include <winsock2.h>
41 #include <ws2tcpip.h>
42 #if defined(__cplusplus) && defined(_MSC_VER)
43 }
44 #endif
45 #endif
46 
47 #define NT 1 /* deprecated */
48 
49 //
50 // We're not using Microsoft's "extensions" to C for
51 // Structured Exception Handling (SEH) so we can nuke these
52 //
53 #undef try
54 #undef except
55 #undef finally
56 #undef leave
57 
58 #include <stdio.h>
59 #include <stdlib.h>
60 #include <string.h>
61 #include <direct.h>
62 #include <process.h>
63 #include <time.h>
64 #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
65 extern "C++" { /* template without extern "C++" */
66 #endif
67 #include <math.h>
68 #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
69 }
70 #endif
71 #include <signal.h>
72 #include <sys/stat.h>
73 #include <sys/types.h>
74 #ifdef HAVE_SYS_UTIME_H
75 # include <sys/utime.h>
76 #else
77 # include <utime.h>
78 #endif
79 #include <io.h>
80 #include <malloc.h>
81 #if defined __MINGW32__ || __BORLANDC__ >= 0x0580
82 # include <stdint.h>
83 #else
84 # if !defined(_INTPTR_T_DEFINED)
85 # ifdef _WIN64
86 typedef __int64 intptr_t;
87 # else
88 typedef int intptr_t;
89 # endif
90 # define _INTPTR_T_DEFINED
91 # endif
92 # if !defined(_UINTPTR_T_DEFINED)
93 # ifdef _WIN64
94 typedef unsigned __int64 uintptr_t;
95 # else
96 typedef unsigned int uintptr_t;
97 # endif
98 # define _UINTPTR_T_DEFINED
99 # endif
100 #endif
101 #ifndef __MINGW32__
102 # define mode_t int
103 #endif
104 #ifdef HAVE_UNISTD_H
105 # include <unistd.h>
106 #endif
107 
108 #ifdef WIN95
109 extern DWORD rb_w32_osid(void);
110 #define rb_w32_iswinnt() (rb_w32_osid() == VER_PLATFORM_WIN32_NT)
111 #define rb_w32_iswin95() (rb_w32_osid() == VER_PLATFORM_WIN32_WINDOWS)
112 #else
113 #define rb_w32_iswinnt() TRUE
114 #define rb_w32_iswin95() FALSE
115 #endif
116 
117 #define WNOHANG -1
118 
119 #undef getc
120 #undef putc
121 #undef fgetc
122 #undef fputc
123 #undef getchar
124 #undef putchar
125 #undef fgetchar
126 #undef fputchar
127 #undef utime
128 #undef lseek
129 #undef stat
130 #undef fstat
131 #define getc(_stream) rb_w32_getc(_stream)
132 #define getchar() rb_w32_getc(stdin)
133 #define putc(_c, _stream) rb_w32_putc(_c, _stream)
134 #define putchar(_c) rb_w32_putc(_c, stdout)
135 #ifdef RUBY_EXPORT
136 #define fgetc(_stream) getc(_stream)
137 #define fputc(_c, _stream) putc(_c, _stream)
138 #define fgetchar() getchar()
139 #define fputchar(_c) putchar(_c)
140 #define utime(_p, _t) rb_w32_utime(_p, _t)
141 #define lseek(_f, _o, _w) _lseeki64(_f, _o, _w)
142 
143 #define pipe(p) rb_w32_pipe(p)
144 #define open rb_w32_open
145 #define close(h) rb_w32_close(h)
146 #define fclose(f) rb_w32_fclose(f)
147 #define read(f, b, s) rb_w32_read(f, b, s)
148 #define write(f, b, s) rb_w32_write(f, b, s)
149 #define getpid() rb_w32_getpid()
150 #define getppid() rb_w32_getppid()
151 #define sleep(x) rb_w32_Sleep((x)*1000)
152 #define Sleep(msec) (void)rb_w32_Sleep(msec)
153 #define fstati64(fd,st) rb_w32_fstati64(fd,st)
154 #ifdef __BORLANDC__
155 #define creat(p, m) _creat(p, m)
156 #define eof() _eof()
157 #define filelength(h) _filelength(h)
158 #define mktemp(t) _mktemp(t)
159 #define tell(h) _tell(h)
160 #define _open _sopen
161 #define sopen _sopen
162 #undef fopen
163 #define fopen(p, m) rb_w32_fopen(p, m)
164 #undef fdopen
165 #define fdopen(h, m) rb_w32_fdopen(h, m)
166 #undef fsopen
167 #define fsopen(p, m, sh) rb_w32_fsopen(p, m, sh)
168 #endif /* __BORLANDC__ */
169 
170 #undef execv
171 #define execv(path,argv) rb_w32_aspawn(P_OVERLAY,path,argv)
172 #if !defined(__BORLANDC__)
173 #undef isatty
174 #define isatty(h) rb_w32_isatty(h)
175 #endif /* __BORLANDC__ */
176 
177 #undef mkdir
178 #define mkdir(p, m) rb_w32_mkdir(p, m)
179 #undef rmdir
180 #define rmdir(p) rb_w32_rmdir(p)
181 #undef unlink
182 #define unlink(p) rb_w32_unlink(p)
183 #endif /* RUBY_EXPORT */
184 
185 #if SIZEOF_OFF_T == 8
186 #define off_t __int64
187 #define stat stati64
188 #define fstat(fd,st) fstati64(fd,st)
189 #if defined(__BORLANDC__)
190 #define stati64(path, st) rb_w32_stati64(path, st)
191 #elif !defined(_MSC_VER) || RT_VER < 80
192 #define stati64 _stati64
193 #ifndef _stati64
194 #define _stati64(path, st) rb_w32_stati64(path, st)
195 #endif
196 #else
197 #define stati64 _stat64
198 #define _stat64(path, st) rb_w32_stati64(path, st)
199 #endif
200 #else
201 #define stat(path,st) rb_w32_stat(path,st)
202 #define fstat(fd,st) rb_w32_fstat(fd,st)
203 extern int rb_w32_stat(const char *, struct stat *);
204 extern int rb_w32_fstat(int, struct stat *);
205 #endif
206 #define access(path,mode) rb_w32_access(path,mode)
207 
208 #define strcasecmp _stricmp
209 #define strncasecmp _strnicmp
210 #define fsync _commit
211 
212 struct timezone;
213 
214 #ifdef __MINGW32__
215 #undef isascii
216 #define isascii __isascii
217 #endif
218 
219 struct iovec {
220  void *iov_base;
221  size_t iov_len;
222 };
223 struct msghdr {
224  void *msg_name;
226  struct iovec *msg_iov;
228  void *msg_control;
231 };
232 
233 #define NtInitialize ruby_sysinit
234 extern int rb_w32_cmdvector(const char *, char ***);
235 extern rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int *, int *);
236 extern int flock(int fd, int oper);
237 extern int rb_w32_io_cancelable_p(int);
238 extern int rb_w32_is_socket(int);
239 extern int WSAAPI rb_w32_accept(int, struct sockaddr *, int *);
240 extern int WSAAPI rb_w32_bind(int, const struct sockaddr *, int);
241 extern int WSAAPI rb_w32_connect(int, const struct sockaddr *, int);
242 extern void rb_w32_fdset(int, fd_set*);
243 extern void rb_w32_fdclr(int, fd_set*);
244 extern int rb_w32_fdisset(int, fd_set*);
245 extern int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
246 extern int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *);
247 extern int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *);
248 extern int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *);
249 extern int WSAAPI rb_w32_ioctlsocket(int, long, u_long *);
250 extern int WSAAPI rb_w32_listen(int, int);
251 extern int WSAAPI rb_w32_recv(int, char *, int, int);
252 extern int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *);
253 extern int WSAAPI rb_w32_send(int, const char *, int, int);
254 extern int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int);
255 extern int recvmsg(int, struct msghdr *, int);
256 extern int sendmsg(int, const struct msghdr *, int);
257 extern int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int);
258 extern int WSAAPI rb_w32_shutdown(int, int);
259 extern int WSAAPI rb_w32_socket(int, int, int);
260 extern SOCKET rb_w32_get_osfhandle(int);
261 extern struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int);
262 extern struct hostent *WSAAPI rb_w32_gethostbyname(const char *);
263 extern int WSAAPI rb_w32_gethostname(char *, int);
264 extern struct protoent *WSAAPI rb_w32_getprotobyname(const char *);
265 extern struct protoent *WSAAPI rb_w32_getprotobynumber(int);
266 extern struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *);
267 extern struct servent *WSAAPI rb_w32_getservbyport(int, const char *);
268 extern int rb_w32_socketpair(int, int, int, int *);
269 extern char * rb_w32_getcwd(char *, int);
270 extern char * rb_w32_getenv(const char *);
271 extern int rb_w32_rename(const char *, const char *);
272 extern int rb_w32_urename(const char *, const char *);
273 extern char **rb_w32_get_environ(void);
274 extern void rb_w32_free_environ(char **);
275 extern int rb_w32_map_errno(DWORD);
276 extern char * WSAAPI rb_w32_inet_ntop(int,void *,char *,size_t);
277 extern DWORD rb_w32_osver(void);
278 
279 extern int chown(const char *, int, int);
280 extern int rb_w32_uchown(const char *, int, int);
281 extern int link(const char *, const char *);
282 extern int rb_w32_ulink(const char *, const char *);
283 extern int gettimeofday(struct timeval *, struct timezone *);
284 extern rb_pid_t waitpid (rb_pid_t, int *, int);
285 extern rb_pid_t rb_w32_spawn(int, const char *, const char*);
286 extern rb_pid_t rb_w32_aspawn(int, const char *, char *const *);
287 extern rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD);
288 extern int kill(int, int);
289 extern int fcntl(int, int, ...);
290 extern rb_pid_t rb_w32_getpid(void);
291 extern rb_pid_t rb_w32_getppid(void);
292 #if !defined(__BORLANDC__)
293 extern int rb_w32_isatty(int);
294 #endif
295 extern int rb_w32_uchdir(const char *);
296 extern int rb_w32_mkdir(const char *, int);
297 extern int rb_w32_umkdir(const char *, int);
298 extern int rb_w32_rmdir(const char *);
299 extern int rb_w32_urmdir(const char *);
300 extern int rb_w32_unlink(const char *);
301 extern int rb_w32_uunlink(const char *);
302 extern int rb_w32_uchmod(const char *, int);
303 extern int rb_w32_stati64(const char *, struct stati64 *);
304 extern int rb_w32_ustati64(const char *, struct stati64 *);
305 extern int rb_w32_access(const char *, int);
306 extern int rb_w32_uaccess(const char *, int);
307 extern char rb_w32_fd_is_text(int);
308 extern int rb_w32_fstati64(int, struct stati64 *);
309 
310 #ifdef __BORLANDC__
311 extern off_t _lseeki64(int, off_t, int);
312 extern FILE *rb_w32_fopen(const char *, const char *);
313 extern FILE *rb_w32_fdopen(int, const char *);
314 extern FILE *rb_w32_fsopen(const char *, const char *, int);
315 #endif
316 
317 #include <float.h>
318 
319 #if defined _MSC_VER && _MSC_VER >= 1800 && defined INFINITY
320 #pragma warning(push)
321 #pragma warning(disable:4756)
322 static inline float
323 rb_infinity_float(void)
324 {
325  return INFINITY;
326 }
327 #pragma warning(pop)
328 #undef INFINITY
329 #define INFINITY rb_infinity_float()
330 #endif
331 
332 #if !defined __MINGW32__ || defined __NO_ISOCEXT
333 #ifndef isnan
334 #define isnan(x) _isnan(x)
335 #endif
336 static inline int
337 finite(double x)
338 {
339  return _finite(x);
340 }
341 #ifndef copysign
342 #define copysign(a, b) _copysign(a, b)
343 #endif
344 static inline double
345 scalb(double a, long b)
346 {
347  return _scalb(a, b);
348 }
349 #endif
350 
351 #if !defined S_IFIFO && defined _S_IFIFO
352 #define S_IFIFO _S_IFIFO
353 #endif
354 
355 #if 0 && defined __BORLANDC__
356 #undef S_ISDIR
357 #undef S_ISFIFO
358 #undef S_ISBLK
359 #undef S_ISCHR
360 #undef S_ISREG
361 #define S_ISDIR(m) (((unsigned short)(m) & S_IFMT) == S_IFDIR)
362 #define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO)
363 #define S_ISBLK(m) (((unsigned short)(m) & S_IFMT) == S_IFBLK)
364 #define S_ISCHR(m) (((unsigned short)(m) & S_IFMT) == S_IFCHR)
365 #define S_ISREG(m) (((unsigned short)(m) & S_IFMT) == S_IFREG)
366 #endif
367 
368 #if !defined S_IRUSR && !defined __MINGW32__
369 #define S_IRUSR 0400
370 #endif
371 #ifndef S_IRGRP
372 #define S_IRGRP 0040
373 #endif
374 #ifndef S_IROTH
375 #define S_IROTH 0004
376 #endif
377 
378 #if !defined S_IWUSR && !defined __MINGW32__
379 #define S_IWUSR 0200
380 #endif
381 #ifndef S_IWGRP
382 #define S_IWGRP 0020
383 #endif
384 #ifndef S_IWOTH
385 #define S_IWOTH 0002
386 #endif
387 
388 #if !defined S_IXUSR && !defined __MINGW32__
389 #define S_IXUSR 0100
390 #endif
391 #ifndef S_IXGRP
392 #define S_IXGRP 0010
393 #endif
394 #ifndef S_IXOTH
395 #define S_IXOTH 0001
396 #endif
397 
398 //
399 // define this so we can do inplace editing
400 //
401 
402 #define SUFFIX
403 
404 extern int rb_w32_ftruncate(int fd, off_t length);
405 extern int rb_w32_truncate(const char *path, off_t length);
406 extern off_t rb_w32_ftello(FILE *stream);
407 extern int rb_w32_fseeko(FILE *stream, off_t offset, int whence);
408 
409 #undef HAVE_FTRUNCATE
410 #define HAVE_FTRUNCATE 1
411 #if defined HAVE_FTRUNCATE64
412 #define ftruncate ftruncate64
413 #else
414 #define ftruncate rb_w32_ftruncate
415 #endif
416 
417 #undef HAVE_TRUNCATE
418 #define HAVE_TRUNCATE 1
419 #if defined HAVE_TRUNCATE64
420 #define truncate truncate64
421 #else
422 #define truncate rb_w32_truncate
423 #endif
424 
425 #undef HAVE_FSEEKO
426 #define HAVE_FSEEKO 1
427 #if defined HAVE_FSEEKO64
428 #define fseeko fseeko64
429 #else
430 #define fseeko rb_w32_fseeko
431 #endif
432 
433 #undef HAVE_FTELLO
434 #define HAVE_FTELLO 1
435 #if defined HAVE_FTELLO64
436 #define ftello ftello64
437 #else
438 #define ftello rb_w32_ftello
439 #endif
440 
441 //
442 // stubs
443 //
444 extern int ioctl (int, int, ...);
445 extern rb_uid_t getuid (void);
446 extern rb_uid_t geteuid (void);
447 extern rb_gid_t getgid (void);
448 extern rb_gid_t getegid (void);
449 extern int setuid (rb_uid_t);
450 extern int setgid (rb_gid_t);
451 
452 extern char *rb_w32_strerror(int);
453 
454 #ifdef RUBY_EXPORT
455 #define strerror(e) rb_w32_strerror(e)
456 #endif
457 
458 #define PIPE_BUF 1024
459 
460 #define LOCK_SH 1
461 #define LOCK_EX 2
462 #define LOCK_NB 4
463 #define LOCK_UN 8
464 
465 
466 #ifndef SIGINT
467 #define SIGINT 2
468 #endif
469 #ifndef SIGKILL
470 #define SIGKILL 9
471 #endif
472 
473 
474 /* #undef va_start */
475 /* #undef va_end */
476 
477 /* winsock error map */
478 #include <errno.h>
479 
480 #ifndef EWOULDBLOCK
481 # define EWOULDBLOCK WSAEWOULDBLOCK
482 #endif
483 #ifndef EINPROGRESS
484 # define EINPROGRESS WSAEINPROGRESS
485 #endif
486 #ifndef EALREADY
487 # define EALREADY WSAEALREADY
488 #endif
489 #ifndef ENOTSOCK
490 # define ENOTSOCK WSAENOTSOCK
491 #endif
492 #ifndef EDESTADDRREQ
493 # define EDESTADDRREQ WSAEDESTADDRREQ
494 #endif
495 #ifndef EMSGSIZE
496 # define EMSGSIZE WSAEMSGSIZE
497 #endif
498 #ifndef EPROTOTYPE
499 # define EPROTOTYPE WSAEPROTOTYPE
500 #endif
501 #ifndef ENOPROTOOPT
502 # define ENOPROTOOPT WSAENOPROTOOPT
503 #endif
504 #ifndef EPROTONOSUPPORT
505 # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
506 #endif
507 #ifndef ESOCKTNOSUPPORT
508 # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
509 #endif
510 #ifndef EOPNOTSUPP
511 # define EOPNOTSUPP WSAEOPNOTSUPP
512 #endif
513 #ifndef EPFNOSUPPORT
514 # define EPFNOSUPPORT WSAEPFNOSUPPORT
515 #endif
516 #ifndef EAFNOSUPPORT
517 # define EAFNOSUPPORT WSAEAFNOSUPPORT
518 #endif
519 #ifndef EADDRINUSE
520 # define EADDRINUSE WSAEADDRINUSE
521 #endif
522 #ifndef EADDRNOTAVAIL
523 # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
524 #endif
525 #ifndef ENETDOWN
526 # define ENETDOWN WSAENETDOWN
527 #endif
528 #ifndef ENETUNREACH
529 # define ENETUNREACH WSAENETUNREACH
530 #endif
531 #ifndef ENETRESET
532 # define ENETRESET WSAENETRESET
533 #endif
534 #ifndef ECONNABORTED
535 # define ECONNABORTED WSAECONNABORTED
536 #endif
537 #ifndef ECONNRESET
538 # define ECONNRESET WSAECONNRESET
539 #endif
540 #ifndef ENOBUFS
541 # define ENOBUFS WSAENOBUFS
542 #endif
543 #ifndef EISCONN
544 # define EISCONN WSAEISCONN
545 #endif
546 #ifndef ENOTCONN
547 # define ENOTCONN WSAENOTCONN
548 #endif
549 #ifndef ESHUTDOWN
550 # define ESHUTDOWN WSAESHUTDOWN
551 #endif
552 #ifndef ETOOMANYREFS
553 # define ETOOMANYREFS WSAETOOMANYREFS
554 #endif
555 #ifndef ETIMEDOUT
556 # define ETIMEDOUT WSAETIMEDOUT
557 #endif
558 #ifndef ECONNREFUSED
559 # define ECONNREFUSED WSAECONNREFUSED
560 #endif
561 #ifndef ELOOP
562 # define ELOOP WSAELOOP
563 #endif
564 /*#define ENAMETOOLONG WSAENAMETOOLONG*/
565 #ifndef EHOSTDOWN
566 # define EHOSTDOWN WSAEHOSTDOWN
567 #endif
568 #ifndef EHOSTUNREACH
569 # define EHOSTUNREACH WSAEHOSTUNREACH
570 #endif
571 /*#define ENOTEMPTY WSAENOTEMPTY*/
572 #ifndef EPROCLIM
573 # define EPROCLIM WSAEPROCLIM
574 #endif
575 #ifndef EUSERS
576 # define EUSERS WSAEUSERS
577 #endif
578 #ifndef EDQUOT
579 # define EDQUOT WSAEDQUOT
580 #endif
581 #ifndef ESTALE
582 # define ESTALE WSAESTALE
583 #endif
584 #ifndef EREMOTE
585 # define EREMOTE WSAEREMOTE
586 #endif
587 
588 #define F_SETFL 1
589 #define O_NONBLOCK 1
590 
591 #undef FD_SET
592 #define FD_SET(fd, set) do {\
593  unsigned int i;\
594  SOCKET s = _get_osfhandle(fd);\
595 \
596  for (i = 0; i < (set)->fd_count; i++) {\
597  if ((set)->fd_array[i] == s) {\
598  break;\
599  }\
600  }\
601  if (i == (set)->fd_count) {\
602  if ((set)->fd_count < FD_SETSIZE) {\
603  (set)->fd_array[i] = s;\
604  (set)->fd_count++;\
605  }\
606  }\
607 } while(0)
608 
609 #undef FD_CLR
610 #define FD_CLR(f, s) rb_w32_fdclr(f, s)
611 
612 #undef FD_ISSET
613 #define FD_ISSET(f, s) rb_w32_fdisset(f, s)
614 
615 #ifdef RUBY_EXPORT
616 #undef inet_ntop
617 #define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l)
618 
619 #undef accept
620 #define accept(s, a, l) rb_w32_accept(s, a, l)
621 
622 #undef bind
623 #define bind(s, a, l) rb_w32_bind(s, a, l)
624 
625 #undef connect
626 #define connect(s, a, l) rb_w32_connect(s, a, l)
627 
628 #undef select
629 #define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t)
630 
631 #undef getpeername
632 #define getpeername(s, a, l) rb_w32_getpeername(s, a, l)
633 
634 #undef getsockname
635 #define getsockname(s, a, l) rb_w32_getsockname(s, a, l)
636 
637 #undef getsockopt
638 #define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
639 
640 #undef ioctlsocket
641 #define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a)
642 
643 #undef listen
644 #define listen(s, b) rb_w32_listen(s, b)
645 
646 #undef recv
647 #define recv(s, b, l, f) rb_w32_recv(s, b, l, f)
648 
649 #undef recvfrom
650 #define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
651 
652 #undef send
653 #define send(s, b, l, f) rb_w32_send(s, b, l, f)
654 
655 #undef sendto
656 #define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
657 
658 #undef setsockopt
659 #define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
660 
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 socketpair
689 #define socketpair(a, t, p, s) rb_w32_socketpair(a, t, p, s)
690 
691 #undef get_osfhandle
692 #define get_osfhandle(h) rb_w32_get_osfhandle(h)
693 
694 #undef getcwd
695 #define getcwd(b, s) rb_w32_getcwd(b, s)
696 
697 #undef getenv
698 #define getenv(n) rb_w32_getenv(n)
699 
700 #undef rename
701 #define rename(o, n) rb_w32_rename(o, n)
702 
703 #undef times
704 #define times(t) rb_w32_times(t)
705 #endif
706 
707 struct tms {
708  long tms_utime;
709  long tms_stime;
712 };
713 
714 int rb_w32_times(struct tms *);
715 
716 /* thread stuff */
717 HANDLE GetCurrentThreadHandle(void);
718 int rb_w32_sleep(unsigned long msec);
719 int rb_w32_putc(int, FILE*);
720 int rb_w32_getc(FILE*);
721 int rb_w32_open(const char *, int, ...);
722 int rb_w32_uopen(const char *, int, ...);
723 int rb_w32_wopen(const WCHAR *, int, ...);
724 int rb_w32_close(int);
725 int rb_w32_fclose(FILE*);
726 int rb_w32_pipe(int[2]);
727 ssize_t rb_w32_read(int, void *, size_t);
728 ssize_t rb_w32_write(int, const void *, size_t);
729 int rb_w32_utime(const char *, const struct utimbuf *);
730 int rb_w32_uutime(const char *, const struct utimbuf *);
731 long rb_w32_write_console(uintptr_t, int); /* use uintptr_t instead of VALUE because it's not defined yet here */
732 int WINAPI rb_w32_Sleep(unsigned long msec);
733 int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout);
734 int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait);
735 
736 /*
737 == ***CAUTION***
738 Since this function is very dangerous, ((*NEVER*))
739 * lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
740 * use anything like TRAP_BEG...TRAP_END block structure,
741 in asynchronous_func_t.
742 */
745 
746 #if defined __GNUC__ && __GNUC__ >= 4
747 #pragma GCC visibility pop
748 #endif
749 
750 #ifdef __MINGW_ATTRIB_PURE
751 /* get rid of bugs in math.h of mingw */
752 #define frexp(_X, _Y) __extension__ ({\
753  int intpart_frexp_bug = intpart_frexp_bug;\
754  double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\
755  *(_Y) = intpart_frexp_bug;\
756  result_frexp_bug;\
757 })
758 #define modf(_X, _Y) __extension__ ({\
759  double intpart_modf_bug = intpart_modf_bug;\
760  double result_modf_bug = modf((_X), &intpart_modf_bug);\
761  *(_Y) = intpart_modf_bug;\
762  result_modf_bug;\
763 })
764 #endif
765 
766 #if defined(__cplusplus)
767 #if 0
768 { /* satisfy cc-mode */
769 #endif
770 } /* extern "C" { */
771 #endif
772 
773 #ifdef __MINGW64__
774 /*
775  * Use powl() instead of broken pow() of x86_64-w64-mingw32.
776  * This workaround will fix test failures in test_bignum.rb,
777  * test_fixnum.rb and test_float.rb etc.
778  */
779 static inline double
780 rb_w32_pow(double x, double y)
781 {
782  return powl(x, y);
783 }
784 #define pow rb_w32_pow
785 #endif
786 
787 #endif /* RUBY_WIN32_H */
size_t iov_len
Definition: win32.h:221
int gettimeofday(struct timeval *, struct timezone *)
Definition: win32.c:3746
int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout)
int ioctl(int, int,...)
Definition: win32.c:2319
int rb_w32_getc(FILE *)
Definition: win32.c:4633
int msg_iovlen
Definition: win32.h:227
void * iov_base
Definition: win32.h:220
void * msg_control
Definition: win32.h:228
rb_pid_t rb_w32_getppid(void)
Definition: win32.c:4808
rb_uid_t getuid(void)
Definition: win32.c:2279
ssize_t rb_w32_write(int, const void *, size_t)
Definition: win32.c:5358
int rb_w32_fstat(int, struct stat *)
Definition: win32.c:4134
int sendmsg(int, const struct msghdr *, int)
Definition: win32.c:3158
int WSAAPI rb_w32_connect(int, const struct sockaddr *, int)
Definition: win32.c:2823
int WSAAPI rb_w32_bind(int, const struct sockaddr *, int)
Definition: win32.c:2805
int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int)
Definition: win32.c:3058
long tms_stime
Definition: win32.h:709
int msg_namelen
Definition: win32.h:225
int rb_w32_fseeko(FILE *stream, off_t offset, int whence)
Definition: win32.h:223
int rb_w32_ustati64(const char *, struct stati64 *)
Definition: win32.c:4385
SOCKET rb_w32_get_osfhandle(int)
Definition: win32.c:888
void * msg_name
Definition: win32.h:224
int rb_w32_umkdir(const char *, int)
Definition: win32.c:5601
rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int *, int *)
int fcntl(int, int,...)
Definition: win32.c:3579
ssize_t rb_w32_read(int, void *, size_t)
Definition: win32.c:5228
rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD)
Definition: win32.c:1214
int kill(int, int)
Definition: win32.c:3808
int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *)
Definition: win32.c:2878
int rb_w32_urename(const char *, const char *)
Definition: win32.c:4059
int rb_w32_fdisset(int, fd_set *)
Definition: win32.c:2351
struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *)
Definition: win32.c:3405
struct iovec * msg_iov
Definition: win32.h:226
int rb_w32_pipe(int[2])
Definition: win32.c:5068
int rb_w32_open(const char *, int,...)
Definition: win32.c:4857
int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
Definition: win32.c:2748
void rb_w32_free_environ(char **)
Definition: win32.c:4786
int WSAAPI rb_w32_accept(int, struct sockaddr *, int *)
Definition: win32.c:2770
struct protoent *WSAAPI rb_w32_getprotobynumber(int)
Definition: win32.c:3388
rb_pid_t rb_w32_getpid(void)
Definition: win32.c:4795
int rb_w32_uaccess(const char *, int)
Definition: win32.c:4425
int rb_w32_map_errno(DWORD)
Definition: win32.c:213
int recvmsg(int, struct msghdr *, int)
Definition: win32.c:3099
int msg_flags
Definition: win32.h:230
int wait(int *status)
Definition: win32.c:3981
void rb_w32_fdclr(int, fd_set *)
Definition: win32.c:2334
int rb_w32_times(struct tms *)
Definition: win32.c:4587
int WSAAPI rb_w32_socket(int, int, int)
Definition: win32.c:3292
int rb_w32_is_socket(int)
Definition: win32.c:2198
int rb_w32_cmdvector(const char *, char ***)
Definition: win32.c:1410
int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *)
Definition: win32.c:2863
struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int)
Definition: win32.c:3320
rb_gid_t getegid(void)
Definition: win32.c:2297
Definition: file.c:2302
struct hostent *WSAAPI rb_w32_gethostbyname(const char *)
Definition: win32.c:3337
int rb_w32_wopen(const WCHAR *, int,...)
Definition: win32.c:4879
uintptr_t(* asynchronous_func_t)(uintptr_t self, int argc, uintptr_t *argv)
Definition: win32.h:743
IUnknown DWORD
Definition: win32ole.c:149
int WSAAPI rb_w32_send(int, const char *, int, int)
Definition: win32.c:3052
rb_pid_t rb_w32_spawn(int, const char *, const char *)
Definition: win32.c:1112
off_t rb_w32_ftello(FILE *stream)
Definition: win32.c:4569
int WINAPI rb_w32_Sleep(unsigned long msec)
int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *)
Definition: win32.c:3045
int chown(const char *, int, int)
Definition: win32.c:3796
int WSAAPI rb_w32_listen(int, int)
Definition: win32.c:2912
int rb_w32_sleep(unsigned long msec)
int argc
Definition: ruby.c:120
int rb_w32_mkdir(const char *, int)
Definition: win32.c:5614
int rb_w32_uutime(const char *, const struct utimbuf *)
Definition: win32.c:5543
int rb_w32_rmdir(const char *)
Definition: win32.c:5647
int link(const char *, const char *)
Definition: win32.c:3962
int rb_w32_putc(int, FILE *)
Definition: win32.c:4653
int rb_w32_fstati64(int, struct stati64 *)
Definition: win32.c:4157
int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait)
Definition: win32.c:2569
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
int rb_w32_unlink(const char *)
Definition: win32.c:5706
#define off_t
Definition: io.c:57
int rb_w32_truncate(const char *path, off_t length)
Definition: win32.c:4470
int rb_w32_urmdir(const char *)
Definition: win32.c:5660
char ** rb_w32_get_environ(void)
Definition: win32.c:4751
int setgid(rb_gid_t)
Definition: win32.c:2309
unsigned int uintptr_t
Definition: win32.h:96
int rb_w32_uopen(const char *, int,...)
Definition: win32.c:4838
int rb_w32_stati64(const char *, struct stati64 *)
Definition: win32.c:4398
rb_uid_t geteuid(void)
Definition: win32.c:2285
int rb_w32_uchmod(const char *, int)
Definition: win32.c:5719
char * rb_w32_getenv(const char *)
Definition: win32.c:3987
int intptr_t
Definition: win32.h:88
Definition: win32.h:219
struct protoent *WSAAPI rb_w32_getprotobyname(const char *)
Definition: win32.c:3371
#define INFINITY
Definition: missing.h:130
char *WSAAPI rb_w32_inet_ntop(int, void *, char *, size_t)
Definition: win32.c:5825
long tms_utime
Definition: win32.h:708
int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int)
Definition: win32.c:3211
HANDLE GetCurrentThreadHandle(void)
Definition: win32.c:270
int rb_w32_access(const char *, int)
Definition: win32.c:4411
rb_pid_t rb_w32_aspawn(int, const char *, char *const *)
Definition: win32.c:1280
long tms_cstime
Definition: win32.h:711
Definition: win32.h:707
int rb_w32_isatty(int)
Definition: win32.c:5733
int rb_w32_uchdir(const char *)
Definition: win32.c:5569
int rb_w32_ulink(const char *, const char *)
Definition: win32.c:3943
long rb_w32_write_console(uintptr_t, int)
Definition: win32.c:5458
char * rb_w32_strerror(int)
Definition: win32.c:2212
int WSAAPI rb_w32_ioctlsocket(int, long, u_long *)
Definition: win32.c:2895
DWORD rb_w32_osver(void)
Definition: win32.c:256
struct servent *WSAAPI rb_w32_getservbyport(int, const char *)
Definition: win32.c:3422
int WSAAPI rb_w32_gethostname(char *, int)
Definition: win32.c:3354
int rb_w32_ftruncate(int fd, off_t length)
Definition: win32.c:4496
void rb_w32_fdset(int, fd_set *)
Definition: win32.c:2326
int WSAAPI rb_w32_shutdown(int, int)
Definition: win32.c:3228
int flock(int fd, int oper)
Definition: flock.c:124
int rb_w32_close(int)
Definition: win32.c:5160
int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *)
Definition: win32.c:2846
char * rb_w32_getcwd(char *, int)
Definition: win32.c:3757
#define u_long
Definition: vsnprintf.c:64
static double scalb(double a, long b)
Definition: win32.h:345
int msg_controllen
Definition: win32.h:229
rb_gid_t getgid(void)
Definition: win32.c:2291
int rb_w32_fclose(FILE *)
Definition: win32.c:5046
static int finite(double x)
Definition: win32.h:337
char rb_w32_fd_is_text(int)
Definition: win32.c:5841
long tms_cutime
Definition: win32.h:710
#define stat(path, st)
Definition: win32.h:201
int rb_w32_socketpair(int, int, int, int *)
Definition: win32.c:3527
int WSAAPI rb_w32_recv(int, char *, int, int)
Definition: win32.c:3039
int rb_w32_io_cancelable_p(int)
Definition: win32.c:2090
int setuid(rb_uid_t)
Definition: win32.c:2303
uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t *argv, uintptr_t intrval)
Definition: win32.c:4689
int rb_w32_uunlink(const char *)
Definition: win32.c:5693
int rb_w32_stat(const char *, struct stat *)
Definition: win32.c:4327
int rb_w32_utime(const char *, const struct utimbuf *)
Definition: win32.c:5556
rb_pid_t waitpid(rb_pid_t, int *, int)
Definition: win32.c:3662
int rb_w32_uchown(const char *, int, int)
Definition: win32.c:3802
int rb_w32_rename(const char *, const char *)
Definition: win32.c:4077
char ** argv
Definition: ruby.c:121