Ruby  2.0.0p451(2014-02-24revision45167)
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;
218  struct iovec *msg_iov;
220  void *msg_control;
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 
312 #if defined _MSC_VER && _MSC_VER >= 1800 && defined INFINITY
313 #pragma warning(push)
314 #pragma warning(disable:4756)
315 static inline float
316 rb_infinity_float(void)
317 {
318  return INFINITY;
319 }
320 #pragma warning(pop)
321 #undef INFINITY
322 #define INFINITY rb_infinity_float()
323 #endif
324 
325 #if !defined __MINGW32__ || defined __NO_ISOCEXT
326 #ifndef isnan
327 #define isnan(x) _isnan(x)
328 #endif
329 static inline int
330 finite(double x)
331 {
332  return _finite(x);
333 }
334 #ifndef copysign
335 #define copysign(a, b) _copysign(a, b)
336 #endif
337 static inline double
338 scalb(double a, long b)
339 {
340  return _scalb(a, b);
341 }
342 #endif
343 
344 #if !defined S_IFIFO && defined _S_IFIFO
345 #define S_IFIFO _S_IFIFO
346 #endif
347 
348 #if 0 && defined __BORLANDC__
349 #undef S_ISDIR
350 #undef S_ISFIFO
351 #undef S_ISBLK
352 #undef S_ISCHR
353 #undef S_ISREG
354 #define S_ISDIR(m) (((unsigned short)(m) & S_IFMT) == S_IFDIR)
355 #define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO)
356 #define S_ISBLK(m) (((unsigned short)(m) & S_IFMT) == S_IFBLK)
357 #define S_ISCHR(m) (((unsigned short)(m) & S_IFMT) == S_IFCHR)
358 #define S_ISREG(m) (((unsigned short)(m) & S_IFMT) == S_IFREG)
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 /*
392  * define this so we can do inplace editing
393  */
394 
395 #define SUFFIX
396 
397 extern int rb_w32_ftruncate(int fd, off_t length);
398 extern int rb_w32_truncate(const char *path, off_t length);
399 extern off_t rb_w32_ftello(FILE *stream);
400 extern int rb_w32_fseeko(FILE *stream, off_t offset, int whence);
401 
402 #undef HAVE_FTRUNCATE
403 #define HAVE_FTRUNCATE 1
404 #if defined HAVE_FTRUNCATE64
405 #define ftruncate ftruncate64
406 #else
407 #define ftruncate rb_w32_ftruncate
408 #endif
409 
410 #undef HAVE_TRUNCATE
411 #define HAVE_TRUNCATE 1
412 #if defined HAVE_TRUNCATE64
413 #define truncate truncate64
414 #else
415 #define truncate rb_w32_truncate
416 #endif
417 
418 #undef HAVE_FSEEKO
419 #define HAVE_FSEEKO 1
420 #if defined HAVE_FSEEKO64
421 #define fseeko fseeko64
422 #else
423 #define fseeko rb_w32_fseeko
424 #endif
425 
426 #undef HAVE_FTELLO
427 #define HAVE_FTELLO 1
428 #if defined HAVE_FTELLO64
429 #define ftello ftello64
430 #else
431 #define ftello rb_w32_ftello
432 #endif
433 
434 /*
435  * stubs
436  */
437 extern int ioctl (int, int, ...);
438 extern rb_uid_t getuid (void);
439 extern rb_uid_t geteuid (void);
440 extern rb_gid_t getgid (void);
441 extern rb_gid_t getegid (void);
442 extern int setuid (rb_uid_t);
443 extern int setgid (rb_gid_t);
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 #if 0
583 #define F_GETFD 1
584 #define F_SETFD 2
585 #define F_GETFL 3
586 #endif
587 #define F_SETFL 4
588 #if 0
589 #define FD_CLOEXEC 1 /* F_GETFD, F_SETFD */
590 #endif
591 #define O_NONBLOCK 1
592 
593 #undef FD_SET
594 #define FD_SET(fd, set) do {\
595  unsigned int i;\
596  SOCKET s = _get_osfhandle(fd);\
597 \
598  for (i = 0; i < (set)->fd_count; i++) {\
599  if ((set)->fd_array[i] == s) {\
600  break;\
601  }\
602  }\
603  if (i == (set)->fd_count) {\
604  if ((set)->fd_count < FD_SETSIZE) {\
605  (set)->fd_array[i] = s;\
606  (set)->fd_count++;\
607  }\
608  }\
609 } while(0)
610 
611 #undef FD_CLR
612 #define FD_CLR(f, s) rb_w32_fdclr(f, s)
613 
614 #undef FD_ISSET
615 #define FD_ISSET(f, s) rb_w32_fdisset(f, s)
616 
617 #ifdef RUBY_EXPORT
618 #undef inet_ntop
619 #define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l)
620 
621 #undef accept
622 #define accept(s, a, l) rb_w32_accept(s, a, l)
623 
624 #undef bind
625 #define bind(s, a, l) rb_w32_bind(s, a, l)
626 
627 #undef connect
628 #define connect(s, a, l) rb_w32_connect(s, a, l)
629 
630 #undef select
631 #define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t)
632 
633 #undef getpeername
634 #define getpeername(s, a, l) rb_w32_getpeername(s, a, l)
635 
636 #undef getsockname
637 #define getsockname(s, a, l) rb_w32_getsockname(s, a, l)
638 
639 #undef getsockopt
640 #define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
641 
642 #undef ioctlsocket
643 #define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a)
644 
645 #undef listen
646 #define listen(s, b) rb_w32_listen(s, b)
647 
648 #undef recv
649 #define recv(s, b, l, f) rb_w32_recv(s, b, l, f)
650 
651 #undef recvfrom
652 #define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
653 
654 #undef send
655 #define send(s, b, l, f) rb_w32_send(s, b, l, f)
656 
657 #undef sendto
658 #define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
659 
660 #undef setsockopt
661 #define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
662 
663 #undef shutdown
664 #define shutdown(s, h) rb_w32_shutdown(s, h)
665 
666 #undef socket
667 #define socket(s, t, p) rb_w32_socket(s, t, p)
668 
669 #undef gethostbyaddr
670 #define gethostbyaddr(a, l, t) rb_w32_gethostbyaddr(a, l, t)
671 
672 #undef gethostbyname
673 #define gethostbyname(n) rb_w32_gethostbyname(n)
674 
675 #undef gethostname
676 #define gethostname(n, l) rb_w32_gethostname(n, l)
677 
678 #undef getprotobyname
679 #define getprotobyname(n) rb_w32_getprotobyname(n)
680 
681 #undef getprotobynumber
682 #define getprotobynumber(n) rb_w32_getprotobynumber(n)
683 
684 #undef getservbyname
685 #define getservbyname(n, p) rb_w32_getservbyname(n, p)
686 
687 #undef getservbyport
688 #define getservbyport(p, pr) rb_w32_getservbyport(p, pr)
689 
690 #undef socketpair
691 #define socketpair(a, t, p, s) rb_w32_socketpair(a, t, p, s)
692 
693 #undef get_osfhandle
694 #define get_osfhandle(h) rb_w32_get_osfhandle(h)
695 
696 #undef getcwd
697 #define getcwd(b, s) rb_w32_getcwd(b, s)
698 
699 #undef getenv
700 #define getenv(n) rb_w32_getenv(n)
701 
702 #undef rename
703 #define rename(o, n) rb_w32_rename(o, n)
704 
705 #undef times
706 #define times(t) rb_w32_times(t)
707 #endif
708 
709 struct tms {
710  long tms_utime;
711  long tms_stime;
714 };
715 
716 int rb_w32_times(struct tms *);
717 
718 struct tm *gmtime_r(const time_t *, struct tm *);
719 struct tm *localtime_r(const time_t *, struct tm *);
720 
721 /* thread stuff */
722 int rb_w32_sleep(unsigned long msec);
723 int rb_w32_putc(int, FILE*);
724 int rb_w32_getc(FILE*);
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 
742 /*
743 == ***CAUTION***
744 Since this function is very dangerous, ((*NEVER*))
745 * lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
746 * use anything like TRAP_BEG...TRAP_END block structure,
747 in asynchronous_func_t.
748 */
751 
752 #if defined __GNUC__ && __GNUC__ >= 4
753 #pragma GCC visibility pop
754 #endif
755 
756 #ifdef __MINGW_ATTRIB_PURE
757 /* License: Ruby's */
758 /* get rid of bugs in math.h of mingw */
759 #define frexp(_X, _Y) __extension__ ({\
760  int intpart_frexp_bug = intpart_frexp_bug;\
761  double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\
762  *(_Y) = intpart_frexp_bug;\
763  result_frexp_bug;\
764 })
765 /* License: Ruby's */
766 #define modf(_X, _Y) __extension__ ({\
767  double intpart_modf_bug = intpart_modf_bug;\
768  double result_modf_bug = modf((_X), &intpart_modf_bug);\
769  *(_Y) = intpart_modf_bug;\
770  result_modf_bug;\
771 })
772 #endif
773 
774 #if defined(__cplusplus)
775 #if 0
776 { /* satisfy cc-mode */
777 #endif
778 } /* extern "C" { */
779 #endif
780 
781 #if defined(__MINGW64__)
782 /*
783  * Use powl() instead of broken pow() of x86_64-w64-mingw32.
784  * This workaround will fix test failures in test_bignum.rb,
785  * test_fixnum.rb and test_float.rb etc.
786  */
787 static inline double
788 rb_w32_pow(double x, double y)
789 {
790  return powl(x, y);
791 }
792 #elif defined(__MINGW64_VERSION_MAJOR)
793 /*
794  * Set floating point precision for pow() of mingw-w64 x86.
795  * With default precision the result is not proper on WinXP.
796  */
797 static inline double
798 rb_w32_pow(double x, double y)
799 {
800  double r;
801  unsigned int default_control = _controlfp(0, 0);
802  _controlfp(_PC_64, _MCW_PC);
803  r = pow(x, y);
804  /* Restore setting */
805  _controlfp(default_control, _MCW_PC);
806  return r;
807 }
808 #endif
809 #if defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW64__)
810 #define pow rb_w32_pow
811 #endif
812 
813 #endif /* RUBY_WIN32_H */
size_t iov_len
Definition: win32.h:213
char * rb_w32_ugetenv(const char *)
Definition: win32.c:4262
int gettimeofday(struct timeval *, struct timezone *)
Definition: win32.c:4013
int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout)
int ioctl(int, int,...)
Definition: win32.c:2438
int rb_w32_getc(FILE *)
Definition: win32.c:4953
int msg_iovlen
Definition: win32.h:219
void * iov_base
Definition: win32.h:212
void * msg_control
Definition: win32.h:220
rb_pid_t rb_w32_getppid(void)
Definition: win32.c:5131
rb_uid_t getuid(void)
Definition: win32.c:2392
ssize_t rb_w32_write(int, const void *, size_t)
Definition: win32.c:6044
int rb_w32_fstat(int, struct stat *)
Definition: win32.c:4441
int sendmsg(int, const struct msghdr *, int)
Definition: win32.c:3337
int WSAAPI rb_w32_connect(int, const struct sockaddr *, int)
Definition: win32.c:2961
int WSAAPI rb_w32_bind(int, const struct sockaddr *, int)
Definition: win32.c:2942
int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int)
Definition: win32.c:3235
long tms_stime
Definition: win32.h:711
int msg_namelen
Definition: win32.h:217
int rb_w32_fseeko(FILE *stream, off_t offset, int whence)
Definition: win32.h:215
int rb_w32_ustati64(const char *, struct stati64 *)
Definition: win32.c:4705
int rb_w32_wrap_io_handle(HANDLE, int)
Definition: win32.c:6694
SOCKET rb_w32_get_osfhandle(int)
Definition: win32.c:958
void * msg_name
Definition: win32.h:216
int rb_w32_umkdir(const char *, int)
Definition: win32.c:6308
rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int *, int *)
int fcntl(int, int,...)
Definition: win32.c:3835
ssize_t rb_w32_read(int, void *, size_t)
Definition: win32.c:5907
rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD)
Definition: win32.c:1287
int kill(int, int)
Definition: win32.c:4079
int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *)
Definition: win32.c:3036
int rb_w32_urename(const char *, const char *)
Definition: win32.c:4360
int rb_w32_fdisset(int, fd_set *)
Definition: win32.c:2472
struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *)
Definition: win32.c:3592
struct iovec * msg_iov
Definition: win32.h:218
int rb_w32_pipe(int[2])
Definition: win32.c:5430
int rb_w32_open(const char *, int,...)
Definition: win32.c:5210
int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
Definition: win32.c:2882
void rb_w32_free_environ(char **)
Definition: win32.c:5113
int WSAAPI rb_w32_accept(int, struct sockaddr *, int *)
Definition: win32.c:2906
struct protoent *WSAAPI rb_w32_getprotobynumber(int)
Definition: win32.c:3574
rb_pid_t rb_w32_getpid(void)
Definition: win32.c:5123
int rb_w32_uaccess(const char *, int)
Definition: win32.c:4748
int rb_w32_map_errno(DWORD)
Definition: win32.c:223
int recvmsg(int, struct msghdr *, int)
Definition: win32.c:3279
int msg_flags
Definition: win32.h:222
int wait(int *status)
Definition: win32.c:4255
void rb_w32_fdclr(int, fd_set *)
Definition: win32.c:2454
int rb_w32_times(struct tms *)
Definition: win32.c:4900
int WSAAPI rb_w32_socket(int, int, int)
Definition: win32.c:3473
int rb_w32_is_socket(int)
Definition: win32.c:2309
int rb_w32_cmdvector(const char *, char ***)
Definition: win32.c:1491
int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *)
Definition: win32.c:3003
const char *WSAAPI rb_w32_inet_ntop(int, const void *, char *, size_t)
Definition: win32.c:6550
struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int)
Definition: win32.c:3502
rb_gid_t getegid(void)
Definition: win32.c:2413
Definition: file.c:2361
struct hostent *WSAAPI rb_w32_gethostbyname(const char *)
Definition: win32.c:3520
int rb_w32_wopen(const WCHAR *, int,...)
Definition: win32.c:5235
uintptr_t(* asynchronous_func_t)(uintptr_t self, int argc, uintptr_t *argv)
Definition: win32.h:749
IUnknown DWORD
Definition: win32ole.c:149
int WSAAPI rb_w32_send(int, const char *, int, int)
Definition: win32.c:3228
rb_pid_t rb_w32_spawn(int, const char *, const char *)
Definition: win32.c:1180
off_t rb_w32_ftello(FILE *stream)
Definition: win32.c:4880
int WINAPI rb_w32_Sleep(unsigned long msec)
int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *)
Definition: win32.c:3220
struct tm * localtime_r(const time_t *, struct tm *)
Definition: win32.c:6670
int chown(const char *, int, int)
Definition: win32.c:4065
int WSAAPI rb_w32_listen(int, int)
Definition: win32.c:3072
int rb_w32_sleep(unsigned long msec)
int argc
Definition: ruby.c:130
int rb_w32_mkdir(const char *, int)
Definition: win32.c:6322
int rb_w32_uutime(const char *, const struct utimbuf *)
Definition: win32.c:6246
int rb_w32_rmdir(const char *)
Definition: win32.c:6357
int link(const char *, const char *)
Definition: win32.c:4235
int rb_w32_unwrap_io_handle(int)
Definition: win32.c:6716
int rb_w32_putc(int, FILE *)
Definition: win32.c:4974
int rb_w32_fstati64(int, struct stati64 *)
Definition: win32.c:4465
int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait)
Definition: win32.c:2704
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:108
int rb_w32_unlink(const char *)
Definition: win32.c:6420
#define off_t
Definition: io.c:65
int rb_w32_truncate(const char *path, off_t length)
Definition: win32.c:4792
int rb_w32_urmdir(const char *)
Definition: win32.c:6371
char ** rb_w32_get_environ(void)
Definition: win32.c:5076
int setgid(rb_gid_t)
Definition: win32.c:2427
unsigned int uintptr_t
Definition: win32.h:94
int rb_w32_uopen(const char *, int,...)
Definition: win32.c:5162
int rb_w32_stati64(const char *, struct stati64 *)
Definition: win32.c:4719
rb_uid_t geteuid(void)
Definition: win32.c:2399
int rb_w32_uchmod(const char *, int)
Definition: win32.c:6434
char * rb_w32_getenv(const char *)
Definition: win32.c:4300
int intptr_t
Definition: win32.h:86
Definition: win32.h:211
struct protoent *WSAAPI rb_w32_getprotobyname(const char *)
Definition: win32.c:3556
#define INFINITY
Definition: missing.h:138
long tms_utime
Definition: win32.h:710
int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int)
Definition: win32.c:3389
int rb_w32_access(const char *, int)
Definition: win32.c:4733
rb_pid_t rb_w32_aspawn(int, const char *, char *const *)
Definition: win32.c:1357
long tms_cstime
Definition: win32.h:713
Definition: win32.h:709
int rb_w32_isatty(int)
Definition: win32.c:6449
int rb_w32_uchdir(const char *)
Definition: win32.c:6274
int rb_w32_ulink(const char *, const char *)
Definition: win32.c:4215
long rb_w32_write_console(uintptr_t, int)
Definition: win32.c:6145
char * rb_w32_strerror(int)
Definition: win32.c:2324
DWORD rb_w32_osid(void)
int WSAAPI rb_w32_ioctlsocket(int, long, u_long *)
Definition: win32.c:3054
DWORD rb_w32_osver(void)
Definition: win32.c:269
struct servent *WSAAPI rb_w32_getservbyport(int, const char *)
Definition: win32.c:3610
int WSAAPI rb_w32_gethostname(char *, int)
Definition: win32.c:3538
struct tm * gmtime_r(const time_t *, struct tm *)
Definition: win32.c:6646
int rb_w32_ftruncate(int fd, off_t length)
Definition: win32.c:4808
void rb_w32_fdset(int, fd_set *)
Definition: win32.c:2445
int WSAAPI rb_w32_shutdown(int, int)
Definition: win32.c:3407
int flock(int fd, int oper)
Definition: flock.c:125
int rb_w32_close(int)
Definition: win32.c:5840
int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *)
Definition: win32.c:2985
char * rb_w32_getcwd(char *, int)
Definition: win32.c:4025
#define u_long
Definition: vsnprintf.c:64
static double scalb(double a, long b)
Definition: win32.h:338
int msg_controllen
Definition: win32.h:221
rb_gid_t getgid(void)
Definition: win32.c:2406
int rb_w32_fclose(FILE *)
Definition: win32.c:5407
static int finite(double x)
Definition: win32.h:330
char rb_w32_fd_is_text(int)
Definition: win32.c:6568
long tms_cutime
Definition: win32.h:712
#define stat(path, st)
Definition: win32.h:193
int rb_w32_socketpair(int, int, int, int *)
Definition: win32.c:3717
int WSAAPI rb_w32_recv(int, char *, int, int)
Definition: win32.c:3213
int rb_w32_io_cancelable_p(int)
Definition: win32.c:2195
int setuid(rb_uid_t)
Definition: win32.c:2420
uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t *argv, uintptr_t intrval)
Definition: win32.c:5013
int rb_w32_uunlink(const char *)
Definition: win32.c:6406
int rb_w32_stat(const char *, struct stat *)
Definition: win32.c:4645
int rb_w32_utime(const char *, const struct utimbuf *)
Definition: win32.c:6260
rb_pid_t waitpid(rb_pid_t, int *, int)
Definition: win32.c:3919
int rb_w32_uchown(const char *, int, int)
Definition: win32.c:4072
int rb_w32_rename(const char *, const char *)
Definition: win32.c:4379
char ** argv
Definition: ruby.c:131