Ruby 2.0.0p247(2013-06-27revision41674)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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 /*
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
63 extern "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__ || __BORLANDC__ >= 0x0580
80 # include <stdint.h>
81 #else
82 # if !defined(_INTPTR_T_DEFINED)
83 # ifdef _WIN64
84 typedef __int64 intptr_t;
85 # else
86 typedef int intptr_t;
87 # endif
88 # define _INTPTR_T_DEFINED
89 # endif
90 # if !defined(_UINTPTR_T_DEFINED)
91 # ifdef _WIN64
92 typedef unsigned __int64 uintptr_t;
93 # else
94 typedef unsigned int uintptr_t;
95 # endif
96 # define _UINTPTR_T_DEFINED
97 # endif
98 #endif
99 #ifndef __MINGW32__
100 # define mode_t int
101 #endif
102 #ifdef HAVE_UNISTD_H
103 # include <unistd.h>
104 #endif
105
106 #define rb_w32_iswinnt() TRUE
107 #define rb_w32_iswin95() FALSE
108
109 #define WNOHANG -1
110
111 #undef getc
112 #undef putc
113 #undef fgetc
114 #undef fputc
115 #undef getchar
116 #undef putchar
117 #undef fgetchar
118 #undef fputchar
119 #undef utime
120 #undef lseek
121 #undef stat
122 #undef fstat
123 #define getc(_stream) rb_w32_getc(_stream)
124 #define getchar() rb_w32_getc(stdin)
125 #define putc(_c, _stream) rb_w32_putc(_c, _stream)
126 #define putchar(_c) rb_w32_putc(_c, stdout)
127 #ifdef RUBY_EXPORT
128 #define fgetc(_stream) getc(_stream)
129 #define fputc(_c, _stream) putc(_c, _stream)
130 #define fgetchar() getchar()
131 #define fputchar(_c) putchar(_c)
132 #define utime(_p, _t) rb_w32_utime(_p, _t)
133 #define lseek(_f, _o, _w) _lseeki64(_f, _o, _w)
134
135 #define pipe(p) rb_w32_pipe(p)
136 #define open rb_w32_open
137 #define close(h) rb_w32_close(h)
138 #define fclose(f) rb_w32_fclose(f)
139 #define read(f, b, s) rb_w32_read(f, b, s)
140 #define write(f, b, s) rb_w32_write(f, b, s)
141 #define getpid() rb_w32_getpid()
142 #define getppid() rb_w32_getppid()
143 #define sleep(x) rb_w32_Sleep((x)*1000)
144 #define Sleep(msec) (void)rb_w32_Sleep(msec)
145 #define fstati64(fd,st) rb_w32_fstati64(fd,st)
146 #ifdef __BORLANDC__
147 #define creat(p, m) _creat(p, m)
148 #define eof() _eof()
149 #define filelength(h) _filelength(h)
150 #define mktemp(t) _mktemp(t)
151 #define tell(h) _tell(h)
152 #define _open _sopen
153 #define sopen _sopen
154 #undef fopen
155 #define fopen(p, m) rb_w32_fopen(p, m)
156 #undef fdopen
157 #define fdopen(h, m) rb_w32_fdopen(h, m)
158 #undef fsopen
159 #define fsopen(p, m, sh) rb_w32_fsopen(p, m, sh)
160 #endif /* __BORLANDC__ */
161
162 #undef execv
163 #define execv(path,argv) rb_w32_aspawn(P_OVERLAY,path,argv)
164 #if !defined(__BORLANDC__)
165 #undef isatty
166 #define isatty(h) rb_w32_isatty(h)
167 #endif /* __BORLANDC__ */
168
169 #undef mkdir
170 #define mkdir(p, m) rb_w32_mkdir(p, m)
171 #undef rmdir
172 #define rmdir(p) rb_w32_rmdir(p)
173 #undef unlink
174 #define unlink(p) rb_w32_unlink(p)
175 #endif /* RUBY_EXPORT */
176
177 #if SIZEOF_OFF_T == 8
178 #define off_t __int64
179 #define stat stati64
180 #define fstat(fd,st) fstati64(fd,st)
181 #if defined(__BORLANDC__)
182 #define stati64(path, st) rb_w32_stati64(path, st)
183 #elif !defined(_MSC_VER) || RT_VER < 80
184 #define stati64 _stati64
185 #ifndef _stati64
186 #define _stati64(path, st) rb_w32_stati64(path, st)
187 #endif
188 #else
189 #define stati64 _stat64
190 #define _stat64(path, st) rb_w32_stati64(path, st)
191 #endif
192 #else
193 #define stat(path,st) rb_w32_stat(path,st)
194 #define fstat(fd,st) rb_w32_fstat(fd,st)
195 extern int rb_w32_stat(const char *, struct stat *);
196 extern int rb_w32_fstat(int, struct stat *);
197 #endif
198 #define access(path,mode) rb_w32_access(path,mode)
199
200 #define strcasecmp _stricmp
201 #define strncasecmp _strnicmp
202 #define fsync _commit
203
204 struct timezone;
205
206 #ifdef __MINGW32__
207 #undef isascii
208 #define isascii __isascii
209 #endif
210
211 struct iovec {
212 void *iov_base;
213 size_t iov_len;
214 };
215 struct msghdr {
216 void *msg_name;
217 int msg_namelen;
218 struct iovec *msg_iov;
219 int msg_iovlen;
220 void *msg_control;
221 int msg_controllen;
222 int msg_flags;
223 };
224
225 extern DWORD rb_w32_osid(void);
226 extern int rb_w32_cmdvector(const char *, char ***);
227 extern rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int *, int *);
228 extern int flock(int fd, int oper);
229 extern int rb_w32_io_cancelable_p(int);
230 extern int rb_w32_is_socket(int);
231 extern int WSAAPI rb_w32_accept(int, struct sockaddr *, int *);
232 extern int WSAAPI rb_w32_bind(int, const struct sockaddr *, int);
233 extern int WSAAPI rb_w32_connect(int, const struct sockaddr *, int);
234 extern void rb_w32_fdset(int, fd_set*);
235 extern void rb_w32_fdclr(int, fd_set*);
236 extern int rb_w32_fdisset(int, fd_set*);
237 extern int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
238 extern int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *);
239 extern int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *);
240 extern int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *);
241 extern int WSAAPI rb_w32_ioctlsocket(int, long, u_long *);
242 extern int WSAAPI rb_w32_listen(int, int);
243 extern int WSAAPI rb_w32_recv(int, char *, int, int);
244 extern int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *);
245 extern int WSAAPI rb_w32_send(int, const char *, int, int);
246 extern int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int);
247 extern int recvmsg(int, struct msghdr *, int);
248 extern int sendmsg(int, const struct msghdr *, int);
249 extern int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int);
250 extern int WSAAPI rb_w32_shutdown(int, int);
251 extern int WSAAPI rb_w32_socket(int, int, int);
252 extern SOCKET rb_w32_get_osfhandle(int);
253 extern struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int);
254 extern struct hostent *WSAAPI rb_w32_gethostbyname(const char *);
255 extern int WSAAPI rb_w32_gethostname(char *, int);
256 extern struct protoent *WSAAPI rb_w32_getprotobyname(const char *);
257 extern struct protoent *WSAAPI rb_w32_getprotobynumber(int);
258 extern struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *);
259 extern struct servent *WSAAPI rb_w32_getservbyport(int, const char *);
260 extern int rb_w32_socketpair(int, int, int, int *);
261 extern char * rb_w32_getcwd(char *, int);
262 extern char * rb_w32_ugetenv(const char *);
263 extern char * rb_w32_getenv(const char *);
264 extern int rb_w32_rename(const char *, const char *);
265 extern int rb_w32_urename(const char *, const char *);
266 extern char **rb_w32_get_environ(void);
267 extern void rb_w32_free_environ(char **);
268 extern int rb_w32_map_errno(DWORD);
269 extern const char *WSAAPI rb_w32_inet_ntop(int,const void *,char *,size_t);
270 extern DWORD rb_w32_osver(void);
271
272 extern int chown(const char *, int, int);
273 extern int rb_w32_uchown(const char *, int, int);
274 extern int link(const char *, const char *);
275 extern int rb_w32_ulink(const char *, const char *);
276 extern int gettimeofday(struct timeval *, struct timezone *);
277 extern rb_pid_t waitpid (rb_pid_t, int *, int);
278 extern rb_pid_t rb_w32_spawn(int, const char *, const char*);
279 extern rb_pid_t rb_w32_aspawn(int, const char *, char *const *);
280 extern rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD);
281 extern int kill(int, int);
282 extern int fcntl(int, int, ...);
283 extern rb_pid_t rb_w32_getpid(void);
284 extern rb_pid_t rb_w32_getppid(void);
285 #if !defined(__BORLANDC__)
286 extern int rb_w32_isatty(int);
287 #endif
288 extern int rb_w32_uchdir(const char *);
289 extern int rb_w32_mkdir(const char *, int);
290 extern int rb_w32_umkdir(const char *, int);
291 extern int rb_w32_rmdir(const char *);
292 extern int rb_w32_urmdir(const char *);
293 extern int rb_w32_unlink(const char *);
294 extern int rb_w32_uunlink(const char *);
295 extern int rb_w32_uchmod(const char *, int);
296 extern int rb_w32_stati64(const char *, struct stati64 *);
297 extern int rb_w32_ustati64(const char *, struct stati64 *);
298 extern int rb_w32_access(const char *, int);
299 extern int rb_w32_uaccess(const char *, int);
300 extern char rb_w32_fd_is_text(int);
301 extern int rb_w32_fstati64(int, struct stati64 *);
302
303 #ifdef __BORLANDC__
304 extern off_t _lseeki64(int, off_t, int);
305 extern FILE *rb_w32_fopen(const char *, const char *);
306 extern FILE *rb_w32_fdopen(int, const char *);
307 extern FILE *rb_w32_fsopen(const char *, const char *, int);
308 #endif
309
310 #include <float.h>
311 #if !defined __MINGW32__ || defined __NO_ISOCEXT
312 #ifndef isnan
313 #define isnan(x) _isnan(x)
314 #endif
315 static inline int
316 finite(double x)
317 {
318 return _finite(x);
319 }
320 #ifndef copysign
321 #define copysign(a, b) _copysign(a, b)
322 #endif
323 static inline double
324 scalb(double a, long b)
325 {
326 return _scalb(a, b);
327 }
328 #endif
329
330 #if !defined S_IFIFO && defined _S_IFIFO
331 #define S_IFIFO _S_IFIFO
332 #endif
333
334 #if 0 && defined __BORLANDC__
335 #undef S_ISDIR
336 #undef S_ISFIFO
337 #undef S_ISBLK
338 #undef S_ISCHR
339 #undef S_ISREG
340 #define S_ISDIR(m) (((unsigned short)(m) & S_IFMT) == S_IFDIR)
341 #define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO)
342 #define S_ISBLK(m) (((unsigned short)(m) & S_IFMT) == S_IFBLK)
343 #define S_ISCHR(m) (((unsigned short)(m) & S_IFMT) == S_IFCHR)
344 #define S_ISREG(m) (((unsigned short)(m) & S_IFMT) == S_IFREG)
345 #endif
346
347 #if !defined S_IRUSR && !defined __MINGW32__
348 #define S_IRUSR 0400
349 #endif
350 #ifndef S_IRGRP
351 #define S_IRGRP 0040
352 #endif
353 #ifndef S_IROTH
354 #define S_IROTH 0004
355 #endif
356
357 #if !defined S_IWUSR && !defined __MINGW32__
358 #define S_IWUSR 0200
359 #endif
360 #ifndef S_IWGRP
361 #define S_IWGRP 0020
362 #endif
363 #ifndef S_IWOTH
364 #define S_IWOTH 0002
365 #endif
366
367 #if !defined S_IXUSR && !defined __MINGW32__
368 #define S_IXUSR 0100
369 #endif
370 #ifndef S_IXGRP
371 #define S_IXGRP 0010
372 #endif
373 #ifndef S_IXOTH
374 #define S_IXOTH 0001
375 #endif
376
377 /*
378 * define this so we can do inplace editing
379 */
380
381 #define SUFFIX
382
383 extern int rb_w32_ftruncate(int fd, off_t length);
384 extern int rb_w32_truncate(const char *path, off_t length);
385 extern off_t rb_w32_ftello(FILE *stream);
386 extern int rb_w32_fseeko(FILE *stream, off_t offset, int whence);
387
388 #undef HAVE_FTRUNCATE
389 #define HAVE_FTRUNCATE 1
390 #if defined HAVE_FTRUNCATE64
391 #define ftruncate ftruncate64
392 #else
393 #define ftruncate rb_w32_ftruncate
394 #endif
395
396 #undef HAVE_TRUNCATE
397 #define HAVE_TRUNCATE 1
398 #if defined HAVE_TRUNCATE64
399 #define truncate truncate64
400 #else
401 #define truncate rb_w32_truncate
402 #endif
403
404 #undef HAVE_FSEEKO
405 #define HAVE_FSEEKO 1
406 #if defined HAVE_FSEEKO64
407 #define fseeko fseeko64
408 #else
409 #define fseeko rb_w32_fseeko
410 #endif
411
412 #undef HAVE_FTELLO
413 #define HAVE_FTELLO 1
414 #if defined HAVE_FTELLO64
415 #define ftello ftello64
416 #else
417 #define ftello rb_w32_ftello
418 #endif
419
420 /*
421 * stubs
422 */
423 extern int ioctl (int, int, ...);
424 extern rb_uid_t getuid (void);
425 extern rb_uid_t geteuid (void);
426 extern rb_gid_t getgid (void);
427 extern rb_gid_t getegid (void);
428 extern int setuid (rb_uid_t);
429 extern int setgid (rb_gid_t);
430
431 extern char *rb_w32_strerror(int);
432
433 #ifdef RUBY_EXPORT
434 #define strerror(e) rb_w32_strerror(e)
435 #endif
436
437 #define PIPE_BUF 1024
438
439 #define LOCK_SH 1
440 #define LOCK_EX 2
441 #define LOCK_NB 4
442 #define LOCK_UN 8
443
444
445 #ifndef SIGINT
446 #define SIGINT 2
447 #endif
448 #ifndef SIGKILL
449 #define SIGKILL 9
450 #endif
451
452
453 /* #undef va_start */
454 /* #undef va_end */
455
456 /* winsock error map */
457 #include <errno.h>
458
459 #ifndef EWOULDBLOCK
460 # define EWOULDBLOCK WSAEWOULDBLOCK
461 #endif
462 #ifndef EINPROGRESS
463 # define EINPROGRESS WSAEINPROGRESS
464 #endif
465 #ifndef EALREADY
466 # define EALREADY WSAEALREADY
467 #endif
468 #ifndef ENOTSOCK
469 # define ENOTSOCK WSAENOTSOCK
470 #endif
471 #ifndef EDESTADDRREQ
472 # define EDESTADDRREQ WSAEDESTADDRREQ
473 #endif
474 #ifndef EMSGSIZE
475 # define EMSGSIZE WSAEMSGSIZE
476 #endif
477 #ifndef EPROTOTYPE
478 # define EPROTOTYPE WSAEPROTOTYPE
479 #endif
480 #ifndef ENOPROTOOPT
481 # define ENOPROTOOPT WSAENOPROTOOPT
482 #endif
483 #ifndef EPROTONOSUPPORT
484 # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
485 #endif
486 #ifndef ESOCKTNOSUPPORT
487 # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
488 #endif
489 #ifndef EOPNOTSUPP
490 # define EOPNOTSUPP WSAEOPNOTSUPP
491 #endif
492 #ifndef EPFNOSUPPORT
493 # define EPFNOSUPPORT WSAEPFNOSUPPORT
494 #endif
495 #ifndef EAFNOSUPPORT
496 # define EAFNOSUPPORT WSAEAFNOSUPPORT
497 #endif
498 #ifndef EADDRINUSE
499 # define EADDRINUSE WSAEADDRINUSE
500 #endif
501 #ifndef EADDRNOTAVAIL
502 # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
503 #endif
504 #ifndef ENETDOWN
505 # define ENETDOWN WSAENETDOWN
506 #endif
507 #ifndef ENETUNREACH
508 # define ENETUNREACH WSAENETUNREACH
509 #endif
510 #ifndef ENETRESET
511 # define ENETRESET WSAENETRESET
512 #endif
513 #ifndef ECONNABORTED
514 # define ECONNABORTED WSAECONNABORTED
515 #endif
516 #ifndef ECONNRESET
517 # define ECONNRESET WSAECONNRESET
518 #endif
519 #ifndef ENOBUFS
520 # define ENOBUFS WSAENOBUFS
521 #endif
522 #ifndef EISCONN
523 # define EISCONN WSAEISCONN
524 #endif
525 #ifndef ENOTCONN
526 # define ENOTCONN WSAENOTCONN
527 #endif
528 #ifndef ESHUTDOWN
529 # define ESHUTDOWN WSAESHUTDOWN
530 #endif
531 #ifndef ETOOMANYREFS
532 # define ETOOMANYREFS WSAETOOMANYREFS
533 #endif
534 #ifndef ETIMEDOUT
535 # define ETIMEDOUT WSAETIMEDOUT
536 #endif
537 #ifndef ECONNREFUSED
538 # define ECONNREFUSED WSAECONNREFUSED
539 #endif
540 #ifndef ELOOP
541 # define ELOOP WSAELOOP
542 #endif
543 /*#define ENAMETOOLONG WSAENAMETOOLONG*/
544 #ifndef EHOSTDOWN
545 # define EHOSTDOWN WSAEHOSTDOWN
546 #endif
547 #ifndef EHOSTUNREACH
548 # define EHOSTUNREACH WSAEHOSTUNREACH
549 #endif
550 /*#define ENOTEMPTY WSAENOTEMPTY*/
551 #ifndef EPROCLIM
552 # define EPROCLIM WSAEPROCLIM
553 #endif
554 #ifndef EUSERS
555 # define EUSERS WSAEUSERS
556 #endif
557 #ifndef EDQUOT
558 # define EDQUOT WSAEDQUOT
559 #endif
560 #ifndef ESTALE
561 # define ESTALE WSAESTALE
562 #endif
563 #ifndef EREMOTE
564 # define EREMOTE WSAEREMOTE
565 #endif
566
567 #define F_DUPFD 0
568 #if 0
569 #define F_GETFD 1
570 #define F_SETFD 2
571 #define F_GETFL 3
572 #endif
573 #define F_SETFL 4
574 #if 0
575 #define FD_CLOEXEC 1 /* F_GETFD, F_SETFD */
576 #endif
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 accept
608 #define accept(s, a, l) rb_w32_accept(s, a, l)
609
610 #undef bind
611 #define bind(s, a, l) rb_w32_bind(s, a, l)
612
613 #undef connect
614 #define connect(s, a, l) rb_w32_connect(s, a, l)
615
616 #undef select
617 #define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t)
618
619 #undef getpeername
620 #define getpeername(s, a, l) rb_w32_getpeername(s, a, l)
621
622 #undef getsockname
623 #define getsockname(s, a, l) rb_w32_getsockname(s, a, l)
624
625 #undef getsockopt
626 #define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
627
628 #undef ioctlsocket
629 #define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a)
630
631 #undef listen
632 #define listen(s, b) rb_w32_listen(s, b)
633
634 #undef recv
635 #define recv(s, b, l, f) rb_w32_recv(s, b, l, f)
636
637 #undef recvfrom
638 #define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
639
640 #undef send
641 #define send(s, b, l, f) rb_w32_send(s, b, l, f)
642
643 #undef sendto
644 #define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
645
646 #undef setsockopt
647 #define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
648
649 #undef shutdown
650 #define shutdown(s, h) rb_w32_shutdown(s, h)
651
652 #undef socket
653 #define socket(s, t, p) rb_w32_socket(s, t, p)
654
655 #undef gethostbyaddr
656 #define gethostbyaddr(a, l, t) rb_w32_gethostbyaddr(a, l, t)
657
658 #undef gethostbyname
659 #define gethostbyname(n) rb_w32_gethostbyname(n)
660
661 #undef gethostname
662 #define gethostname(n, l) rb_w32_gethostname(n, l)
663
664 #undef getprotobyname
665 #define getprotobyname(n) rb_w32_getprotobyname(n)
666
667 #undef getprotobynumber
668 #define getprotobynumber(n) rb_w32_getprotobynumber(n)
669
670 #undef getservbyname
671 #define getservbyname(n, p) rb_w32_getservbyname(n, p)
672
673 #undef getservbyport
674 #define getservbyport(p, pr) rb_w32_getservbyport(p, pr)
675
676 #undef socketpair
677 #define socketpair(a, t, p, s) rb_w32_socketpair(a, t, p, s)
678
679 #undef get_osfhandle
680 #define get_osfhandle(h) rb_w32_get_osfhandle(h)
681
682 #undef getcwd
683 #define getcwd(b, s) rb_w32_getcwd(b, s)
684
685 #undef getenv
686 #define getenv(n) rb_w32_getenv(n)
687
688 #undef rename
689 #define rename(o, n) rb_w32_rename(o, n)
690
691 #undef times
692 #define times(t) rb_w32_times(t)
693 #endif
694
695 struct tms {
696 long tms_utime;
697 long tms_stime;
698 long tms_cutime;
699 long tms_cstime;
700 };
701
702 int rb_w32_times(struct tms *);
703
704 struct tm *gmtime_r(const time_t *, struct tm *);
705 struct tm *localtime_r(const time_t *, struct tm *);
706
707 /* thread stuff */
708 int rb_w32_sleep(unsigned long msec);
709 int rb_w32_putc(int, FILE*);
710 int rb_w32_getc(FILE*);
711 int rb_w32_open(const char *, int, ...);
712 int rb_w32_uopen(const char *, int, ...);
713 int rb_w32_wopen(const WCHAR *, int, ...);
714 int rb_w32_close(int);
715 int rb_w32_fclose(FILE*);
716 int rb_w32_pipe(int[2]);
717 ssize_t rb_w32_read(int, void *, size_t);
718 ssize_t rb_w32_write(int, const void *, size_t);
719 int rb_w32_utime(const char *, const struct utimbuf *);
720 int rb_w32_uutime(const char *, const struct utimbuf *);
721 long rb_w32_write_console(uintptr_t, int); /* use uintptr_t instead of VALUE because it's not defined yet here */
722 int WINAPI rb_w32_Sleep(unsigned long msec);
723 int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout);
724 int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait);
725 int rb_w32_wrap_io_handle(HANDLE, int);
726 int rb_w32_unwrap_io_handle(int);
727
728 /*
729 == ***CAUTION***
730 Since this function is very dangerous, ((*NEVER*))
731 * lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
732 * use anything like TRAP_BEG...TRAP_END block structure,
733 in asynchronous_func_t.
734 */
735 typedef uintptr_t (*asynchronous_func_t)(uintptr_t self, int argc, uintptr_t* argv);
736 uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t* argv, uintptr_t intrval);
737
738 #if defined __GNUC__ && __GNUC__ >= 4
739 #pragma GCC visibility pop
740 #endif
741
742 #ifdef __MINGW_ATTRIB_PURE
743 /* License: Ruby's */
744 /* get rid of bugs in math.h of mingw */
745 #define frexp(_X, _Y) __extension__ ({\
746 int intpart_frexp_bug = intpart_frexp_bug;\
747 double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\
748 *(_Y) = intpart_frexp_bug;\
749 result_frexp_bug;\
750 })
751 /* License: Ruby's */
752 #define modf(_X, _Y) __extension__ ({\
753 double intpart_modf_bug = intpart_modf_bug;\
754 double result_modf_bug = modf((_X), &intpart_modf_bug);\
755 *(_Y) = intpart_modf_bug;\
756 result_modf_bug;\
757 })
758 #endif
759
760 #if defined(__cplusplus)
761 #if 0
762 { /* satisfy cc-mode */
763 #endif
764 } /* extern "C" { */
765 #endif
766
767 #if defined(__MINGW64__)
768 /*
769 * Use powl() instead of broken pow() of x86_64-w64-mingw32.
770 * This workaround will fix test failures in test_bignum.rb,
771 * test_fixnum.rb and test_float.rb etc.
772 */
773 static inline double
774 rb_w32_pow(double x, double y)
775 {
776 return powl(x, y);
777 }
778 #elif defined(__MINGW64_VERSION_MAJOR)
779 /*
780 * Set floating point precision for pow() of mingw-w64 x86.
781 * With default precision the result is not proper on WinXP.
782 */
783 static inline double
784 rb_w32_pow(double x, double y)
785 {
786 double r;
787 unsigned int default_control = _controlfp(0, 0);
788 _controlfp(_PC_64, _MCW_PC);
789 r = pow(x, y);
790 /* Restore setting */
791 _controlfp(default_control, _MCW_PC);
792 return r;
793 }
794 #endif
795 #if defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW64__)
796 #define pow rb_w32_pow
797 #endif
798
799 #endif /* RUBY_WIN32_H */
800