Ruby  2.0.0p481(2014-05-08revision45883)
include/ruby/win32.h
Go to the documentation of this file.
00001 #ifndef RUBY_WIN32_H
00002 #define RUBY_WIN32_H 1
00003 
00004 #if defined(__cplusplus)
00005 extern "C" {
00006 #if 0
00007 } /* satisfy cc-mode */
00008 #endif
00009 #endif
00010 
00011 #if defined __GNUC__ && __GNUC__ >= 4
00012 #pragma GCC visibility push(default)
00013 #endif
00014 
00015 /*
00016  *  Copyright (c) 1993, Intergraph Corporation
00017  *
00018  *  You may distribute under the terms of either the GNU General Public
00019  *  License or the Artistic License, as specified in the perl README file.
00020  *
00021  */
00022 
00023 /*
00024  * Definitions for NT port of Perl
00025  */
00026 
00027 
00028 /*
00029  * Ok now we can include the normal include files.
00030  */
00031 
00032 /* #include <stdarg.h> conflict with varargs.h? */
00033 #if !defined(WSAAPI)
00034 #if defined(__cplusplus) && defined(_MSC_VER)
00035 extern "C++" {                  /* template without extern "C++" */
00036 #endif
00037 #if !defined(_WIN64) && !defined(WIN32)
00038 #define WIN32
00039 #endif
00040 #include <winsock2.h>
00041 #include <ws2tcpip.h>
00042 #if defined(__cplusplus) && defined(_MSC_VER)
00043 }
00044 #endif
00045 #endif
00046 
00047 /*
00048  * We're not using Microsoft's "extensions" to C for
00049  * Structured Exception Handling (SEH) so we can nuke these
00050  */
00051 #undef try
00052 #undef except
00053 #undef finally
00054 #undef leave
00055 
00056 #include <stdio.h>
00057 #include <stdlib.h>
00058 #include <string.h>
00059 #include <direct.h>
00060 #include <process.h>
00061 #include <time.h>
00062 #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
00063 extern "C++" {                  /* template without extern "C++" */
00064 #endif
00065 #include <math.h>
00066 #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
00067 }
00068 #endif
00069 #include <signal.h>
00070 #include <sys/stat.h>
00071 #include <sys/types.h>
00072 #ifdef HAVE_SYS_UTIME_H
00073 # include <sys/utime.h>
00074 #else
00075 # include <utime.h>
00076 #endif
00077 #include <io.h>
00078 #include <malloc.h>
00079 #if defined __MINGW32__ || __BORLANDC__ >= 0x0580
00080 # include <stdint.h>
00081 #else
00082 # if !defined(_INTPTR_T_DEFINED)
00083 #  ifdef _WIN64
00084 typedef __int64 intptr_t;
00085 #  else
00086 typedef int intptr_t;
00087 #  endif
00088 #  define _INTPTR_T_DEFINED
00089 # endif
00090 # if !defined(_UINTPTR_T_DEFINED)
00091 #  ifdef _WIN64
00092 typedef unsigned __int64 uintptr_t;
00093 #  else
00094 typedef unsigned int uintptr_t;
00095 #  endif
00096 #  define _UINTPTR_T_DEFINED
00097 # endif
00098 #endif
00099 #ifndef __MINGW32__
00100 # define mode_t int
00101 #endif
00102 #ifdef HAVE_UNISTD_H
00103 # include <unistd.h>
00104 #endif
00105 
00106 #define rb_w32_iswinnt()  TRUE
00107 #define rb_w32_iswin95()  FALSE
00108 
00109 #define WNOHANG -1
00110 
00111 #undef getc
00112 #undef putc
00113 #undef fgetc
00114 #undef fputc
00115 #undef getchar
00116 #undef putchar
00117 #undef fgetchar
00118 #undef fputchar
00119 #undef utime
00120 #undef lseek
00121 #undef stat
00122 #undef fstat
00123 #define getc(_stream)           rb_w32_getc(_stream)
00124 #define getchar()               rb_w32_getc(stdin)
00125 #define putc(_c, _stream)       rb_w32_putc(_c, _stream)
00126 #define putchar(_c)             rb_w32_putc(_c, stdout)
00127 #ifdef RUBY_EXPORT
00128 #define fgetc(_stream)          getc(_stream)
00129 #define fputc(_c, _stream)      putc(_c, _stream)
00130 #define fgetchar()              getchar()
00131 #define fputchar(_c)            putchar(_c)
00132 #define utime(_p, _t)           rb_w32_utime(_p, _t)
00133 #define lseek(_f, _o, _w)       _lseeki64(_f, _o, _w)
00134 
00135 #define pipe(p)                 rb_w32_pipe(p)
00136 #define open                    rb_w32_open
00137 #define close(h)                rb_w32_close(h)
00138 #define fclose(f)               rb_w32_fclose(f)
00139 #define read(f, b, s)           rb_w32_read(f, b, s)
00140 #define write(f, b, s)          rb_w32_write(f, b, s)
00141 #define getpid()                rb_w32_getpid()
00142 #define getppid()               rb_w32_getppid()
00143 #define sleep(x)                rb_w32_Sleep((x)*1000)
00144 #define Sleep(msec)             (void)rb_w32_Sleep(msec)
00145 #define fstati64(fd,st)         rb_w32_fstati64(fd,st)
00146 #ifdef __BORLANDC__
00147 #define creat(p, m)             _creat(p, m)
00148 #define eof()                   _eof()
00149 #define filelength(h)           _filelength(h)
00150 #define mktemp(t)               _mktemp(t)
00151 #define tell(h)                 _tell(h)
00152 #define _open                   _sopen
00153 #define sopen                   _sopen
00154 #undef fopen
00155 #define fopen(p, m)             rb_w32_fopen(p, m)
00156 #undef fdopen
00157 #define fdopen(h, m)            rb_w32_fdopen(h, m)
00158 #undef fsopen
00159 #define fsopen(p, m, sh)        rb_w32_fsopen(p, m, sh)
00160 #endif /* __BORLANDC__ */
00161 
00162 #undef execv
00163 #define execv(path,argv)        rb_w32_aspawn(P_OVERLAY,path,argv)
00164 #if !defined(__BORLANDC__)
00165 #undef isatty
00166 #define isatty(h)               rb_w32_isatty(h)
00167 #endif /* __BORLANDC__ */
00168 
00169 #undef mkdir
00170 #define mkdir(p, m)             rb_w32_mkdir(p, m)
00171 #undef rmdir
00172 #define rmdir(p)                rb_w32_rmdir(p)
00173 #undef unlink
00174 #define unlink(p)               rb_w32_unlink(p)
00175 #endif /* RUBY_EXPORT */
00176 
00177 #if SIZEOF_OFF_T == 8
00178 #define off_t __int64
00179 #define stat stati64
00180 #define fstat(fd,st)            fstati64(fd,st)
00181 #if defined(__BORLANDC__)
00182 #define stati64(path, st) rb_w32_stati64(path, st)
00183 #elif !defined(_MSC_VER) || RT_VER < 80
00184 #define stati64 _stati64
00185 #ifndef _stati64
00186 #define _stati64(path, st) rb_w32_stati64(path, st)
00187 #endif
00188 #else
00189 #define stati64 _stat64
00190 #define _stat64(path, st) rb_w32_stati64(path, st)
00191 #endif
00192 #else
00193 #define stat(path,st)           rb_w32_stat(path,st)
00194 #define fstat(fd,st)            rb_w32_fstat(fd,st)
00195 extern int rb_w32_stat(const char *, struct stat *);
00196 extern int rb_w32_fstat(int, struct stat *);
00197 #endif
00198 #define access(path,mode)       rb_w32_access(path,mode)
00199 
00200 #define strcasecmp              _stricmp
00201 #define strncasecmp             _strnicmp
00202 #define fsync                   _commit
00203 
00204 struct timezone;
00205 
00206 #ifdef __MINGW32__
00207 #undef isascii
00208 #define isascii __isascii
00209 #endif
00210 
00211 struct iovec {
00212     void *iov_base;
00213     size_t iov_len;
00214 };
00215 struct msghdr {
00216     void *msg_name;
00217     int msg_namelen;
00218     struct iovec *msg_iov;
00219     int msg_iovlen;
00220     void *msg_control;
00221     int msg_controllen;
00222     int msg_flags;
00223 };
00224 
00225 extern DWORD  rb_w32_osid(void);
00226 extern int    rb_w32_cmdvector(const char *, char ***);
00227 extern rb_pid_t  rb_w32_pipe_exec(const char *, const char *, int, int *, int *);
00228 extern int    flock(int fd, int oper);
00229 extern int    rb_w32_io_cancelable_p(int);
00230 extern int    rb_w32_is_socket(int);
00231 extern int    WSAAPI rb_w32_accept(int, struct sockaddr *, int *);
00232 extern int    WSAAPI rb_w32_bind(int, const struct sockaddr *, int);
00233 extern int    WSAAPI rb_w32_connect(int, const struct sockaddr *, int);
00234 extern void   rb_w32_fdset(int, fd_set*);
00235 extern void   rb_w32_fdclr(int, fd_set*);
00236 extern int    rb_w32_fdisset(int, fd_set*);
00237 extern int    WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
00238 extern int    WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *);
00239 extern int    WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *);
00240 extern int    WSAAPI rb_w32_getsockopt(int, int, int, char *, int *);
00241 extern int    WSAAPI rb_w32_ioctlsocket(int, long, u_long *);
00242 extern int    WSAAPI rb_w32_listen(int, int);
00243 extern int    WSAAPI rb_w32_recv(int, char *, int, int);
00244 extern int    WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *);
00245 extern int    WSAAPI rb_w32_send(int, const char *, int, int);
00246 extern int    WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int);
00247 extern int    recvmsg(int, struct msghdr *, int);
00248 extern int    sendmsg(int, const struct msghdr *, int);
00249 extern int    WSAAPI rb_w32_setsockopt(int, int, int, const char *, int);
00250 extern int    WSAAPI rb_w32_shutdown(int, int);
00251 extern int    WSAAPI rb_w32_socket(int, int, int);
00252 extern SOCKET rb_w32_get_osfhandle(int);
00253 extern struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int);
00254 extern struct hostent *WSAAPI rb_w32_gethostbyname(const char *);
00255 extern int    WSAAPI rb_w32_gethostname(char *, int);
00256 extern struct protoent *WSAAPI rb_w32_getprotobyname(const char *);
00257 extern struct protoent *WSAAPI rb_w32_getprotobynumber(int);
00258 extern struct servent  *WSAAPI rb_w32_getservbyname(const char *, const char *);
00259 extern struct servent  *WSAAPI rb_w32_getservbyport(int, const char *);
00260 extern int    rb_w32_socketpair(int, int, int, int *);
00261 extern char * rb_w32_getcwd(char *, int);
00262 extern char * rb_w32_ugetenv(const char *);
00263 extern char * rb_w32_getenv(const char *);
00264 extern int    rb_w32_rename(const char *, const char *);
00265 extern int    rb_w32_urename(const char *, const char *);
00266 extern char **rb_w32_get_environ(void);
00267 extern void   rb_w32_free_environ(char **);
00268 extern int    rb_w32_map_errno(DWORD);
00269 extern const char *WSAAPI rb_w32_inet_ntop(int,const void *,char *,size_t);
00270 extern DWORD  rb_w32_osver(void);
00271 
00272 extern int chown(const char *, int, int);
00273 extern int rb_w32_uchown(const char *, int, int);
00274 extern int link(const char *, const char *);
00275 extern int rb_w32_ulink(const char *, const char *);
00276 extern int gettimeofday(struct timeval *, struct timezone *);
00277 extern rb_pid_t waitpid (rb_pid_t, int *, int);
00278 extern rb_pid_t rb_w32_spawn(int, const char *, const char*);
00279 extern rb_pid_t rb_w32_aspawn(int, const char *, char *const *);
00280 extern rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD);
00281 extern int kill(int, int);
00282 extern int fcntl(int, int, ...);
00283 extern rb_pid_t rb_w32_getpid(void);
00284 extern rb_pid_t rb_w32_getppid(void);
00285 #if !defined(__BORLANDC__)
00286 extern int rb_w32_isatty(int);
00287 #endif
00288 extern int rb_w32_uchdir(const char *);
00289 extern int rb_w32_mkdir(const char *, int);
00290 extern int rb_w32_umkdir(const char *, int);
00291 extern int rb_w32_rmdir(const char *);
00292 extern int rb_w32_urmdir(const char *);
00293 extern int rb_w32_unlink(const char *);
00294 extern int rb_w32_uunlink(const char *);
00295 extern int rb_w32_uchmod(const char *, int);
00296 extern int rb_w32_stati64(const char *, struct stati64 *);
00297 extern int rb_w32_ustati64(const char *, struct stati64 *);
00298 extern int rb_w32_access(const char *, int);
00299 extern int rb_w32_uaccess(const char *, int);
00300 extern char rb_w32_fd_is_text(int);
00301 extern int rb_w32_fstati64(int, struct stati64 *);
00302 
00303 #ifdef __BORLANDC__
00304 extern off_t _lseeki64(int, off_t, int);
00305 extern FILE *rb_w32_fopen(const char *, const char *);
00306 extern FILE *rb_w32_fdopen(int, const char *);
00307 extern FILE *rb_w32_fsopen(const char *, const char *, int);
00308 #endif
00309 
00310 #include <float.h>
00311 
00312 #if defined _MSC_VER && _MSC_VER >= 1800 && defined INFINITY
00313 #pragma warning(push)
00314 #pragma warning(disable:4756)
00315 static inline float
00316 rb_infinity_float(void)
00317 {
00318     return INFINITY;
00319 }
00320 #pragma warning(pop)
00321 #undef INFINITY
00322 #define INFINITY rb_infinity_float()
00323 #endif
00324 
00325 #if !defined __MINGW32__ || defined __NO_ISOCEXT
00326 #ifndef isnan
00327 #define isnan(x) _isnan(x)
00328 #endif
00329 static inline int
00330 finite(double x)
00331 {
00332     return _finite(x);
00333 }
00334 #ifndef copysign
00335 #define copysign(a, b) _copysign(a, b)
00336 #endif
00337 static inline double
00338 scalb(double a, long b)
00339 {
00340     return _scalb(a, b);
00341 }
00342 #endif
00343 
00344 #if !defined S_IFIFO && defined _S_IFIFO
00345 #define S_IFIFO _S_IFIFO
00346 #endif
00347 
00348 #if 0 && defined __BORLANDC__
00349 #undef S_ISDIR
00350 #undef S_ISFIFO
00351 #undef S_ISBLK
00352 #undef S_ISCHR
00353 #undef S_ISREG
00354 #define S_ISDIR(m)  (((unsigned short)(m) & S_IFMT) == S_IFDIR)
00355 #define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO)
00356 #define S_ISBLK(m)  (((unsigned short)(m) & S_IFMT) == S_IFBLK)
00357 #define S_ISCHR(m)  (((unsigned short)(m) & S_IFMT) == S_IFCHR)
00358 #define S_ISREG(m)  (((unsigned short)(m) & S_IFMT) == S_IFREG)
00359 #endif
00360 
00361 #if !defined S_IRUSR && !defined __MINGW32__
00362 #define S_IRUSR 0400
00363 #endif
00364 #ifndef S_IRGRP
00365 #define S_IRGRP 0040
00366 #endif
00367 #ifndef S_IROTH
00368 #define S_IROTH 0004
00369 #endif
00370 
00371 #if !defined S_IWUSR && !defined __MINGW32__
00372 #define S_IWUSR 0200
00373 #endif
00374 #ifndef S_IWGRP
00375 #define S_IWGRP 0020
00376 #endif
00377 #ifndef S_IWOTH
00378 #define S_IWOTH 0002
00379 #endif
00380 
00381 #if !defined S_IXUSR && !defined __MINGW32__
00382 #define S_IXUSR 0100
00383 #endif
00384 #ifndef S_IXGRP
00385 #define S_IXGRP 0010
00386 #endif
00387 #ifndef S_IXOTH
00388 #define S_IXOTH 0001
00389 #endif
00390 
00391 /*
00392  * define this so we can do inplace editing
00393  */
00394 
00395 #define SUFFIX
00396 
00397 extern int       rb_w32_ftruncate(int fd, off_t length);
00398 extern int       rb_w32_truncate(const char *path, off_t length);
00399 extern off_t     rb_w32_ftello(FILE *stream);
00400 extern int       rb_w32_fseeko(FILE *stream, off_t offset, int whence);
00401 
00402 #undef HAVE_FTRUNCATE
00403 #define HAVE_FTRUNCATE 1
00404 #if defined HAVE_FTRUNCATE64
00405 #define ftruncate ftruncate64
00406 #else
00407 #define ftruncate rb_w32_ftruncate
00408 #endif
00409 
00410 #undef HAVE_TRUNCATE
00411 #define HAVE_TRUNCATE 1
00412 #if defined HAVE_TRUNCATE64
00413 #define truncate truncate64
00414 #else
00415 #define truncate rb_w32_truncate
00416 #endif
00417 
00418 #undef HAVE_FSEEKO
00419 #define HAVE_FSEEKO 1
00420 #if defined HAVE_FSEEKO64
00421 #define fseeko fseeko64
00422 #else
00423 #define fseeko rb_w32_fseeko
00424 #endif
00425 
00426 #undef HAVE_FTELLO
00427 #define HAVE_FTELLO 1
00428 #if defined HAVE_FTELLO64
00429 #define ftello ftello64
00430 #else
00431 #define ftello rb_w32_ftello
00432 #endif
00433 
00434 /*
00435  * stubs
00436  */
00437 extern int       ioctl (int, int, ...);
00438 extern rb_uid_t  getuid (void);
00439 extern rb_uid_t  geteuid (void);
00440 extern rb_gid_t  getgid (void);
00441 extern rb_gid_t  getegid (void);
00442 extern int       setuid (rb_uid_t);
00443 extern int       setgid (rb_gid_t);
00444 
00445 extern char *rb_w32_strerror(int);
00446 
00447 #ifdef RUBY_EXPORT
00448 #define strerror(e) rb_w32_strerror(e)
00449 #endif
00450 
00451 #define PIPE_BUF 1024
00452 
00453 #define LOCK_SH 1
00454 #define LOCK_EX 2
00455 #define LOCK_NB 4
00456 #define LOCK_UN 8
00457 
00458 
00459 #ifndef SIGINT
00460 #define SIGINT 2
00461 #endif
00462 #ifndef SIGKILL
00463 #define SIGKILL 9
00464 #endif
00465 
00466 
00467 /* #undef va_start */
00468 /* #undef va_end */
00469 
00470 /* winsock error map */
00471 #include <errno.h>
00472 
00473 #ifndef EWOULDBLOCK
00474 # define EWOULDBLOCK            WSAEWOULDBLOCK
00475 #endif
00476 #ifndef EINPROGRESS
00477 # define EINPROGRESS            WSAEINPROGRESS
00478 #endif
00479 #ifndef EALREADY
00480 # define EALREADY               WSAEALREADY
00481 #endif
00482 #ifndef ENOTSOCK
00483 # define ENOTSOCK               WSAENOTSOCK
00484 #endif
00485 #ifndef EDESTADDRREQ
00486 # define EDESTADDRREQ           WSAEDESTADDRREQ
00487 #endif
00488 #ifndef EMSGSIZE
00489 # define EMSGSIZE               WSAEMSGSIZE
00490 #endif
00491 #ifndef EPROTOTYPE
00492 # define EPROTOTYPE             WSAEPROTOTYPE
00493 #endif
00494 #ifndef ENOPROTOOPT
00495 # define ENOPROTOOPT            WSAENOPROTOOPT
00496 #endif
00497 #ifndef EPROTONOSUPPORT
00498 # define EPROTONOSUPPORT        WSAEPROTONOSUPPORT
00499 #endif
00500 #ifndef ESOCKTNOSUPPORT
00501 # define ESOCKTNOSUPPORT        WSAESOCKTNOSUPPORT
00502 #endif
00503 #ifndef EOPNOTSUPP
00504 # define EOPNOTSUPP             WSAEOPNOTSUPP
00505 #endif
00506 #ifndef EPFNOSUPPORT
00507 # define EPFNOSUPPORT           WSAEPFNOSUPPORT
00508 #endif
00509 #ifndef EAFNOSUPPORT
00510 # define EAFNOSUPPORT           WSAEAFNOSUPPORT
00511 #endif
00512 #ifndef EADDRINUSE
00513 # define EADDRINUSE             WSAEADDRINUSE
00514 #endif
00515 #ifndef EADDRNOTAVAIL
00516 # define EADDRNOTAVAIL          WSAEADDRNOTAVAIL
00517 #endif
00518 #ifndef ENETDOWN
00519 # define ENETDOWN               WSAENETDOWN
00520 #endif
00521 #ifndef ENETUNREACH
00522 # define ENETUNREACH            WSAENETUNREACH
00523 #endif
00524 #ifndef ENETRESET
00525 # define ENETRESET              WSAENETRESET
00526 #endif
00527 #ifndef ECONNABORTED
00528 # define ECONNABORTED           WSAECONNABORTED
00529 #endif
00530 #ifndef ECONNRESET
00531 # define ECONNRESET             WSAECONNRESET
00532 #endif
00533 #ifndef ENOBUFS
00534 # define ENOBUFS                WSAENOBUFS
00535 #endif
00536 #ifndef EISCONN
00537 # define EISCONN                WSAEISCONN
00538 #endif
00539 #ifndef ENOTCONN
00540 # define ENOTCONN               WSAENOTCONN
00541 #endif
00542 #ifndef ESHUTDOWN
00543 # define ESHUTDOWN              WSAESHUTDOWN
00544 #endif
00545 #ifndef ETOOMANYREFS
00546 # define ETOOMANYREFS           WSAETOOMANYREFS
00547 #endif
00548 #ifndef ETIMEDOUT
00549 # define ETIMEDOUT              WSAETIMEDOUT
00550 #endif
00551 #ifndef ECONNREFUSED
00552 # define ECONNREFUSED           WSAECONNREFUSED
00553 #endif
00554 #ifndef ELOOP
00555 # define ELOOP                  WSAELOOP
00556 #endif
00557 /*#define ENAMETOOLONG  WSAENAMETOOLONG*/
00558 #ifndef EHOSTDOWN
00559 # define EHOSTDOWN              WSAEHOSTDOWN
00560 #endif
00561 #ifndef EHOSTUNREACH
00562 # define EHOSTUNREACH           WSAEHOSTUNREACH
00563 #endif
00564 /*#define ENOTEMPTY     WSAENOTEMPTY*/
00565 #ifndef EPROCLIM
00566 # define EPROCLIM               WSAEPROCLIM
00567 #endif
00568 #ifndef EUSERS
00569 # define EUSERS                 WSAEUSERS
00570 #endif
00571 #ifndef EDQUOT
00572 # define EDQUOT                 WSAEDQUOT
00573 #endif
00574 #ifndef ESTALE
00575 # define ESTALE                 WSAESTALE
00576 #endif
00577 #ifndef EREMOTE
00578 # define EREMOTE                WSAEREMOTE
00579 #endif
00580 
00581 #define F_DUPFD 0
00582 #if 0
00583 #define F_GETFD 1
00584 #define F_SETFD 2
00585 #define F_GETFL 3
00586 #endif
00587 #define F_SETFL 4
00588 #if 0
00589 #define FD_CLOEXEC 1 /* F_GETFD, F_SETFD */
00590 #endif
00591 #define O_NONBLOCK 1
00592 
00593 #undef FD_SET
00594 #define FD_SET(fd, set) do {\
00595     unsigned int i;\
00596     SOCKET s = _get_osfhandle(fd);\
00597 \
00598     for (i = 0; i < (set)->fd_count; i++) {\
00599         if ((set)->fd_array[i] == s) {\
00600             break;\
00601         }\
00602     }\
00603     if (i == (set)->fd_count) {\
00604         if ((set)->fd_count < FD_SETSIZE) {\
00605             (set)->fd_array[i] = s;\
00606             (set)->fd_count++;\
00607         }\
00608     }\
00609 } while(0)
00610 
00611 #undef FD_CLR
00612 #define FD_CLR(f, s)            rb_w32_fdclr(f, s)
00613 
00614 #undef FD_ISSET
00615 #define FD_ISSET(f, s)          rb_w32_fdisset(f, s)
00616 
00617 #ifdef RUBY_EXPORT
00618 #undef inet_ntop
00619 #define inet_ntop(f,a,n,l)      rb_w32_inet_ntop(f,a,n,l)
00620 
00621 #undef accept
00622 #define accept(s, a, l)         rb_w32_accept(s, a, l)
00623 
00624 #undef bind
00625 #define bind(s, a, l)           rb_w32_bind(s, a, l)
00626 
00627 #undef connect
00628 #define connect(s, a, l)        rb_w32_connect(s, a, l)
00629 
00630 #undef select
00631 #define select(n, r, w, e, t)   rb_w32_select(n, r, w, e, t)
00632 
00633 #undef getpeername
00634 #define getpeername(s, a, l)    rb_w32_getpeername(s, a, l)
00635 
00636 #undef getsockname
00637 #define getsockname(s, a, l)    rb_w32_getsockname(s, a, l)
00638 
00639 #undef getsockopt
00640 #define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
00641 
00642 #undef ioctlsocket
00643 #define ioctlsocket(s, c, a)    rb_w32_ioctlsocket(s, c, a)
00644 
00645 #undef listen
00646 #define listen(s, b)            rb_w32_listen(s, b)
00647 
00648 #undef recv
00649 #define recv(s, b, l, f)        rb_w32_recv(s, b, l, f)
00650 
00651 #undef recvfrom
00652 #define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
00653 
00654 #undef send
00655 #define send(s, b, l, f)        rb_w32_send(s, b, l, f)
00656 
00657 #undef sendto
00658 #define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
00659 
00660 #undef setsockopt
00661 #define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
00662 
00663 #undef shutdown
00664 #define shutdown(s, h)          rb_w32_shutdown(s, h)
00665 
00666 #undef socket
00667 #define socket(s, t, p)         rb_w32_socket(s, t, p)
00668 
00669 #undef gethostbyaddr
00670 #define gethostbyaddr(a, l, t)  rb_w32_gethostbyaddr(a, l, t)
00671 
00672 #undef gethostbyname
00673 #define gethostbyname(n)        rb_w32_gethostbyname(n)
00674 
00675 #undef gethostname
00676 #define gethostname(n, l)       rb_w32_gethostname(n, l)
00677 
00678 #undef getprotobyname
00679 #define getprotobyname(n)       rb_w32_getprotobyname(n)
00680 
00681 #undef getprotobynumber
00682 #define getprotobynumber(n)     rb_w32_getprotobynumber(n)
00683 
00684 #undef getservbyname
00685 #define getservbyname(n, p)     rb_w32_getservbyname(n, p)
00686 
00687 #undef getservbyport
00688 #define getservbyport(p, pr)    rb_w32_getservbyport(p, pr)
00689 
00690 #undef socketpair
00691 #define socketpair(a, t, p, s)  rb_w32_socketpair(a, t, p, s)
00692 
00693 #undef get_osfhandle
00694 #define get_osfhandle(h)        rb_w32_get_osfhandle(h)
00695 
00696 #undef getcwd
00697 #define getcwd(b, s)            rb_w32_getcwd(b, s)
00698 
00699 #undef getenv
00700 #define getenv(n)               rb_w32_getenv(n)
00701 
00702 #undef rename
00703 #define rename(o, n)            rb_w32_rename(o, n)
00704 
00705 #undef times
00706 #define times(t)                rb_w32_times(t)
00707 #endif
00708 
00709 struct tms {
00710         long    tms_utime;
00711         long    tms_stime;
00712         long    tms_cutime;
00713         long    tms_cstime;
00714 };
00715 
00716 int rb_w32_times(struct tms *);
00717 
00718 struct tm *gmtime_r(const time_t *, struct tm *);
00719 struct tm *localtime_r(const time_t *, struct tm *);
00720 
00721 /* thread stuff */
00722 int  rb_w32_sleep(unsigned long msec);
00723 int  rb_w32_putc(int, FILE*);
00724 int  rb_w32_getc(FILE*);
00725 int  rb_w32_open(const char *, int, ...);
00726 int  rb_w32_uopen(const char *, int, ...);
00727 int  rb_w32_wopen(const WCHAR *, int, ...);
00728 int  rb_w32_close(int);
00729 int  rb_w32_fclose(FILE*);
00730 int  rb_w32_pipe(int[2]);
00731 ssize_t rb_w32_read(int, void *, size_t);
00732 ssize_t rb_w32_write(int, const void *, size_t);
00733 int  rb_w32_utime(const char *, const struct utimbuf *);
00734 int  rb_w32_uutime(const char *, const struct utimbuf *);
00735 long rb_w32_write_console(uintptr_t, int);      /* use uintptr_t instead of VALUE because it's not defined yet here */
00736 int  WINAPI rb_w32_Sleep(unsigned long msec);
00737 int  rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout);
00738 int  rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait);
00739 int  rb_w32_wrap_io_handle(HANDLE, int);
00740 int  rb_w32_unwrap_io_handle(int);
00741 
00742 /*
00743 == ***CAUTION***
00744 Since this function is very dangerous, ((*NEVER*))
00745 * lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
00746 * use anything like TRAP_BEG...TRAP_END block structure,
00747 in asynchronous_func_t.
00748 */
00749 typedef uintptr_t (*asynchronous_func_t)(uintptr_t self, int argc, uintptr_t* argv);
00750 uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t* argv, uintptr_t intrval);
00751 
00752 #if defined __GNUC__ && __GNUC__ >= 4
00753 #pragma GCC visibility pop
00754 #endif
00755 
00756 #ifdef __MINGW_ATTRIB_PURE
00757 /* License: Ruby's */
00758 /* get rid of bugs in math.h of mingw */
00759 #define frexp(_X, _Y) __extension__ ({\
00760     int intpart_frexp_bug = intpart_frexp_bug;\
00761     double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\
00762     *(_Y) = intpart_frexp_bug;\
00763     result_frexp_bug;\
00764 })
00765 /* License: Ruby's */
00766 #define modf(_X, _Y) __extension__ ({\
00767     double intpart_modf_bug = intpart_modf_bug;\
00768     double result_modf_bug = modf((_X), &intpart_modf_bug);\
00769     *(_Y) = intpart_modf_bug;\
00770     result_modf_bug;\
00771 })
00772 #endif
00773 
00774 #if defined(__cplusplus)
00775 #if 0
00776 { /* satisfy cc-mode */
00777 #endif
00778 }  /* extern "C" { */
00779 #endif
00780 
00781 #if defined(__MINGW64__)
00782 /*
00783  * Use powl() instead of broken pow() of x86_64-w64-mingw32.
00784  * This workaround will fix test failures in test_bignum.rb,
00785  * test_fixnum.rb and test_float.rb etc.
00786  */
00787 static inline double
00788 rb_w32_pow(double x, double y)
00789 {
00790     return powl(x, y);
00791 }
00792 #elif defined(__MINGW64_VERSION_MAJOR)
00793 /*
00794  * Set floating point precision for pow() of mingw-w64 x86.
00795  * With default precision the result is not proper on WinXP.
00796  */
00797 static inline double
00798 rb_w32_pow(double x, double y)
00799 {
00800     double r;
00801     unsigned int default_control = _controlfp(0, 0);
00802     _controlfp(_PC_64, _MCW_PC);
00803     r = pow(x, y);
00804     /* Restore setting */
00805     _controlfp(default_control, _MCW_PC);
00806     return r;
00807 }
00808 #endif
00809 #if defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW64__)
00810 #define pow rb_w32_pow
00811 #endif
00812 
00813 #endif /* RUBY_WIN32_H */
00814