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