diff options
Diffstat (limited to 'include/ruby/win32.h')
| -rw-r--r-- | include/ruby/win32.h | 736 |
1 files changed, 506 insertions, 230 deletions
diff --git a/include/ruby/win32.h b/include/ruby/win32.h index 02021f19d9..ae11a61481 100644 --- a/include/ruby/win32.h +++ b/include/ruby/win32.h @@ -8,6 +8,8 @@ extern "C" { #endif #endif +RUBY_SYMBOL_EXPORT_BEGIN + /* * Copyright (c) 1993, Intergraph Corporation * @@ -16,40 +18,36 @@ extern "C" { * */ -// -// Definitions for NT port of Perl -// - - -// -// Ok now we can include the normal include files. -// +/* + * Ok now we can include the normal include files. + */ -// #include <stdarg.h> conflict with varargs.h? +/* #include <stdarg.h> conflict with varargs.h? */ #if !defined(WSAAPI) +#if defined(__cplusplus) && defined(_MSC_VER) +extern "C++" { /* template without extern "C++" */ +#endif +#if !defined(_WIN64) && !defined(WIN32) +#define WIN32 +#endif #include <winsock2.h> +#include <ws2tcpip.h> +#include <mswsock.h> +#include <iphlpapi.h> +#if defined(__cplusplus) && defined(_MSC_VER) +} #endif - -#define NT 1 /* deprecated */ - -#ifdef _WIN32_WCE -#undef CharNext -#define CharNext CharNextA #endif -// -// We're not using Microsoft's "extensions" to C for -// Structured Exception Handling (SEH) so we can nuke these -// +/* + * We're not using Microsoft's "extensions" to C for + * Structured Exception Handling (SEH) so we can nuke these + */ #undef try #undef except #undef finally #undef leave -#if defined(__cplusplus) -extern "C++" { -#endif - #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -67,7 +65,7 @@ extern "C++" { #endif #include <io.h> #include <malloc.h> -#ifdef __MINGW32__ +#if defined __MINGW32__ # include <stdint.h> #else # if !defined(_INTPTR_T_DEFINED) @@ -78,6 +76,14 @@ typedef int intptr_t; # endif # define _INTPTR_T_DEFINED # endif +# if !defined(INTPTR_MAX) +# ifdef _WIN64 +# define INTPTR_MAX 9223372036854775807I64 +# else +# define INTPTR_MAX 2147483647 +# endif +# define INTPTR_MIN (-INTPTR_MAX-1) +# endif # if !defined(_UINTPTR_T_DEFINED) # ifdef _WIN64 typedef unsigned __int64 uintptr_t; @@ -86,128 +92,178 @@ typedef unsigned int uintptr_t; # endif # define _UINTPTR_T_DEFINED # endif +# if !defined(UINTPTR_MAX) +# ifdef _WIN64 +# define UINTPTR_MAX 18446744073709551615UI64 +# else +# define UINTPTR_MAX 4294967295U +# endif +# endif #endif - -#if defined(__cplusplus) -} +#ifndef __MINGW32__ +# define mode_t int #endif - -#ifdef _M_IX86 -# define WIN95 1 -#else -# undef WIN95 +#ifdef HAVE_UNISTD_H +# include <unistd.h> #endif -#ifdef WIN95 -extern DWORD rb_w32_osid(void); -#define rb_w32_iswinnt() (rb_w32_osid() == VER_PLATFORM_WIN32_NT) -#define rb_w32_iswin95() (rb_w32_osid() == VER_PLATFORM_WIN32_WINDOWS) -#else #define rb_w32_iswinnt() TRUE #define rb_w32_iswin95() FALSE -#endif #define WNOHANG -1 -#undef getc -#undef putc -#undef fgetc -#undef fputc -#undef getchar -#undef putchar -#undef fgetchar -#undef fputchar +#define O_SHARE_DELETE 0x20000000 /* for rb_w32_open(), rb_w32_wopen() */ + +typedef int clockid_t; + +/* + * Since we use our versions in win32/win32.c, not to depend on yet + * another DLL, prefix our versions not to conflict with inline + * versions provided in time.h. + */ +#define clock_gettime rb_w32_clock_gettime +#define clock_getres rb_w32_clock_getres + +#ifndef CLOCK_REALTIME +# define CLOCK_REALTIME 0 +#endif +#ifndef CLOCK_MONOTONIC +# define CLOCK_MONOTONIC 1 +#endif +#ifndef CLOCK_PROCESS_CPUTIME_ID +# define CLOCK_PROCESS_CPUTIME_ID 2 +#endif +#ifndef CLOCK_THREAD_CPUTIME_ID +# define CLOCK_THREAD_CPUTIME_ID 3 +#endif +#ifndef CLOCK_REALTIME_COARSE +# define CLOCK_REALTIME_COARSE 4 +#endif + #undef utime #undef lseek +#undef stat #undef fstat -#define getc(_stream) rb_w32_getc(_stream) -#define getchar() rb_w32_getc(stdin) -#define putc(_c, _stream) rb_w32_putc(_c, _stream) -#define putchar(_c) rb_w32_putc(_c, stdout) #ifdef RUBY_EXPORT -#define fgetc(_stream) getc(_stream) -#define fputc(_c, _stream) putc(_c, _stream) -#define fgetchar() getchar() -#define fputchar(_c) putchar(_c) -#define utime(_p, _t) rb_w32_utime(_p, _t) -#define lseek(_f, _o, _w) _lseeki64(_f, _o, _w) - -#define pipe(p) _pipe(p, 2048L, O_BINARY) +#define utime(_p, _t) rb_w32_uutime(_p, _t) +#undef HAVE_UTIMES +#define HAVE_UTIMES 1 +#define utimes(_p, _t) rb_w32_uutimes(_p, _t) +#undef HAVE_UTIMENSAT +#define HAVE_UTIMENSAT 1 +#define AT_FDCWD -100 +#define utimensat(_d, _p, _t, _f) rb_w32_uutimensat(_d, _p, _t, _f) +#define lseek(_f, _o, _w) rb_w32_lseek(_f, _o, _w) + +#define pipe(p) rb_w32_pipe(p) +#define open rb_w32_uopen #define close(h) rb_w32_close(h) #define fclose(f) rb_w32_fclose(f) -#define read(f, b, s) rb_w32_read(f, b, s) -#define write(f, b, s) rb_w32_write(f, b, s) +#define read(f, b, s) rb_w32_read(f, b, s) +#define write(f, b, s) rb_w32_write(f, b, s) +#define pread(f, b, s, o) rb_w32_pread(f, b, s, o) +#define pwrite(f, b, s, o) rb_w32_pwrite(f, b, s, o) #define getpid() rb_w32_getpid() +#undef HAVE_GETPPID +#define HAVE_GETPPID 1 +#define getppid() rb_w32_getppid() #define sleep(x) rb_w32_Sleep((x)*1000) #define Sleep(msec) (void)rb_w32_Sleep(msec) -#define fstat(fd,st) _fstati64(fd,st) -#ifdef __BORLANDC__ -#define creat(p, m) _creat(p, m) -#define eof() _eof() -#define filelength(h) _filelength(h) -#define mktemp(t) _mktemp(t) -#define tell(h) _tell(h) -#define _open _sopen -#define sopen _sopen -#define _fstati64(fd,st) rb_w32_fstati64(fd,st) -#undef fopen -#define fopen(p, m) rb_w32_fopen(p, m) -#undef fdopen -#define fdopen(h, m) rb_w32_fdopen(h, m) -#undef fsopen -#define fsopen(p, m, sh) rb_w32_fsopen(p, m, sh) -#endif +#undef HAVE_EXECV +#define HAVE_EXECV 1 #undef execv -#define execv(path,argv) rb_w32_aspawn(P_OVERLAY,path,argv) -#if !defined(__BORLANDC__) && !defined(_WIN32_WCE) +#define execv(path,argv) rb_w32_uaspawn(P_OVERLAY,path,argv) #undef isatty #define isatty(h) rb_w32_isatty(h) -#endif #undef mkdir -#define mkdir(p, m) rb_w32_mkdir(p, m) +#define mkdir(p, m) rb_w32_umkdir(p, m) #undef rmdir -#define rmdir(p) rb_w32_rmdir(p) +#define rmdir(p) rb_w32_urmdir(p) #undef unlink -#define unlink(p) rb_w32_unlink(p) -#endif - -#if SIZEOF_OFF_T == 8 -#define off_t __int64 -#define stat stati64 -#if defined(__BORLANDC__) -#define stati64(path, st) rb_w32_stati64(path, st) -#elif !defined(_MSC_VER) || _MSC_VER < 1400 -#define stati64 _stati64 -#define _stati64(path, st) rb_w32_stati64(path, st) -#else -#define stati64 _stat64 -#define _stat64(path, st) rb_w32_stati64(path, st) -#endif -#else -#define stat(path,st) rb_w32_stat(path,st) -#define fstat(fd,st) rb_w32_fstat(fd,st) -extern int rb_w32_stat(const char *, struct stat *); -extern int rb_w32_fstat(int, struct stat *); -#endif +#define unlink(p) rb_w32_uunlink(p) +#endif /* RUBY_EXPORT */ + +/* same with stati64 except the size of st_ino and nanosecond timestamps */ +struct stati128 { + _dev_t st_dev; + unsigned __int64 st_ino; + __int64 st_inohigh; + unsigned short st_mode; + short st_nlink; + short st_uid; + short st_gid; + _dev_t st_rdev; + __int64 st_size; + __time64_t st_atime; + long st_atimensec; + __time64_t st_mtime; + long st_mtimensec; + __time64_t st_ctime; + long st_ctimensec; +}; -#define strcasecmp stricmp -#define strncasecmp strnicmp +#define stat stati128 +#undef SIZEOF_STRUCT_STAT_ST_INO +#define SIZEOF_STRUCT_STAT_ST_INO sizeof(unsigned __int64) +#define HAVE_STRUCT_STAT_ST_INOHIGH +#define HAVE_STRUCT_STAT_ST_ATIMENSEC +#define HAVE_STRUCT_STAT_ST_MTIMENSEC +#define HAVE_STRUCT_STAT_ST_CTIMENSEC +#define fstat(fd,st) rb_w32_fstati128(fd,st) +#define stati128(path, st) rb_w32_ustati128(path,st) +#define lstat(path,st) rb_w32_ulstati128(path,st) +#define access(path,mode) rb_w32_uaccess(path,mode) + +#define strcasecmp _stricmp +#define strncasecmp _strnicmp #define fsync _commit +struct timezone; + #ifdef __MINGW32__ -struct timezone { - int tz_minuteswest; - int tz_dsttime; -}; #undef isascii #define isascii __isascii #endif -#define NtInitialize ruby_sysinit -extern int rb_w32_cmdvector(const char *, char ***); -extern rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int *); + +struct iovec { + void *iov_base; + size_t iov_len; +}; +struct msghdr { + void *msg_name; + int msg_namelen; + struct iovec *msg_iov; + int msg_iovlen; + void *msg_control; + int msg_controllen; + int msg_flags; +}; + +/* for getifaddrs() and others */ +struct ifaddrs { + struct ifaddrs *ifa_next; + char *ifa_name; + u_int ifa_flags; + struct sockaddr *ifa_addr; + struct sockaddr *ifa_netmask; + struct sockaddr *ifa_broadaddr; + struct sockaddr *ifa_dstaddr; + void *ifa_data; +}; +#ifdef IF_NAMESIZE +#define IFNAMSIZ IF_NAMESIZE +#else +#define IFNAMSIZ 256 +#endif +#ifdef IFF_POINTTOPOINT +#define IFF_POINTOPOINT IFF_POINTTOPOINT +#endif + +extern void rb_w32_sysinit(int *, char ***); extern int flock(int fd, int oper); +extern int rb_w32_io_cancelable_p(int); extern int rb_w32_is_socket(int); extern int WSAAPI rb_w32_accept(int, struct sockaddr *, int *); extern int WSAAPI rb_w32_bind(int, const struct sockaddr *, int); @@ -225,6 +281,8 @@ extern int WSAAPI rb_w32_recv(int, char *, int, int); extern int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *); extern int WSAAPI rb_w32_send(int, const char *, int, int); extern int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int); +extern int recvmsg(int, struct msghdr *, int); +extern int sendmsg(int, const struct msghdr *, int); extern int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int); extern int WSAAPI rb_w32_shutdown(int, int); extern int WSAAPI rb_w32_socket(int, int, int); @@ -236,78 +294,85 @@ extern struct protoent *WSAAPI rb_w32_getprotobyname(const char *); extern struct protoent *WSAAPI rb_w32_getprotobynumber(int); extern struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *); extern struct servent *WSAAPI rb_w32_getservbyport(int, const char *); -extern int rb_w32_socketpair(int, int, int, int *); -extern char * rb_w32_getcwd(char *, int); -extern char * rb_w32_getenv(const char *); -extern int rb_w32_rename(const char *, const char *); +extern int socketpair(int, int, int, int *); +extern int getifaddrs(struct ifaddrs **); +extern void freeifaddrs(struct ifaddrs *); +extern char * rb_w32_ugetcwd(char *, int); +extern char * rb_w32_ugetenv(const char *); +extern int rb_w32_urename(const char *, const char *); extern char **rb_w32_get_environ(void); extern void rb_w32_free_environ(char **); - -#define vsnprintf(s,n,f,l) rb_w32_vsnprintf(s,n,f,l) -#define snprintf rb_w32_snprintf -extern int rb_w32_vsnprintf(char *, size_t, const char *, va_list); -extern int rb_w32_snprintf(char *, size_t, const char *, ...); - -extern int chown(const char *, int, int); -extern int link(const char *, const char *); +extern int rb_w32_map_errno(DWORD); +extern const char *WSAAPI rb_w32_inet_ntop(int,const void *,char *,size_t); +extern int WSAAPI rb_w32_inet_pton(int,const char *,void *); + +RBIMPL_ATTR_DEPRECATED(("as Windows 9x is not supported already")) +static inline DWORD rb_w32_osid(void) {return VER_PLATFORM_WIN32_NT;} +RBIMPL_ATTR_DEPRECATED(("by Windows Version Helper APIs")) +extern DWORD rb_w32_osver(void); + +extern int rb_w32_uchown(const char *, int, int); +extern int rb_w32_ulink(const char *, const char *); +extern ssize_t rb_w32_ureadlink(const char *, char *, size_t); +extern int rb_w32_usymlink(const char *src, const char *link); extern int gettimeofday(struct timeval *, struct timezone *); -extern rb_pid_t waitpid (rb_pid_t, int *, int); -extern int rb_w32_argv_size(char *const *); -extern char *rb_w32_join_argv(char *, char *const *); -extern rb_pid_t rb_w32_spawn(int, const char *, const char*); -extern rb_pid_t rb_w32_aspawn(int, const char *, char *const *); -extern int kill(int, int); +extern int clock_gettime(clockid_t, struct timespec *); +extern int clock_getres(clockid_t, struct timespec *); +extern rb_pid_t waitpid(rb_pid_t, int *, int); +extern rb_pid_t wait(int *); +extern rb_pid_t rb_w32_uspawn(int, const char *, const char*); +extern rb_pid_t rb_w32_uaspawn(int, const char *, char *const *); +extern rb_pid_t rb_w32_uaspawn_flags(int, const char *, char *const *, DWORD); +#undef HAVE_KILL +#define HAVE_KILL 1 +extern int kill(rb_pid_t, int); extern int fcntl(int, int, ...); +extern int rb_w32_set_nonblock(int); extern rb_pid_t rb_w32_getpid(void); -#if !defined(__BORLANDC__) && !defined(_WIN32_WCE) +extern rb_pid_t rb_w32_getppid(void); extern int rb_w32_isatty(int); -#endif -extern int rb_w32_mkdir(const char *, int); -extern int rb_w32_rmdir(const char *); -extern int rb_w32_unlink(const char *); -extern int rb_w32_stati64(const char *, struct stati64 *); +extern int rb_w32_uchdir(const char *); +extern int rb_w32_umkdir(const char *, int); +extern int rb_w32_urmdir(const char *); +extern int rb_w32_uunlink(const char *); +extern int rb_w32_uchmod(const char *, int); +extern int rb_w32_ustati128(const char *, struct stati128 *); +extern int rb_w32_ulstati128(const char *, struct stati128 *); +extern int rb_w32_uaccess(const char *, int); +extern char rb_w32_fd_is_text(int); +extern int rb_w32_fstati128(int, struct stati128 *); +extern int rb_w32_dup2(int, int); + +#include <float.h> -#ifdef __BORLANDC__ -extern int rb_w32_fstati64(int, struct stati64 *); -extern off_t _lseeki64(int, off_t, int); -extern FILE *rb_w32_fopen(const char *, const char *); -extern FILE *rb_w32_fdopen(int, const char *); -extern FILE *rb_w32_fsopen(const char *, const char *, int); +#if defined _MSC_VER && defined INFINITY +#pragma warning(push) +#pragma warning(disable:4756) +static inline float +rb_infinity_float(void) +{ + return INFINITY; +} +#pragma warning(pop) +#undef INFINITY +#define INFINITY rb_infinity_float() #endif -#include <float.h> #if !defined __MINGW32__ || defined __NO_ISOCEXT -#ifndef isnan -#define isnan(x) _isnan(x) -#endif -#ifndef finite -#define finite(x) _finite(x) -#endif #ifndef copysign #define copysign(a, b) _copysign(a, b) #endif -#ifndef scalb -#define scalb(a, b) _scalb(a, b) -#endif +static inline double +scalb(double a, long b) +{ + return _scalb(a, b); +} #endif #if !defined S_IFIFO && defined _S_IFIFO #define S_IFIFO _S_IFIFO #endif -#if 0 && defined __BORLANDC__ -#undef S_ISDIR -#undef S_ISFIFO -#undef S_ISBLK -#undef S_ISCHR -#undef S_ISREG -#define S_ISDIR(m) (((unsigned short)(m) & S_IFMT) == S_IFDIR) -#define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO) -#define S_ISBLK(m) (((unsigned short)(m) & S_IFMT) == S_IFBLK) -#define S_ISCHR(m) (((unsigned short)(m) & S_IFMT) == S_IFCHR) -#define S_ISREG(m) (((unsigned short)(m) & S_IFMT) == S_IFREG) -#endif - #if !defined S_IRUSR && !defined __MINGW32__ #define S_IRUSR 0400 #endif @@ -338,19 +403,34 @@ extern FILE *rb_w32_fsopen(const char *, const char *, int); #define S_IXOTH 0001 #endif -// -// define this so we can do inplace editing -// +#define S_IFLNK 0xa000 +#define S_IFSOCK 0xc000 + +/* + * define this so we can do inplace editing + */ #define SUFFIX -extern int truncate(const char *path, off_t length); -extern int ftruncate(int fd, off_t length); -extern int fseeko(FILE *stream, off_t offset, int whence); -extern off_t ftello(FILE *stream); - -// -// stubs -// + +extern int rb_w32_ftruncate(int fd, rb_off_t length); +extern int rb_w32_truncate(const char *path, rb_off_t length); +extern int rb_w32_utruncate(const char *path, rb_off_t length); + +#undef HAVE_FTRUNCATE +#define HAVE_FTRUNCATE 1 +#if defined HAVE_FTRUNCATE64 +#define ftruncate ftruncate64 +#else +#define ftruncate rb_w32_ftruncate +#endif + +#undef HAVE_TRUNCATE +#define HAVE_TRUNCATE 1 +#define truncate rb_w32_utruncate + +/* + * stubs + */ extern int ioctl (int, int, ...); extern rb_uid_t getuid (void); extern rb_uid_t geteuid (void); @@ -385,49 +465,144 @@ extern char *rb_w32_strerror(int); /* #undef va_end */ /* winsock error map */ -#define EWOULDBLOCK WSAEWOULDBLOCK -#define EINPROGRESS WSAEINPROGRESS -#define EALREADY WSAEALREADY -#define ENOTSOCK WSAENOTSOCK -#define EDESTADDRREQ WSAEDESTADDRREQ -#define EMSGSIZE WSAEMSGSIZE -#define EPROTOTYPE WSAEPROTOTYPE -#define ENOPROTOOPT WSAENOPROTOOPT -#define EPROTONOSUPPORT WSAEPROTONOSUPPORT -#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT -#define EOPNOTSUPP WSAEOPNOTSUPP -#define EPFNOSUPPORT WSAEPFNOSUPPORT -#define EAFNOSUPPORT WSAEAFNOSUPPORT -#define EADDRINUSE WSAEADDRINUSE -#define EADDRNOTAVAIL WSAEADDRNOTAVAIL -#define ENETDOWN WSAENETDOWN -#define ENETUNREACH WSAENETUNREACH -#define ENETRESET WSAENETRESET -#define ECONNABORTED WSAECONNABORTED -#define ECONNRESET WSAECONNRESET -#define ENOBUFS WSAENOBUFS -#define EISCONN WSAEISCONN -#define ENOTCONN WSAENOTCONN -#define ESHUTDOWN WSAESHUTDOWN -#define ETOOMANYREFS WSAETOOMANYREFS -#define ETIMEDOUT WSAETIMEDOUT -#define ECONNREFUSED WSAECONNREFUSED -#define ELOOP WSAELOOP +#include <errno.h> + +#ifndef EWOULDBLOCK +# define EWOULDBLOCK WSAEWOULDBLOCK +#endif +#ifndef EINPROGRESS +# define EINPROGRESS WSAEINPROGRESS +#endif +#ifndef EALREADY +# define EALREADY WSAEALREADY +#endif +#ifndef ENOTSOCK +# define ENOTSOCK WSAENOTSOCK +#endif +#ifndef EDESTADDRREQ +# define EDESTADDRREQ WSAEDESTADDRREQ +#endif +#ifndef EMSGSIZE +# define EMSGSIZE WSAEMSGSIZE +#endif +#ifndef EPROTOTYPE +# define EPROTOTYPE WSAEPROTOTYPE +#endif +#ifndef ENOPROTOOPT +# define ENOPROTOOPT WSAENOPROTOOPT +#endif +#ifndef EPROTONOSUPPORT +# define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#endif +#ifndef ESOCKTNOSUPPORT +# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT +#endif +#ifndef EOPNOTSUPP +# define EOPNOTSUPP WSAEOPNOTSUPP +#endif +#ifndef EPFNOSUPPORT +# define EPFNOSUPPORT WSAEPFNOSUPPORT +#endif +#ifndef EAFNOSUPPORT +# define EAFNOSUPPORT WSAEAFNOSUPPORT +#endif +#ifndef EADDRINUSE +# define EADDRINUSE WSAEADDRINUSE +#endif +#ifndef EADDRNOTAVAIL +# define EADDRNOTAVAIL WSAEADDRNOTAVAIL +#endif +#ifndef ENETDOWN +# define ENETDOWN WSAENETDOWN +#endif +#ifndef ENETUNREACH +# define ENETUNREACH WSAENETUNREACH +#endif +#ifndef ENETRESET +# define ENETRESET WSAENETRESET +#endif +#ifndef ECONNABORTED +# define ECONNABORTED WSAECONNABORTED +#endif +#ifndef ECONNRESET +# define ECONNRESET WSAECONNRESET +#endif +#ifndef ENOBUFS +# define ENOBUFS WSAENOBUFS +#endif +#ifndef EISCONN +# define EISCONN WSAEISCONN +#endif +#ifndef ENOTCONN +# define ENOTCONN WSAENOTCONN +#endif +#ifndef ESHUTDOWN +# define ESHUTDOWN WSAESHUTDOWN +#endif +#ifndef ETOOMANYREFS +# define ETOOMANYREFS WSAETOOMANYREFS +#endif +#ifndef ETIMEDOUT +# define ETIMEDOUT WSAETIMEDOUT +#endif +#ifndef ECONNREFUSED +# define ECONNREFUSED WSAECONNREFUSED +#endif +#ifndef ELOOP +# define ELOOP WSAELOOP +#endif /*#define ENAMETOOLONG WSAENAMETOOLONG*/ -#define EHOSTDOWN WSAEHOSTDOWN -#define EHOSTUNREACH WSAEHOSTUNREACH +#ifndef EHOSTDOWN +# define EHOSTDOWN WSAEHOSTDOWN +#endif +#ifndef EHOSTUNREACH +# define EHOSTUNREACH WSAEHOSTUNREACH +#endif /*#define ENOTEMPTY WSAENOTEMPTY*/ -#define EPROCLIM WSAEPROCLIM -#define EUSERS WSAEUSERS -#define EDQUOT WSAEDQUOT -#define ESTALE WSAESTALE -#define EREMOTE WSAEREMOTE +#ifndef EPROCLIM +# define EPROCLIM WSAEPROCLIM +#endif +#ifndef EUSERS +# define EUSERS WSAEUSERS +#endif +#ifndef EDQUOT +# define EDQUOT WSAEDQUOT +#endif +#ifndef ESTALE +# define ESTALE WSAESTALE +#endif +#ifndef EREMOTE +# define EREMOTE WSAEREMOTE +#endif -#define F_SETFL 1 +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#if 0 +#define F_GETFL 3 +#endif +#define F_SETFL 4 +#define F_DUPFD_CLOEXEC 67 +#define FD_CLOEXEC 1 /* F_GETFD, F_SETFD */ #define O_NONBLOCK 1 #undef FD_SET -#define FD_SET(f, s) rb_w32_fdset(f, s) +#define FD_SET(fd, set) do {\ + unsigned int i;\ + SOCKET s = _get_osfhandle(fd);\ +\ + for (i = 0; i < (set)->fd_count; i++) {\ + if ((set)->fd_array[i] == s) {\ + break;\ + }\ + }\ + if (i == (set)->fd_count) {\ + if ((set)->fd_count < FD_SETSIZE) {\ + (set)->fd_array[i] = s;\ + (set)->fd_count++;\ + }\ + }\ +} while(0) #undef FD_CLR #define FD_CLR(f, s) rb_w32_fdclr(f, s) @@ -436,6 +611,12 @@ extern char *rb_w32_strerror(int); #define FD_ISSET(f, s) rb_w32_fdisset(f, s) #ifdef RUBY_EXPORT +#undef inet_ntop +#define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l) + +#undef inet_pton +#define inet_pton(f,s,d) rb_w32_inet_pton(f,s,d) + #undef accept #define accept(s, a, l) rb_w32_accept(s, a, l) @@ -478,6 +659,8 @@ extern char *rb_w32_strerror(int); #undef setsockopt #define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l) +#undef HAVE_SHUTDOWN +#define HAVE_SHUTDOWN 1 #undef shutdown #define shutdown(s, h) rb_w32_shutdown(s, h) @@ -505,56 +688,149 @@ extern char *rb_w32_strerror(int); #undef getservbyport #define getservbyport(p, pr) rb_w32_getservbyport(p, pr) -#undef socketpair -#define socketpair(a, t, p, s) rb_w32_socketpair(a, t, p, s) - #undef get_osfhandle #define get_osfhandle(h) rb_w32_get_osfhandle(h) #undef getcwd -#define getcwd(b, s) rb_w32_getcwd(b, s) +#define getcwd(b, s) rb_w32_ugetcwd(b, s) #undef getenv -#define getenv(n) rb_w32_getenv(n) +#define getenv(n) rb_w32_ugetenv(n) #undef rename -#define rename(o, n) rb_w32_rename(o, n) +#define rename(o, n) rb_w32_urename(o, n) #undef times #define times(t) rb_w32_times(t) + +#undef dup2 +#define dup2(o, n) rb_w32_dup2(o, n) #endif struct tms { - long tms_utime; - long tms_stime; - long tms_cutime; - long tms_cstime; + long tms_utime; + long tms_stime; + long tms_cutime; + long tms_cstime; }; int rb_w32_times(struct tms *); +struct tm *gmtime_r(const time_t *, struct tm *); +struct tm *localtime_r(const time_t *, struct tm *); + /* thread stuff */ -HANDLE GetCurrentThreadHandle(void); int rb_w32_sleep(unsigned long msec); -int rb_w32_putc(int, FILE*); -int rb_w32_getc(FILE*); +int rb_w32_uopen(const char *, int, ...); +int rb_w32_wopen(const WCHAR *, int, ...); int rb_w32_close(int); int rb_w32_fclose(FILE*); -size_t rb_w32_read(int, void *, size_t); -size_t rb_w32_write(int, const void *, size_t); -int rb_w32_utime(const char *, const struct utimbuf *); +int rb_w32_pipe(int[2]); +ssize_t rb_w32_read(int, void *, size_t); +ssize_t rb_w32_write(int, const void *, size_t); +ssize_t rb_w32_pread(int, void *, size_t, rb_off_t offset); +ssize_t rb_w32_pwrite(int, const void *, size_t, rb_off_t offset); +rb_off_t rb_w32_lseek(int, rb_off_t, int); +int rb_w32_uutime(const char *, const struct utimbuf *); +int rb_w32_uutimes(const char *, const struct timeval *); +int rb_w32_uutimensat(int /* must be AT_FDCWD */, const char *, const struct timespec *, int /* must be 0 */); +long rb_w32_write_console(uintptr_t, int); /* use uintptr_t instead of VALUE because it's not defined yet here */ int WINAPI rb_w32_Sleep(unsigned long msec); +int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout); +int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait); +int rb_w32_wrap_io_handle(HANDLE, int); +int rb_w32_unwrap_io_handle(int); +WCHAR *rb_w32_mbstr_to_wstr(UINT, const char *, int, long *); +char *rb_w32_wstr_to_mbstr(UINT, const WCHAR *, int, long *); + +DEPRECATED_BY(rb_w32_ugetcwd, char *rb_w32_getcwd(char *, int)); +DEPRECATED_BY(rb_w32_ugetenv, char *rb_w32_getenv(const char *)); +DEPRECATED_BY(rb_w32_urename, int rb_w32_rename(const char *, const char *)); +DEPRECATED_BY(rb_w32_uopen, int rb_w32_open(const char *, int, ...)); +DEPRECATED_BY(rb_w32_uchown, int chown(const char *, int, int)); +DEPRECATED_BY(rb_w32_ulink, int link(const char *, const char *)); +DEPRECATED_BY(rb_w32_ureadlink, ssize_t readlink(const char *, char *, size_t)); +DEPRECATED_BY(rb_w32_usymlink, int symlink(const char *src, const char *link)); +DEPRECATED_BY(rb_w32_umkdir, int rb_w32_mkdir(const char *, int)); +DEPRECATED_BY(rb_w32_urmdir, int rb_w32_rmdir(const char *)); +DEPRECATED_BY(rb_w32_uunlink, int rb_w32_unlink(const char *)); +DEPRECATED_BY(rb_w32_uutime, int rb_w32_utime(const char *, const struct utimbuf *)); +DEPRECATED_BY(rb_w32_uutimes, int rb_w32_utimes(const char *, const struct timeval *)); +DEPRECATED_BY(rb_w32_uutimensat, int rb_w32_utimensat(int, const char *, const struct timespec *, int)); +DEPRECATED_BY(rb_w32_ustati128, int rb_w32_stati128(const char *, struct stati128 *)); +DEPRECATED_BY(rb_w32_ulstati128, int rb_w32_lstati128(const char *, struct stati128 *)); +DEPRECATED_BY(rb_w32_uaccess, int rb_w32_access(const char *, int)); +DEPRECATED_BY(rb_w32_uspawn, rb_pid_t rb_w32_spawn(int, const char *, const char*)); +DEPRECATED_BY(rb_w32_uaspawn, rb_pid_t rb_w32_aspawn(int, const char *, char *const *)); +DEPRECATED_BY(rb_w32_uaspawn_flags, rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD)); /* == ***CAUTION*** Since this function is very dangerous, ((*NEVER*)) * lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or, -* use anything like TRAP_BEG...TRAP_END block structure, +* use anything like rb_thread_call_without_gvl, in asynchronous_func_t. */ typedef uintptr_t (*asynchronous_func_t)(uintptr_t self, int argc, uintptr_t* argv); uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t* argv, uintptr_t intrval); +RUBY_SYMBOL_EXPORT_END + +#if (defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW64__)) && !defined(__cplusplus) +#ifdef RUBY_MINGW64_BROKEN_FREXP_MODF +/* License: Ruby's */ +/* get rid of bugs in math.h of mingw */ +#define frexp(_X, _Y) __extension__ ({\ + int intpart_frexp_bug = intpart_frexp_bug;\ + double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\ + *(_Y) = intpart_frexp_bug;\ + result_frexp_bug;\ +}) +/* License: Ruby's */ +#define modf(_X, _Y) __extension__ ({\ + double intpart_modf_bug = intpart_modf_bug;\ + double result_modf_bug = modf((_X), &intpart_modf_bug);\ + *(_Y) = intpart_modf_bug;\ + result_modf_bug;\ +}) +#endif + +#if defined(__MINGW64__) +/* + * Use powl() instead of broken pow() of x86_64-w64-mingw32. + * This workaround will fix test failures in test_bignum.rb, + * test_fixnum.rb and test_float.rb etc. + */ +static inline double +rb_w32_pow(double x, double y) +{ + return (double)powl(x, y); +} +#elif defined(__MINGW64_VERSION_MAJOR) +double rb_w32_pow(double x, double y); +#endif +#define pow rb_w32_pow +#endif + +// mmap tiny emulation +#define MAP_FAILED ((void *)-1) + +#define PROT_READ 0x01 +#define PROT_WRITE 0x02 +#define PROT_EXEC 0x04 + +#define MAP_PRIVATE 0x0002 +#define MAP_ANON 0x1000 +#define MAP_ANONYMOUS MAP_ANON + +extern void *rb_w32_mmap(void *, size_t, int, int, int, rb_off_t); +extern int rb_w32_munmap(void *, size_t); +extern int rb_w32_mprotect(void *, size_t, int); + +#define mmap(a, l, p, f, d, o) rb_w32_mmap(a, l, p, f, d, o) +#define munmap(a, l) rb_w32_munmap(a, l) +#define mprotect(a, l, prot) rb_w32_mprotect(a, l, prot) + #if defined(__cplusplus) #if 0 { /* satisfy cc-mode */ |
