Ruby 1.9.3p327(2012-11-10revision37606)
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 #if !defined __MINGW32__ || defined __NO_ISOCEXT
00319 #ifndef isnan
00320 #define isnan(x) _isnan(x)
00321 #endif
00322 static inline int
00323 finite(double x)
00324 {
00325     return _finite(x);
00326 }
00327 #ifndef copysign
00328 #define copysign(a, b) _copysign(a, b)
00329 #endif
00330 static inline double
00331 scalb(double a, long b)
00332 {
00333     return _scalb(a, b);
00334 }
00335 #endif
00336 
00337 #if !defined S_IFIFO && defined _S_IFIFO
00338 #define S_IFIFO _S_IFIFO
00339 #endif
00340 
00341 #if 0 && defined __BORLANDC__
00342 #undef S_ISDIR
00343 #undef S_ISFIFO
00344 #undef S_ISBLK
00345 #undef S_ISCHR
00346 #undef S_ISREG
00347 #define S_ISDIR(m)  (((unsigned short)(m) & S_IFMT) == S_IFDIR)
00348 #define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO)
00349 #define S_ISBLK(m)  (((unsigned short)(m) & S_IFMT) == S_IFBLK)
00350 #define S_ISCHR(m)  (((unsigned short)(m) & S_IFMT) == S_IFCHR)
00351 #define S_ISREG(m)  (((unsigned short)(m) & S_IFMT) == S_IFREG)
00352 #endif
00353 
00354 #if !defined S_IRUSR && !defined __MINGW32__
00355 #define S_IRUSR 0400
00356 #endif
00357 #ifndef S_IRGRP
00358 #define S_IRGRP 0040
00359 #endif
00360 #ifndef S_IROTH
00361 #define S_IROTH 0004
00362 #endif
00363 
00364 #if !defined S_IWUSR && !defined __MINGW32__
00365 #define S_IWUSR 0200
00366 #endif
00367 #ifndef S_IWGRP
00368 #define S_IWGRP 0020
00369 #endif
00370 #ifndef S_IWOTH
00371 #define S_IWOTH 0002
00372 #endif
00373 
00374 #if !defined S_IXUSR && !defined __MINGW32__
00375 #define S_IXUSR 0100
00376 #endif
00377 #ifndef S_IXGRP
00378 #define S_IXGRP 0010
00379 #endif
00380 #ifndef S_IXOTH
00381 #define S_IXOTH 0001
00382 #endif
00383 
00384 //
00385 // define this so we can do inplace editing
00386 //
00387 
00388 #define SUFFIX
00389 
00390 extern int       rb_w32_ftruncate(int fd, off_t length);
00391 extern int       rb_w32_truncate(const char *path, off_t length);
00392 extern off_t     rb_w32_ftello(FILE *stream);
00393 extern int       rb_w32_fseeko(FILE *stream, off_t offset, int whence);
00394 
00395 #undef HAVE_FTRUNCATE
00396 #define HAVE_FTRUNCATE 1
00397 #if defined HAVE_FTRUNCATE64
00398 #define ftruncate ftruncate64
00399 #else
00400 #define ftruncate rb_w32_ftruncate
00401 #endif
00402 
00403 #undef HAVE_TRUNCATE
00404 #define HAVE_TRUNCATE 1
00405 #if defined HAVE_TRUNCATE64
00406 #define truncate truncate64
00407 #else
00408 #define truncate rb_w32_truncate
00409 #endif
00410 
00411 #undef HAVE_FSEEKO
00412 #define HAVE_FSEEKO 1
00413 #if defined HAVE_FSEEKO64
00414 #define fseeko fseeko64
00415 #else
00416 #define fseeko rb_w32_fseeko
00417 #endif
00418 
00419 #undef HAVE_FTELLO
00420 #define HAVE_FTELLO 1
00421 #if defined HAVE_FTELLO64
00422 #define ftello ftello64
00423 #else
00424 #define ftello rb_w32_ftello
00425 #endif
00426 
00427 //
00428 // stubs
00429 //
00430 extern int       ioctl (int, int, ...);
00431 extern rb_uid_t  getuid (void);
00432 extern rb_uid_t  geteuid (void);
00433 extern rb_gid_t  getgid (void);
00434 extern rb_gid_t  getegid (void);
00435 extern int       setuid (rb_uid_t);
00436 extern int       setgid (rb_gid_t);
00437 
00438 extern char *rb_w32_strerror(int);
00439 
00440 #ifdef RUBY_EXPORT
00441 #define strerror(e) rb_w32_strerror(e)
00442 #endif
00443 
00444 #define PIPE_BUF 1024
00445 
00446 #define LOCK_SH 1
00447 #define LOCK_EX 2
00448 #define LOCK_NB 4
00449 #define LOCK_UN 8
00450 
00451 
00452 #ifndef SIGINT
00453 #define SIGINT 2
00454 #endif
00455 #ifndef SIGKILL
00456 #define SIGKILL 9
00457 #endif
00458 
00459 
00460 /* #undef va_start */
00461 /* #undef va_end */
00462 
00463 /* winsock error map */
00464 #include <errno.h>
00465 
00466 #ifndef EWOULDBLOCK
00467 # define EWOULDBLOCK            WSAEWOULDBLOCK
00468 #endif
00469 #ifndef EINPROGRESS
00470 # define EINPROGRESS            WSAEINPROGRESS
00471 #endif
00472 #ifndef EALREADY
00473 # define EALREADY               WSAEALREADY
00474 #endif
00475 #ifndef ENOTSOCK
00476 # define ENOTSOCK               WSAENOTSOCK
00477 #endif
00478 #ifndef EDESTADDRREQ
00479 # define EDESTADDRREQ           WSAEDESTADDRREQ
00480 #endif
00481 #ifndef EMSGSIZE
00482 # define EMSGSIZE               WSAEMSGSIZE
00483 #endif
00484 #ifndef EPROTOTYPE
00485 # define EPROTOTYPE             WSAEPROTOTYPE
00486 #endif
00487 #ifndef ENOPROTOOPT
00488 # define ENOPROTOOPT            WSAENOPROTOOPT
00489 #endif
00490 #ifndef EPROTONOSUPPORT
00491 # define EPROTONOSUPPORT        WSAEPROTONOSUPPORT
00492 #endif
00493 #ifndef ESOCKTNOSUPPORT
00494 # define ESOCKTNOSUPPORT        WSAESOCKTNOSUPPORT
00495 #endif
00496 #ifndef EOPNOTSUPP
00497 # define EOPNOTSUPP             WSAEOPNOTSUPP
00498 #endif
00499 #ifndef EPFNOSUPPORT
00500 # define EPFNOSUPPORT           WSAEPFNOSUPPORT
00501 #endif
00502 #ifndef EAFNOSUPPORT
00503 # define EAFNOSUPPORT           WSAEAFNOSUPPORT
00504 #endif
00505 #ifndef EADDRINUSE
00506 # define EADDRINUSE             WSAEADDRINUSE
00507 #endif
00508 #ifndef EADDRNOTAVAIL
00509 # define EADDRNOTAVAIL          WSAEADDRNOTAVAIL
00510 #endif
00511 #ifndef ENETDOWN
00512 # define ENETDOWN               WSAENETDOWN
00513 #endif
00514 #ifndef ENETUNREACH
00515 # define ENETUNREACH            WSAENETUNREACH
00516 #endif
00517 #ifndef ENETRESET
00518 # define ENETRESET              WSAENETRESET
00519 #endif
00520 #ifndef ECONNABORTED
00521 # define ECONNABORTED           WSAECONNABORTED
00522 #endif
00523 #ifndef ECONNRESET
00524 # define ECONNRESET             WSAECONNRESET
00525 #endif
00526 #ifndef ENOBUFS
00527 # define ENOBUFS                WSAENOBUFS
00528 #endif
00529 #ifndef EISCONN
00530 # define EISCONN                WSAEISCONN
00531 #endif
00532 #ifndef ENOTCONN
00533 # define ENOTCONN               WSAENOTCONN
00534 #endif
00535 #ifndef ESHUTDOWN
00536 # define ESHUTDOWN              WSAESHUTDOWN
00537 #endif
00538 #ifndef ETOOMANYREFS
00539 # define ETOOMANYREFS           WSAETOOMANYREFS
00540 #endif
00541 #ifndef ETIMEDOUT
00542 # define ETIMEDOUT              WSAETIMEDOUT
00543 #endif
00544 #ifndef ECONNREFUSED
00545 # define ECONNREFUSED           WSAECONNREFUSED
00546 #endif
00547 #ifndef ELOOP
00548 # define ELOOP                  WSAELOOP
00549 #endif
00550 /*#define ENAMETOOLONG  WSAENAMETOOLONG*/
00551 #ifndef EHOSTDOWN
00552 # define EHOSTDOWN              WSAEHOSTDOWN
00553 #endif
00554 #ifndef EHOSTUNREACH
00555 # define EHOSTUNREACH           WSAEHOSTUNREACH
00556 #endif
00557 /*#define ENOTEMPTY     WSAENOTEMPTY*/
00558 #ifndef EPROCLIM
00559 # define EPROCLIM               WSAEPROCLIM
00560 #endif
00561 #ifndef EUSERS
00562 # define EUSERS                 WSAEUSERS
00563 #endif
00564 #ifndef EDQUOT
00565 # define EDQUOT                 WSAEDQUOT
00566 #endif
00567 #ifndef ESTALE
00568 # define ESTALE                 WSAESTALE
00569 #endif
00570 #ifndef EREMOTE
00571 # define EREMOTE                WSAEREMOTE
00572 #endif
00573 
00574 #define F_SETFL 1
00575 #define O_NONBLOCK 1
00576 
00577 #undef FD_SET
00578 #define FD_SET(fd, set) do {\
00579     unsigned int i;\
00580     SOCKET s = _get_osfhandle(fd);\
00581 \
00582     for (i = 0; i < (set)->fd_count; i++) {\
00583         if ((set)->fd_array[i] == s) {\
00584             break;\
00585         }\
00586     }\
00587     if (i == (set)->fd_count) {\
00588         if ((set)->fd_count < FD_SETSIZE) {\
00589             (set)->fd_array[i] = s;\
00590             (set)->fd_count++;\
00591         }\
00592     }\
00593 } while(0)
00594 
00595 #undef FD_CLR
00596 #define FD_CLR(f, s)            rb_w32_fdclr(f, s)
00597 
00598 #undef FD_ISSET
00599 #define FD_ISSET(f, s)          rb_w32_fdisset(f, s)
00600 
00601 #ifdef RUBY_EXPORT
00602 #undef inet_ntop
00603 #define inet_ntop(f,a,n,l)      rb_w32_inet_ntop(f,a,n,l)
00604 
00605 #undef accept
00606 #define accept(s, a, l)         rb_w32_accept(s, a, l)
00607 
00608 #undef bind
00609 #define bind(s, a, l)           rb_w32_bind(s, a, l)
00610 
00611 #undef connect
00612 #define connect(s, a, l)        rb_w32_connect(s, a, l)
00613 
00614 #undef select
00615 #define select(n, r, w, e, t)   rb_w32_select(n, r, w, e, t)
00616 
00617 #undef getpeername
00618 #define getpeername(s, a, l)    rb_w32_getpeername(s, a, l)
00619 
00620 #undef getsockname
00621 #define getsockname(s, a, l)    rb_w32_getsockname(s, a, l)
00622 
00623 #undef getsockopt
00624 #define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
00625 
00626 #undef ioctlsocket
00627 #define ioctlsocket(s, c, a)    rb_w32_ioctlsocket(s, c, a)
00628 
00629 #undef listen
00630 #define listen(s, b)            rb_w32_listen(s, b)
00631 
00632 #undef recv
00633 #define recv(s, b, l, f)        rb_w32_recv(s, b, l, f)
00634 
00635 #undef recvfrom
00636 #define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
00637 
00638 #undef send
00639 #define send(s, b, l, f)        rb_w32_send(s, b, l, f)
00640 
00641 #undef sendto
00642 #define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
00643 
00644 #undef setsockopt
00645 #define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
00646 
00647 #undef shutdown
00648 #define shutdown(s, h)          rb_w32_shutdown(s, h)
00649 
00650 #undef socket
00651 #define socket(s, t, p)         rb_w32_socket(s, t, p)
00652 
00653 #undef gethostbyaddr
00654 #define gethostbyaddr(a, l, t)  rb_w32_gethostbyaddr(a, l, t)
00655 
00656 #undef gethostbyname
00657 #define gethostbyname(n)        rb_w32_gethostbyname(n)
00658 
00659 #undef gethostname
00660 #define gethostname(n, l)       rb_w32_gethostname(n, l)
00661 
00662 #undef getprotobyname
00663 #define getprotobyname(n)       rb_w32_getprotobyname(n)
00664 
00665 #undef getprotobynumber
00666 #define getprotobynumber(n)     rb_w32_getprotobynumber(n)
00667 
00668 #undef getservbyname
00669 #define getservbyname(n, p)     rb_w32_getservbyname(n, p)
00670 
00671 #undef getservbyport
00672 #define getservbyport(p, pr)    rb_w32_getservbyport(p, pr)
00673 
00674 #undef socketpair
00675 #define socketpair(a, t, p, s)  rb_w32_socketpair(a, t, p, s)
00676 
00677 #undef get_osfhandle
00678 #define get_osfhandle(h)        rb_w32_get_osfhandle(h)
00679 
00680 #undef getcwd
00681 #define getcwd(b, s)            rb_w32_getcwd(b, s)
00682 
00683 #undef getenv
00684 #define getenv(n)               rb_w32_getenv(n)
00685 
00686 #undef rename
00687 #define rename(o, n)            rb_w32_rename(o, n)
00688 
00689 #undef times
00690 #define times(t)                rb_w32_times(t)
00691 #endif
00692 
00693 struct tms {
00694         long    tms_utime;
00695         long    tms_stime;
00696         long    tms_cutime;
00697         long    tms_cstime;
00698 };
00699 
00700 int rb_w32_times(struct tms *);
00701 
00702 /* thread stuff */
00703 HANDLE GetCurrentThreadHandle(void);
00704 int  rb_w32_sleep(unsigned long msec);
00705 int  rb_w32_putc(int, FILE*);
00706 int  rb_w32_getc(FILE*);
00707 int  rb_w32_open(const char *, int, ...);
00708 int  rb_w32_uopen(const char *, int, ...);
00709 int  rb_w32_wopen(const WCHAR *, int, ...);
00710 int  rb_w32_close(int);
00711 int  rb_w32_fclose(FILE*);
00712 int  rb_w32_pipe(int[2]);
00713 ssize_t rb_w32_read(int, void *, size_t);
00714 ssize_t rb_w32_write(int, const void *, size_t);
00715 int  rb_w32_utime(const char *, const struct utimbuf *);
00716 int  rb_w32_uutime(const char *, const struct utimbuf *);
00717 long rb_w32_write_console(uintptr_t, int);      /* use uintptr_t instead of VALUE because it's not defined yet here */
00718 int  WINAPI rb_w32_Sleep(unsigned long msec);
00719 int  rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout);
00720 int  rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait);
00721 
00722 /*
00723 == ***CAUTION***
00724 Since this function is very dangerous, ((*NEVER*))
00725 * lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
00726 * use anything like TRAP_BEG...TRAP_END block structure,
00727 in asynchronous_func_t.
00728 */
00729 typedef uintptr_t (*asynchronous_func_t)(uintptr_t self, int argc, uintptr_t* argv);
00730 uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t* argv, uintptr_t intrval);
00731 
00732 #if defined __GNUC__ && __GNUC__ >= 4
00733 #pragma GCC visibility pop
00734 #endif
00735 
00736 #ifdef __MINGW_ATTRIB_PURE
00737 /* get rid of bugs in math.h of mingw */
00738 #define frexp(_X, _Y) __extension__ ({\
00739     int intpart_frexp_bug = intpart_frexp_bug;\
00740     double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\
00741     *(_Y) = intpart_frexp_bug;\
00742     result_frexp_bug;\
00743 })
00744 #define modf(_X, _Y) __extension__ ({\
00745     double intpart_modf_bug = intpart_modf_bug;\
00746     double result_modf_bug = modf((_X), &intpart_modf_bug);\
00747     *(_Y) = intpart_modf_bug;\
00748     result_modf_bug;\
00749 })
00750 #endif
00751 
00752 #if defined(__cplusplus)
00753 #if 0
00754 { /* satisfy cc-mode */
00755 #endif
00756 }  /* extern "C" { */
00757 #endif
00758 
00759 #ifdef __MINGW64__
00760 /*
00761  * Use powl() instead of broken pow() of x86_64-w64-mingw32.
00762  * This workaround will fix test failures in test_bignum.rb,
00763  * test_fixnum.rb and test_float.rb etc.
00764  */
00765 static inline double
00766 rb_w32_pow(double x, double y)
00767 {
00768     return powl(x, y);
00769 }
00770 #define pow rb_w32_pow
00771 #endif
00772 
00773 #endif /* RUBY_WIN32_H */
00774