4 #if defined(__cplusplus)
11 RUBY_SYMBOL_EXPORT_BEGIN
27 #if defined(__cplusplus) && defined(_MSC_VER)
30 #if !defined(_WIN64) && !defined(WIN32)
33 #if defined(_MSC_VER) && _MSC_VER <= 1200
39 #if !defined(_MSC_VER) || _MSC_VER >= 1400
42 #if defined(__cplusplus) && defined(_MSC_VER)
62 #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
66 #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
71 #include <sys/types.h>
72 #ifdef HAVE_SYS_UTIME_H
73 # include <sys/utime.h>
79 #if defined __MINGW32__
82 # if !defined(_INTPTR_T_DEFINED)
84 typedef __int64 intptr_t;
88 # define _INTPTR_T_DEFINED
90 # if !defined(INTPTR_MAX)
92 # define INTPTR_MAX 9223372036854775807I64
94 # define INTPTR_MAX 2147483647
96 # define INTPTR_MIN (-INTPTR_MAX-1)
98 # if !defined(_UINTPTR_T_DEFINED)
100 typedef unsigned __int64 uintptr_t;
102 typedef unsigned int uintptr_t;
104 # define _UINTPTR_T_DEFINED
106 # if !defined(UINTPTR_MAX)
108 # define UINTPTR_MAX 18446744073709551615UI64
110 # define UINTPTR_MAX 4294967295U
121 #define rb_w32_iswinnt() TRUE
122 #define rb_w32_iswin95() FALSE
126 #define O_SHARE_DELETE 0x20000000
128 typedef int clockid_t;
129 #define CLOCK_REALTIME 0
130 #define CLOCK_MONOTONIC 1
137 #define utime(_p, _t) rb_w32_uutime(_p, _t)
139 #define HAVE_UTIMES 1
140 #define utimes(_p, _t) rb_w32_uutimes(_p, _t)
141 #undef HAVE_UTIMENSAT
142 #define HAVE_UTIMENSAT 1
143 #define AT_FDCWD -100
144 #define utimensat(_d, _p, _t, _f) rb_w32_uutimensat(_d, _p, _t, _f)
145 #define lseek(_f, _o, _w) rb_w32_lseek(_f, _o, _w)
147 #define pipe(p) rb_w32_pipe(p)
148 #define open rb_w32_uopen
149 #define close(h) rb_w32_close(h)
150 #define fclose(f) rb_w32_fclose(f)
151 #define read(f, b, s) rb_w32_read(f, b, s)
152 #define write(f, b, s) rb_w32_write(f, b, s)
153 #define pread(f, b, s, o) rb_w32_pread(f, b, s, o)
154 #define pwrite(f, b, s, o) rb_w32_pwrite(f, b, s, o)
155 #define getpid() rb_w32_getpid()
157 #define HAVE_GETPPID 1
158 #define getppid() rb_w32_getppid()
159 #define sleep(x) rb_w32_Sleep((x)*1000)
160 #define Sleep(msec) (void)rb_w32_Sleep(msec)
165 #define execv(path,argv) rb_w32_uaspawn(P_OVERLAY,path,argv)
167 #define isatty(h) rb_w32_isatty(h)
170 #define mkdir(p, m) rb_w32_umkdir(p, m)
172 #define rmdir(p) rb_w32_urmdir(p)
174 #define unlink(p) rb_w32_uunlink(p)
180 unsigned __int64 st_ino;
182 unsigned short st_mode;
196 #define stat stati128
197 #undef SIZEOF_STRUCT_STAT_ST_INO
198 #define SIZEOF_STRUCT_STAT_ST_INO sizeof(unsigned __int64)
199 #define HAVE_STRUCT_STAT_ST_INOHIGH
200 #define HAVE_STRUCT_STAT_ST_ATIMENSEC
201 #define HAVE_STRUCT_STAT_ST_MTIMENSEC
202 #define HAVE_STRUCT_STAT_ST_CTIMENSEC
203 #define fstat(fd,st) rb_w32_fstati128(fd,st)
204 #define stati128(path, st) rb_w32_ustati128(path,st)
205 #define lstat(path,st) rb_w32_ulstati128(path,st)
206 #define access(path,mode) rb_w32_uaccess(path,mode)
208 #define strcasecmp _stricmp
209 #define strncasecmp _strnicmp
210 #define fsync _commit
216 #define isascii __isascii
226 struct iovec *msg_iov;
238 struct sockaddr *ifa_addr;
239 struct sockaddr *ifa_netmask;
240 struct sockaddr *ifa_broadaddr;
241 struct sockaddr *ifa_dstaddr;
245 #define IFNAMSIZ IF_NAMESIZE
249 #ifdef IFF_POINTTOPOINT
250 #define IFF_POINTOPOINT IFF_POINTTOPOINT
253 extern void rb_w32_sysinit(
int *,
char ***);
254 extern DWORD rb_w32_osid(
void);
255 extern int flock(
int fd,
int oper);
256 extern int rb_w32_io_cancelable_p(
int);
257 extern int rb_w32_is_socket(
int);
258 extern int WSAAPI rb_w32_accept(
int,
struct sockaddr *,
int *);
259 extern int WSAAPI rb_w32_bind(
int,
const struct sockaddr *,
int);
260 extern int WSAAPI rb_w32_connect(
int,
const struct sockaddr *,
int);
261 extern void rb_w32_fdset(
int, fd_set*);
262 extern void rb_w32_fdclr(
int, fd_set*);
263 extern int rb_w32_fdisset(
int, fd_set*);
264 extern int WSAAPI rb_w32_select(
int, fd_set *, fd_set *, fd_set *,
struct timeval *);
265 extern int WSAAPI rb_w32_getpeername(
int,
struct sockaddr *,
int *);
266 extern int WSAAPI rb_w32_getsockname(
int,
struct sockaddr *,
int *);
267 extern int WSAAPI rb_w32_getsockopt(
int,
int,
int,
char *,
int *);
268 extern int WSAAPI rb_w32_ioctlsocket(
int,
long, u_long *);
269 extern int WSAAPI rb_w32_listen(
int,
int);
270 extern int WSAAPI rb_w32_recv(
int,
char *,
int,
int);
271 extern int WSAAPI rb_w32_recvfrom(
int,
char *,
int,
int,
struct sockaddr *,
int *);
272 extern int WSAAPI rb_w32_send(
int,
const char *,
int,
int);
273 extern int WSAAPI rb_w32_sendto(
int,
const char *,
int,
int,
const struct sockaddr *,
int);
274 extern int recvmsg(
int,
struct msghdr *,
int);
275 extern int sendmsg(
int,
const struct msghdr *,
int);
276 extern int WSAAPI rb_w32_setsockopt(
int,
int,
int,
const char *,
int);
277 extern int WSAAPI rb_w32_shutdown(
int,
int);
278 extern int WSAAPI rb_w32_socket(
int,
int,
int);
279 extern SOCKET rb_w32_get_osfhandle(
int);
280 extern struct hostent *WSAAPI rb_w32_gethostbyaddr(
const char *,
int,
int);
281 extern struct hostent *WSAAPI rb_w32_gethostbyname(
const char *);
282 extern int WSAAPI rb_w32_gethostname(
char *,
int);
283 extern struct protoent *WSAAPI rb_w32_getprotobyname(
const char *);
284 extern struct protoent *WSAAPI rb_w32_getprotobynumber(
int);
285 extern struct servent *WSAAPI rb_w32_getservbyname(
const char *,
const char *);
286 extern struct servent *WSAAPI rb_w32_getservbyport(
int,
const char *);
287 extern int socketpair(
int,
int,
int,
int *);
288 extern int getifaddrs(
struct ifaddrs **);
289 extern void freeifaddrs(
struct ifaddrs *);
290 extern char * rb_w32_ugetcwd(
char *,
int);
291 extern char * rb_w32_ugetenv(
const char *);
292 extern int rb_w32_urename(
const char *,
const char *);
293 extern char **rb_w32_get_environ(
void);
294 extern void rb_w32_free_environ(
char **);
295 extern int rb_w32_map_errno(DWORD);
296 extern const char *WSAAPI rb_w32_inet_ntop(
int,
const void *,
char *,
size_t);
297 extern int WSAAPI rb_w32_inet_pton(
int,
const char *,
void *);
298 extern DWORD rb_w32_osver(
void);
300 extern int rb_w32_uchown(
const char *,
int,
int);
301 extern int rb_w32_ulink(
const char *,
const char *);
302 extern ssize_t rb_w32_ureadlink(
const char *,
char *,
size_t);
303 extern int rb_w32_usymlink(
const char *src,
const char *link);
305 extern int clock_gettime(clockid_t,
struct timespec *);
306 extern int clock_getres(clockid_t,
struct timespec *);
307 extern rb_pid_t waitpid(rb_pid_t,
int *,
int);
308 extern rb_pid_t wait(
int *);
309 extern rb_pid_t rb_w32_uspawn(
int,
const char *,
const char*);
310 extern rb_pid_t rb_w32_uaspawn(
int,
const char *,
char *
const *);
311 extern rb_pid_t rb_w32_uaspawn_flags(
int,
const char *,
char *
const *, DWORD);
314 extern int kill(rb_pid_t,
int);
315 extern int fcntl(
int,
int, ...);
316 extern int rb_w32_set_nonblock(
int);
317 extern rb_pid_t rb_w32_getpid(
void);
318 extern rb_pid_t rb_w32_getppid(
void);
319 extern int rb_w32_isatty(
int);
320 extern int rb_w32_uchdir(
const char *);
321 extern int rb_w32_umkdir(
const char *,
int);
322 extern int rb_w32_urmdir(
const char *);
323 extern int rb_w32_uunlink(
const char *);
324 extern int rb_w32_uchmod(
const char *,
int);
325 extern int rb_w32_ustati128(
const char *,
struct stati128 *);
326 extern int rb_w32_ulstati128(
const char *,
struct stati128 *);
327 extern int rb_w32_uaccess(
const char *,
int);
328 extern char rb_w32_fd_is_text(
int);
329 extern int rb_w32_fstati128(
int,
struct stati128 *);
330 extern int rb_w32_dup2(
int,
int);
334 #if defined _MSC_VER && _MSC_VER >= 1800 && defined INFINITY
335 #pragma warning(push)
336 #pragma warning(disable:4756)
338 rb_infinity_float(
void)
344 #define INFINITY rb_infinity_float()
347 #if !defined __MINGW32__ || defined __NO_ISOCEXT
349 #define copysign(a, b) _copysign(a, b)
352 scalb(
double a,
long b)
358 #if !defined S_IFIFO && defined _S_IFIFO
359 #define S_IFIFO _S_IFIFO
362 #if !defined S_IRUSR && !defined __MINGW32__
372 #if !defined S_IWUSR && !defined __MINGW32__
382 #if !defined S_IXUSR && !defined __MINGW32__
392 #define S_IFLNK 0xa000
393 #define S_IFSOCK 0xc000
401 extern int rb_w32_ftruncate(
int fd, rb_off_t length);
402 extern int rb_w32_truncate(
const char *path, rb_off_t length);
403 extern int rb_w32_utruncate(
const char *path, rb_off_t length);
405 #undef HAVE_FTRUNCATE
406 #define HAVE_FTRUNCATE 1
407 #if defined HAVE_FTRUNCATE64
408 #define ftruncate ftruncate64
410 #define ftruncate rb_w32_ftruncate
414 #define HAVE_TRUNCATE 1
415 #define truncate rb_w32_utruncate
417 #if defined(_MSC_VER) && _MSC_VER >= 1400 && _MSC_VER < 1800
418 #define strtoll _strtoi64
419 #define strtoull _strtoui64
425 extern int ioctl (
int,
int, ...);
426 extern rb_uid_t getuid (
void);
427 extern rb_uid_t geteuid (
void);
428 extern rb_gid_t getgid (
void);
429 extern rb_gid_t getegid (
void);
430 extern int setuid (rb_uid_t);
431 extern int setgid (rb_gid_t);
433 extern char *rb_w32_strerror(
int);
436 #define strerror(e) rb_w32_strerror(e)
439 #define PIPE_BUF 1024
462 # define EWOULDBLOCK WSAEWOULDBLOCK
465 # define EINPROGRESS WSAEINPROGRESS
468 # define EALREADY WSAEALREADY
471 # define ENOTSOCK WSAENOTSOCK
474 # define EDESTADDRREQ WSAEDESTADDRREQ
477 # define EMSGSIZE WSAEMSGSIZE
480 # define EPROTOTYPE WSAEPROTOTYPE
483 # define ENOPROTOOPT WSAENOPROTOOPT
485 #ifndef EPROTONOSUPPORT
486 # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
488 #ifndef ESOCKTNOSUPPORT
489 # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
492 # define EOPNOTSUPP WSAEOPNOTSUPP
495 # define EPFNOSUPPORT WSAEPFNOSUPPORT
498 # define EAFNOSUPPORT WSAEAFNOSUPPORT
501 # define EADDRINUSE WSAEADDRINUSE
503 #ifndef EADDRNOTAVAIL
504 # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
507 # define ENETDOWN WSAENETDOWN
510 # define ENETUNREACH WSAENETUNREACH
513 # define ENETRESET WSAENETRESET
516 # define ECONNABORTED WSAECONNABORTED
519 # define ECONNRESET WSAECONNRESET
522 # define ENOBUFS WSAENOBUFS
525 # define EISCONN WSAEISCONN
528 # define ENOTCONN WSAENOTCONN
531 # define ESHUTDOWN WSAESHUTDOWN
534 # define ETOOMANYREFS WSAETOOMANYREFS
537 # define ETIMEDOUT WSAETIMEDOUT
540 # define ECONNREFUSED WSAECONNREFUSED
543 # define ELOOP WSAELOOP
547 # define EHOSTDOWN WSAEHOSTDOWN
550 # define EHOSTUNREACH WSAEHOSTUNREACH
554 # define EPROCLIM WSAEPROCLIM
557 # define EUSERS WSAEUSERS
560 # define EDQUOT WSAEDQUOT
563 # define ESTALE WSAESTALE
566 # define EREMOTE WSAEREMOTE
576 #define F_DUPFD_CLOEXEC 67
581 #define FD_SET(fd, set) do {\
583 SOCKET s = _get_osfhandle(fd);\
585 for (i = 0; i < (set)->fd_count; i++) {\
586 if ((set)->fd_array[i] == s) {\
590 if (i == (set)->fd_count) {\
591 if ((set)->fd_count < FD_SETSIZE) {\
592 (set)->fd_array[i] = s;\
599 #define FD_CLR(f, s) rb_w32_fdclr(f, s)
602 #define FD_ISSET(f, s) rb_w32_fdisset(f, s)
606 #define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l)
609 #define inet_pton(f,s,d) rb_w32_inet_pton(f,s,d)
612 #define accept(s, a, l) rb_w32_accept(s, a, l)
615 #define bind(s, a, l) rb_w32_bind(s, a, l)
618 #define connect(s, a, l) rb_w32_connect(s, a, l)
621 #define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t)
624 #define getpeername(s, a, l) rb_w32_getpeername(s, a, l)
627 #define getsockname(s, a, l) rb_w32_getsockname(s, a, l)
630 #define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
633 #define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a)
636 #define listen(s, b) rb_w32_listen(s, b)
639 #define recv(s, b, l, f) rb_w32_recv(s, b, l, f)
642 #define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
645 #define send(s, b, l, f) rb_w32_send(s, b, l, f)
648 #define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
651 #define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
654 #define HAVE_SHUTDOWN 1
656 #define shutdown(s, h) rb_w32_shutdown(s, h)
659 #define socket(s, t, p) rb_w32_socket(s, t, p)
662 #define gethostbyaddr(a, l, t) rb_w32_gethostbyaddr(a, l, t)
665 #define gethostbyname(n) rb_w32_gethostbyname(n)
668 #define gethostname(n, l) rb_w32_gethostname(n, l)
670 #undef getprotobyname
671 #define getprotobyname(n) rb_w32_getprotobyname(n)
673 #undef getprotobynumber
674 #define getprotobynumber(n) rb_w32_getprotobynumber(n)
677 #define getservbyname(n, p) rb_w32_getservbyname(n, p)
680 #define getservbyport(p, pr) rb_w32_getservbyport(p, pr)
683 #define get_osfhandle(h) rb_w32_get_osfhandle(h)
686 #define getcwd(b, s) rb_w32_ugetcwd(b, s)
689 #define getenv(n) rb_w32_ugetenv(n)
692 #define rename(o, n) rb_w32_urename(o, n)
695 #define times(t) rb_w32_times(t)
698 #define dup2(o, n) rb_w32_dup2(o, n)
708 int rb_w32_times(
struct tms *);
710 struct tm *gmtime_r(
const time_t *,
struct tm *);
711 struct tm *localtime_r(
const time_t *,
struct tm *);
714 int rb_w32_sleep(
unsigned long msec);
715 int rb_w32_uopen(
const char *,
int, ...);
716 int rb_w32_wopen(
const WCHAR *,
int, ...);
717 int rb_w32_close(
int);
718 int rb_w32_fclose(
FILE*);
719 int rb_w32_pipe(
int[2]);
720 ssize_t rb_w32_read(
int,
void *,
size_t);
721 ssize_t rb_w32_write(
int,
const void *,
size_t);
722 ssize_t rb_w32_pread(
int,
void *,
size_t, rb_off_t offset);
723 ssize_t rb_w32_pwrite(
int,
const void *,
size_t, rb_off_t offset);
724 rb_off_t rb_w32_lseek(
int, rb_off_t,
int);
725 int rb_w32_uutime(
const char *,
const struct utimbuf *);
726 int rb_w32_uutimes(
const char *,
const struct timeval *);
727 int rb_w32_uutimensat(
int ,
const char *,
const struct timespec *,
int );
728 long rb_w32_write_console(uintptr_t,
int);
729 int WINAPI rb_w32_Sleep(
unsigned long msec);
730 int rb_w32_wait_events_blocking(HANDLE *events,
int num, DWORD timeout);
731 int rb_w32_time_subtract(
struct timeval *rest,
const struct timeval *wait);
732 int rb_w32_wrap_io_handle(HANDLE,
int);
733 int rb_w32_unwrap_io_handle(
int);
734 WCHAR *rb_w32_mbstr_to_wstr(UINT,
const char *,
int,
long *);
735 char *rb_w32_wstr_to_mbstr(UINT,
const WCHAR *,
int,
long *);
737 DEPRECATED_BY(rb_w32_ugetcwd,
char *rb_w32_getcwd(
char *,
int));
738 DEPRECATED_BY(rb_w32_ugetenv,
char *rb_w32_getenv(
const char *));
739 DEPRECATED_BY(rb_w32_urename,
int rb_w32_rename(
const char *,
const char *));
740 DEPRECATED_BY(rb_w32_uopen,
int rb_w32_open(
const char *,
int, ...));
741 DEPRECATED_BY(rb_w32_uchown,
int chown(
const char *,
int,
int));
742 DEPRECATED_BY(rb_w32_ulink,
int link(
const char *,
const char *));
743 DEPRECATED_BY(rb_w32_ureadlink, ssize_t readlink(
const char *,
char *,
size_t));
744 DEPRECATED_BY(rb_w32_usymlink,
int symlink(
const char *src,
const char *link));
745 DEPRECATED_BY(rb_w32_umkdir,
int rb_w32_mkdir(
const char *,
int));
746 DEPRECATED_BY(rb_w32_urmdir,
int rb_w32_rmdir(
const char *));
747 DEPRECATED_BY(rb_w32_uunlink,
int rb_w32_unlink(
const char *));
748 DEPRECATED_BY(rb_w32_uutime,
int rb_w32_utime(
const char *,
const struct utimbuf *));
749 DEPRECATED_BY(rb_w32_uutimes,
int rb_w32_utimes(
const char *,
const struct timeval *));
750 DEPRECATED_BY(rb_w32_uutimensat,
int rb_w32_utimensat(
int,
const char *,
const struct timespec *,
int));
751 DEPRECATED_BY(rb_w32_ustati128,
int rb_w32_stati128(
const char *,
struct stati128 *));
752 DEPRECATED_BY(rb_w32_ulstati128,
int rb_w32_lstati128(
const char *,
struct stati128 *));
753 DEPRECATED_BY(rb_w32_uaccess,
int rb_w32_access(
const char *,
int));
754 DEPRECATED_BY(rb_w32_uspawn, rb_pid_t rb_w32_spawn(
int,
const char *,
const char*));
755 DEPRECATED_BY(rb_w32_uaspawn, rb_pid_t rb_w32_aspawn(
int,
const char *,
char *
const *));
756 DEPRECATED_BY(rb_w32_uaspawn_flags, rb_pid_t rb_w32_aspawn_flags(
int,
const char *,
char *
const *, DWORD));
765 typedef uintptr_t (*asynchronous_func_t)(uintptr_t
self,
int argc, uintptr_t* argv);
766 uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t
self,
int argc, uintptr_t* argv, uintptr_t intrval);
768 RUBY_SYMBOL_EXPORT_END
770 #if (defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW64__)) && !defined(__cplusplus)
771 #ifdef RUBY_MINGW64_BROKEN_FREXP_MODF
774 #define frexp(_X, _Y) __extension__ ({\
775 int intpart_frexp_bug = intpart_frexp_bug;\
776 double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\
777 *(_Y) = intpart_frexp_bug;\
781 #define modf(_X, _Y) __extension__ ({\
782 double intpart_modf_bug = intpart_modf_bug;\
783 double result_modf_bug = modf((_X), &intpart_modf_bug);\
784 *(_Y) = intpart_modf_bug;\
789 #if defined(__MINGW64__)
796 rb_w32_pow(
double x,
double y)
798 return (
double)powl(x, y);
800 #elif defined(__MINGW64_VERSION_MAJOR)
801 double rb_w32_pow(
double x,
double y);
803 #define pow rb_w32_pow
807 #define MAP_FAILED ((void *)-1)
809 #define PROT_READ 0x01
810 #define PROT_WRITE 0x02
811 #define PROT_EXEC 0x04
813 #define MAP_PRIVATE 0x0002
814 #define MAP_ANON 0x1000
815 #define MAP_ANONYMOUS MAP_ANON
817 extern void *rb_w32_mmap(
void *,
size_t,
int,
int,
int, rb_off_t);
818 extern int rb_w32_munmap(
void *,
size_t);
819 extern int rb_w32_mprotect(
void *,
size_t,
int);
821 #define mmap(a, l, p, f, d, o) rb_w32_mmap(a, l, p, f, d, o)
822 #define munmap(a, l) rb_w32_munmap(a, l)
823 #define mprotect(a, l, prot) rb_w32_mprotect(a, l, prot)
825 #if defined(__cplusplus)