Ruby: include/ruby/win32.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

win32.h
Go to the documentation of this file.
1#ifndef RUBY_WIN32_H
2#define RUBY_WIN32_H 1
3
4#if defined(__cplusplus)
5extern "C" {
6#if 0
7} /* satisfy cc-mode */
8#endif
9#endif
10
11RUBY_SYMBOL_EXPORT_BEGIN
12
13/*
14 * Copyright (c) 1993, Intergraph Corporation
15 *
16 * You may distribute under the terms of either the GNU General Public
17 * License or the Artistic License, as specified in the perl README file.
18 *
19 */
20
21/*
22 * Definitions for NT port of Perl
23 */
24
25
26/*
27 * Ok now we can include the normal include files.
28 */
29
30/* #include <stdarg.h> conflict with varargs.h? */
31#if !defined(WSAAPI)
32#if defined(__cplusplus) && defined(_MSC_VER)
33extern "C++" { /* template without extern "C++" */
34#endif
35#if !defined(_WIN64) && !defined(WIN32)
36#define WIN32
37#endif
38#if defined(_MSC_VER) && _MSC_VER <= 1200
39#include <windows.h>
40#endif
41#include <winsock2.h>
42#include <ws2tcpip.h>
43#if !defined(_MSC_VER) || _MSC_VER >= 1400
44#include <iphlpapi.h>
45#endif
46#if defined(__cplusplus) && defined(_MSC_VER)
47}
48#endif
49#endif
50
51/*
52 * We're not using Microsoft's "extensions" to C for
53 * Structured Exception Handling (SEH) so we can nuke these
54 */
55#undef try
56#undef except
57#undef finally
58#undef leave
59
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <direct.h>
64#include <process.h>
65#include <time.h>
66#if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
67extern "C++" { /* template without extern "C++" */
68#endif
69#include <math.h>
70#if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
71}
72#endif
73#include <signal.h>
74#include <sys/stat.h>
75#include <sys/types.h>
76#ifdef HAVE_SYS_UTIME_H
77# include <sys/utime.h>
78#else
79# include <utime.h>
80#endif
81#include <io.h>
82#include <malloc.h>
83#if defined __MINGW32__
84# include <stdint.h>
85#else
86# if !defined(_INTPTR_T_DEFINED)
87# ifdef _WIN64
88typedef __int64 intptr_t;
89# else
90 typedef int intptr_t;
91# endif
92# define _INTPTR_T_DEFINED
93# endif
94# if !defined(INTPTR_MAX)
95# ifdef _WIN64
96# define INTPTR_MAX 9223372036854775807I64
97# else
98# define INTPTR_MAX 2147483647
99# endif
100# define INTPTR_MIN (-INTPTR_MAX-1)
101# endif
102# if !defined(_UINTPTR_T_DEFINED)
103# ifdef _WIN64
104typedef unsigned __int64 uintptr_t;
105# else
106 typedef unsigned int uintptr_t;
107# endif
108# define _UINTPTR_T_DEFINED
109# endif
110# if !defined(UINTPTR_MAX)
111# ifdef _WIN64
112# define UINTPTR_MAX 18446744073709551615UI64
113# else
114# define UINTPTR_MAX 4294967295U
115# endif
116# endif
117#endif
118#ifndef __MINGW32__
119# define mode_t int
120#endif
121#ifdef HAVE_UNISTD_H
122# include <unistd.h>
123#endif
124
125#define rb_w32_iswinnt() TRUE
126#define rb_w32_iswin95() FALSE
127
128#define WNOHANG -1
129
130#define O_SHARE_DELETE 0x20000000 /* for rb_w32_open(), rb_w32_wopen() */
131
132 typedef int clockid_t;
133#define CLOCK_REALTIME 0
134#define CLOCK_MONOTONIC 1
135
136#undef utime
137#undef lseek
138#undef stat
139#undef fstat
140#ifdef RUBY_EXPORT
141#define utime(_p, _t) rb_w32_uutime(_p, _t)
142#undef HAVE_UTIMES
143#define HAVE_UTIMES 1
144#define utimes(_p, _t) rb_w32_uutimes(_p, _t)
145#undef HAVE_UTIMENSAT
146#define HAVE_UTIMENSAT 1
147#define AT_FDCWD -100
148#define utimensat(_d, _p, _t, _f) rb_w32_uutimensat(_d, _p, _t, _f)
149#define lseek(_f, _o, _w) rb_w32_lseek(_f, _o, _w)
150
151#define pipe(p) rb_w32_pipe(p)
152#define open rb_w32_uopen
153#define close(h) rb_w32_close(h)
154#define fclose(f) rb_w32_fclose(f)
155#define read(f, b, s) rb_w32_read(f, b, s)
156#define write(f, b, s) rb_w32_write(f, b, s)
157#define getpid() rb_w32_getpid()
158#define getppid() rb_w32_getppid()
159#define sleep(x) rb_w32_Sleep((x)*1000)
160#define Sleep(msec) (void)rb_w32_Sleep(msec)
161
162#undef execv
163#define execv(path,argv) rb_w32_uaspawn(P_OVERLAY,path,argv)
164#undef isatty
165#define isatty(h) rb_w32_isatty(h)
166
167#undef mkdir
168#define mkdir(p, m) rb_w32_umkdir(p, m)
169#undef rmdir
170#define rmdir(p) rb_w32_urmdir(p)
171#undef unlink
172#define unlink(p) rb_w32_uunlink(p)
173#endif /* RUBY_EXPORT */
174
175/* same with stati64 except the size of st_ino and nanosecond timestamps */
176 struct stati128 {
177 _dev_t st_dev;
178 unsigned __int64 st_ino;
179 __int64 st_inohigh;
180 unsigned short st_mode;
181 short st_nlink;
182 short st_uid;
183 short st_gid;
184 _dev_t st_rdev;
185 __int64 st_size;
186 __time64_t st_atime;
187 long st_atimensec;
188 __time64_t st_mtime;
189 long st_mtimensec;
190 __time64_t st_ctime;
191 long st_ctimensec;
192};
193
194#define off_t __int64
195#define stat stati128
196#undef SIZEOF_STRUCT_STAT_ST_INO
197#define SIZEOF_STRUCT_STAT_ST_INO sizeof(unsigned __int64)
198#define HAVE_STRUCT_STAT_ST_INOHIGH
199#define HAVE_STRUCT_STAT_ST_ATIMENSEC
200#define HAVE_STRUCT_STAT_ST_MTIMENSEC
201#define HAVE_STRUCT_STAT_ST_CTIMENSEC
202#define fstat(fd,st) rb_w32_fstati128(fd,st)
203#define stati128(path, st) rb_w32_ustati128(path,st)
204#define lstat(path,st) rb_w32_ulstati128(path,st)
205#define access(path,mode) rb_w32_uaccess(path,mode)
206
207#define strcasecmp _stricmp
208#define strncasecmp _strnicmp
209#define fsync _commit
210
211struct timezone;
212
213#ifdef __MINGW32__
214#undef isascii
215#define isascii __isascii
216#endif
217
218 struct iovec {
219 void *iov_base;
220 size_t iov_len;
221};
222 struct msghdr {
223 void *msg_name;
224 int msg_namelen;
225 struct iovec *msg_iov;
226 int msg_iovlen;
227 void *msg_control;
228 int msg_controllen;
229 int msg_flags;
230};
231
232/* for getifaddrs() and others */
233 struct ifaddrs {
234 struct ifaddrs *ifa_next;
235 char *ifa_name;
236 u_int ifa_flags;
237 struct sockaddr *ifa_addr;
238 struct sockaddr *ifa_netmask;
239 struct sockaddr *ifa_broadaddr;
240 struct sockaddr *ifa_dstaddr;
241 void *ifa_data;
242};
243#ifdef IF_NAMESIZE
244#define IFNAMSIZ IF_NAMESIZE
245#else
246#define IFNAMSIZ 256
247#endif
248#ifdef IFF_POINTTOPOINT
249#define IFF_POINTOPOINT IFF_POINTTOPOINT
250#endif
251
252extern void rb_w32_sysinit(int *, char ***);
253 extern DWORD rb_w32_osid(void);
254extern int flock(int fd, int oper);
255extern int rb_w32_io_cancelable_p(int);
256extern int rb_w32_is_socket(int);
257extern int WSAAPI rb_w32_accept(int, struct sockaddr *, int *);
258extern int WSAAPI rb_w32_bind(int, const struct sockaddr *, int);
259extern int WSAAPI rb_w32_connect(int, const struct sockaddr *, int);
260extern void rb_w32_fdset(int, fd_set*);
261extern void rb_w32_fdclr(int, fd_set*);
262extern int rb_w32_fdisset(int, fd_set*);
263extern int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
264extern int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *);
265extern int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *);
266extern int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *);
267extern int WSAAPI rb_w32_ioctlsocket(int, long, u_long *);
268extern int WSAAPI rb_w32_listen(int, int);
269extern int WSAAPI rb_w32_recv(int, char *, int, int);
270extern int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *);
271extern int WSAAPI rb_w32_send(int, const char *, int, int);
272extern int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int);
273extern int recvmsg(int, struct msghdr *, int);
274extern int sendmsg(int, const struct msghdr *, int);
275extern int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int);
276extern int WSAAPI rb_w32_shutdown(int, int);
277extern int WSAAPI rb_w32_socket(int, int, int);
278extern SOCKET rb_w32_get_osfhandle(int);
279extern struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int);
280extern struct hostent *WSAAPI rb_w32_gethostbyname(const char *);
281extern int WSAAPI rb_w32_gethostname(char *, int);
282extern struct protoent *WSAAPI rb_w32_getprotobyname(const char *);
283extern struct protoent *WSAAPI rb_w32_getprotobynumber(int);
284extern struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *);
285extern struct servent *WSAAPI rb_w32_getservbyport(int, const char *);
286extern int socketpair(int, int, int, int *);
287extern int getifaddrs(struct ifaddrs **);
288extern void freeifaddrs(struct ifaddrs *);
289extern char * rb_w32_ugetcwd(char *, int);
290extern char * rb_w32_ugetenv(const char *);
291extern int rb_w32_urename(const char *, const char *);
292extern char **rb_w32_get_environ(void);
293extern void rb_w32_free_environ(char **);
294extern int rb_w32_map_errno(DWORD);
295extern const char *WSAAPI rb_w32_inet_ntop(int,const void *,char *,size_t);
296extern int WSAAPI rb_w32_inet_pton(int,const char *,void *);
297extern DWORD rb_w32_osver(void);
298
299extern int rb_w32_uchown(const char *, int, int);
300extern int rb_w32_ulink(const char *, const char *);
301extern ssize_t rb_w32_ureadlink(const char *, char *, size_t);
302 extern ssize_t rb_w32_wreadlink(const WCHAR *, WCHAR *, size_t);
303extern int rb_w32_usymlink(const char *src, const char *link);
304extern int gettimeofday(struct timeval *, struct timezone *);
305extern int clock_gettime(clockid_t, struct timespec *);
306extern int clock_getres(clockid_t, struct timespec *);
307extern rb_pid_t waitpid (rb_pid_t, int *, int);
308extern rb_pid_t rb_w32_uspawn(int, const char *, const char*);
309extern rb_pid_t rb_w32_uaspawn(int, const char *, char *const *);
310extern rb_pid_t rb_w32_uaspawn_flags(int, const char *, char *const *, DWORD);
311extern int kill(int, int);
312extern int fcntl(int, int, ...);
313extern int rb_w32_set_nonblock(int);
314extern rb_pid_t rb_w32_getpid(void);
315extern rb_pid_t rb_w32_getppid(void);
316extern int rb_w32_isatty(int);
317extern int rb_w32_uchdir(const char *);
318extern int rb_w32_umkdir(const char *, int);
319extern int rb_w32_urmdir(const char *);
320extern int rb_w32_uunlink(const char *);
321extern int rb_w32_uchmod(const char *, int);
322extern int rb_w32_ustati128(const char *, struct stati128 *);
323extern int rb_w32_ulstati128(const char *, struct stati128 *);
324extern int rb_w32_uaccess(const char *, int);
325extern char rb_w32_fd_is_text(int);
326extern int rb_w32_fstati128(int, struct stati128 *);
327extern int rb_w32_dup2(int, int);
328
329#include <float.h>
330
331#if defined _MSC_VER && _MSC_VER >= 1800 && defined INFINITY
332#pragma warning(push)
333#pragma warning(disable:4756)
334static inline float
335rb_infinity_float(void)
336{
337 return INFINITY;
338}
339#pragma warning(pop)
340#undef INFINITY
341#define INFINITY rb_infinity_float()
342#endif
343
344#if !defined __MINGW32__ || defined __NO_ISOCEXT
345#ifndef isnan
346#define isnan(x) _isnan(x)
347#endif
348static inline int
349 finite(double x)
350{
351 return _finite(x);
352}
353#ifndef copysign
354#define copysign(a, b) _copysign(a, b)
355#endif
356static inline double
357scalb(double a, long b)
358{
359 return _scalb(a, b);
360}
361#else
362__declspec(dllimport) extern int finite(double);
363#endif
364
365#if !defined S_IFIFO && defined _S_IFIFO
366#define S_IFIFO _S_IFIFO
367#endif
368
369#if !defined S_IRUSR && !defined __MINGW32__
370#define S_IRUSR 0400
371#endif
372#ifndef S_IRGRP
373#define S_IRGRP 0040
374#endif
375#ifndef S_IROTH
376#define S_IROTH 0004
377#endif
378
379#if !defined S_IWUSR && !defined __MINGW32__
380#define S_IWUSR 0200
381#endif
382#ifndef S_IWGRP
383#define S_IWGRP 0020
384#endif
385#ifndef S_IWOTH
386#define S_IWOTH 0002
387#endif
388
389#if !defined S_IXUSR && !defined __MINGW32__
390#define S_IXUSR 0100
391#endif
392#ifndef S_IXGRP
393#define S_IXGRP 0010
394#endif
395#ifndef S_IXOTH
396#define S_IXOTH 0001
397#endif
398
399#define S_IFLNK 0xa000
400
401/*
402 * define this so we can do inplace editing
403 */
404
405#define SUFFIX
406
407extern int rb_w32_ftruncate(int fd, off_t length);
408extern int rb_w32_truncate(const char *path, off_t length);
409extern int rb_w32_utruncate(const char *path, off_t length);
410
411#undef HAVE_FTRUNCATE
412#define HAVE_FTRUNCATE 1
413#if defined HAVE_FTRUNCATE64
414#define ftruncate ftruncate64
415#else
416#define ftruncate rb_w32_ftruncate
417#endif
418
419#undef HAVE_TRUNCATE
420#define HAVE_TRUNCATE 1
421#define truncate rb_w32_utruncate
422
423#if defined(_MSC_VER) && _MSC_VER >= 1400 && _MSC_VER < 1800
424#define strtoll _strtoi64
425#define strtoull _strtoui64
426#endif
427
428/*
429 * stubs
430 */
431extern int ioctl (int, int, ...);
432extern rb_uid_t getuid (void);
433extern rb_uid_t geteuid (void);
434extern rb_gid_t getgid (void);
435extern rb_gid_t getegid (void);
436extern int setuid (rb_uid_t);
437extern int setgid (rb_gid_t);
438
439extern char *rb_w32_strerror(int);
440
441#ifdef RUBY_EXPORT
442#define strerror(e) rb_w32_strerror(e)
443#endif
444
445#define PIPE_BUF 1024
446
447#define LOCK_SH 1
448#define LOCK_EX 2
449#define LOCK_NB 4
450#define LOCK_UN 8
451
452
453#ifndef SIGINT
454#define SIGINT 2
455#endif
456#ifndef SIGKILL
457#define SIGKILL 9
458#endif
459
460
461/* #undef va_start */
462/* #undef va_end */
463
464/* winsock error map */
465#include <errno.h>
466
467#ifndef EWOULDBLOCK
468# define EWOULDBLOCK WSAEWOULDBLOCK
469#endif
470#ifndef EINPROGRESS
471# define EINPROGRESS WSAEINPROGRESS
472#endif
473#ifndef EALREADY
474# define EALREADY WSAEALREADY
475#endif
476#ifndef ENOTSOCK
477# define ENOTSOCK WSAENOTSOCK
478#endif
479#ifndef EDESTADDRREQ
480# define EDESTADDRREQ WSAEDESTADDRREQ
481#endif
482#ifndef EMSGSIZE
483# define EMSGSIZE WSAEMSGSIZE
484#endif
485#ifndef EPROTOTYPE
486# define EPROTOTYPE WSAEPROTOTYPE
487#endif
488#ifndef ENOPROTOOPT
489# define ENOPROTOOPT WSAENOPROTOOPT
490#endif
491#ifndef EPROTONOSUPPORT
492# define EPROTONOSUPPORT WSAEPROTONOSUPPORT
493#endif
494#ifndef ESOCKTNOSUPPORT
495# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
496#endif
497#ifndef EOPNOTSUPP
498# define EOPNOTSUPP WSAEOPNOTSUPP
499#endif
500#ifndef EPFNOSUPPORT
501# define EPFNOSUPPORT WSAEPFNOSUPPORT
502#endif
503#ifndef EAFNOSUPPORT
504# define EAFNOSUPPORT WSAEAFNOSUPPORT
505#endif
506#ifndef EADDRINUSE
507# define EADDRINUSE WSAEADDRINUSE
508#endif
509#ifndef EADDRNOTAVAIL
510# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
511#endif
512#ifndef ENETDOWN
513# define ENETDOWN WSAENETDOWN
514#endif
515#ifndef ENETUNREACH
516# define ENETUNREACH WSAENETUNREACH
517#endif
518#ifndef ENETRESET
519# define ENETRESET WSAENETRESET
520#endif
521#ifndef ECONNABORTED
522# define ECONNABORTED WSAECONNABORTED
523#endif
524#ifndef ECONNRESET
525# define ECONNRESET WSAECONNRESET
526#endif
527#ifndef ENOBUFS
528# define ENOBUFS WSAENOBUFS
529#endif
530#ifndef EISCONN
531# define EISCONN WSAEISCONN
532#endif
533#ifndef ENOTCONN
534# define ENOTCONN WSAENOTCONN
535#endif
536#ifndef ESHUTDOWN
537# define ESHUTDOWN WSAESHUTDOWN
538#endif
539#ifndef ETOOMANYREFS
540# define ETOOMANYREFS WSAETOOMANYREFS
541#endif
542#ifndef ETIMEDOUT
543# define ETIMEDOUT WSAETIMEDOUT
544#endif
545#ifndef ECONNREFUSED
546# define ECONNREFUSED WSAECONNREFUSED
547#endif
548#ifndef ELOOP
549# define ELOOP WSAELOOP
550#endif
551/*#define ENAMETOOLONG WSAENAMETOOLONG*/
552#ifndef EHOSTDOWN
553# define EHOSTDOWN WSAEHOSTDOWN
554#endif
555#ifndef EHOSTUNREACH
556# define EHOSTUNREACH WSAEHOSTUNREACH
557#endif
558/*#define ENOTEMPTY WSAENOTEMPTY*/
559#ifndef EPROCLIM
560# define EPROCLIM WSAEPROCLIM
561#endif
562#ifndef EUSERS
563# define EUSERS WSAEUSERS
564#endif
565#ifndef EDQUOT
566# define EDQUOT WSAEDQUOT
567#endif
568#ifndef ESTALE
569# define ESTALE WSAESTALE
570#endif
571#ifndef EREMOTE
572# define EREMOTE WSAEREMOTE
573#endif
574
575#define F_DUPFD 0
576#define F_GETFD 1
577#define F_SETFD 2
578#if 0
579#define F_GETFL 3
580#endif
581#define F_SETFL 4
582#define F_DUPFD_CLOEXEC 67
583#define FD_CLOEXEC 1 /* F_GETFD, F_SETFD */
584#define O_NONBLOCK 1
585
586#undef FD_SET
587#define FD_SET(fd, set) do {\
588 unsigned int i;\
589 SOCKET s = _get_osfhandle(fd);\
590\
591 for (i = 0; i < (set)->fd_count; i++) {\
592 if ((set)->fd_array[i] == s) {\
593 break;\
594 }\
595 }\
596 if (i == (set)->fd_count) {\
597 if ((set)->fd_count < FD_SETSIZE) {\
598 (set)->fd_array[i] = s;\
599 (set)->fd_count++;\
600 }\
601 }\
602} while(0)
603
604#undef FD_CLR
605#define FD_CLR(f, s) rb_w32_fdclr(f, s)
606
607#undef FD_ISSET
608#define FD_ISSET(f, s) rb_w32_fdisset(f, s)
609
610#ifdef RUBY_EXPORT
611#undef inet_ntop
612#define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l)
613
614#undef inet_pton
615#define inet_pton(f,s,d) rb_w32_inet_pton(f,s,d)
616
617#undef accept
618#define accept(s, a, l) rb_w32_accept(s, a, l)
619
620#undef bind
621#define bind(s, a, l) rb_w32_bind(s, a, l)
622
623#undef connect
624#define connect(s, a, l) rb_w32_connect(s, a, l)
625
626#undef select
627#define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t)
628
629#undef getpeername
630#define getpeername(s, a, l) rb_w32_getpeername(s, a, l)
631
632#undef getsockname
633#define getsockname(s, a, l) rb_w32_getsockname(s, a, l)
634
635#undef getsockopt
636#define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
637
638#undef ioctlsocket
639#define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a)
640
641#undef listen
642#define listen(s, b) rb_w32_listen(s, b)
643
644#undef recv
645#define recv(s, b, l, f) rb_w32_recv(s, b, l, f)
646
647#undef recvfrom
648#define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
649
650#undef send
651#define send(s, b, l, f) rb_w32_send(s, b, l, f)
652
653#undef sendto
654#define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
655
656#undef setsockopt
657#define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
658
659#undef shutdown
660#define shutdown(s, h) rb_w32_shutdown(s, h)
661
662#undef socket
663#define socket(s, t, p) rb_w32_socket(s, t, p)
664
665#undef gethostbyaddr
666#define gethostbyaddr(a, l, t) rb_w32_gethostbyaddr(a, l, t)
667
668#undef gethostbyname
669#define gethostbyname(n) rb_w32_gethostbyname(n)
670
671#undef gethostname
672#define gethostname(n, l) rb_w32_gethostname(n, l)
673
674#undef getprotobyname
675#define getprotobyname(n) rb_w32_getprotobyname(n)
676
677#undef getprotobynumber
678#define getprotobynumber(n) rb_w32_getprotobynumber(n)
679
680#undef getservbyname
681#define getservbyname(n, p) rb_w32_getservbyname(n, p)
682
683#undef getservbyport
684#define getservbyport(p, pr) rb_w32_getservbyport(p, pr)
685
686#undef get_osfhandle
687#define get_osfhandle(h) rb_w32_get_osfhandle(h)
688
689#undef getcwd
690#define getcwd(b, s) rb_w32_ugetcwd(b, s)
691
692#undef getenv
693#define getenv(n) rb_w32_ugetenv(n)
694
695#undef rename
696#define rename(o, n) rb_w32_urename(o, n)
697
698#undef times
699#define times(t) rb_w32_times(t)
700
701#undef dup2
702#define dup2(o, n) rb_w32_dup2(o, n)
703#endif
704
705 struct tms {
706 long tms_utime;
707 long tms_stime;
708 long tms_cutime;
709 long tms_cstime;
710};
711
712int rb_w32_times(struct tms *);
713
714struct tm *gmtime_r(const time_t *, struct tm *);
715struct tm *localtime_r(const time_t *, struct tm *);
716
717/* thread stuff */
718 int rb_w32_sleep(unsigned long msec);
719int rb_w32_uopen(const char *, int, ...);
720int rb_w32_wopen(const WCHAR *, int, ...);
721int rb_w32_close(int);
722int rb_w32_fclose(FILE*);
723int rb_w32_pipe(int[2]);
724ssize_t rb_w32_read(int, void *, size_t);
725ssize_t rb_w32_write(int, const void *, size_t);
726 off_t rb_w32_lseek(int, off_t, int);
727int rb_w32_uutime(const char *, const struct utimbuf *);
728int rb_w32_uutimes(const char *, const struct timeval *);
729int rb_w32_uutimensat(int /* must be AT_FDCWD */, const char *, const struct timespec *, int /* must be 0 */);
730long rb_w32_write_console(uintptr_t, int); /* use uintptr_t instead of VALUE because it's not defined yet here */
731 int WINAPI rb_w32_Sleep(unsigned long msec);
732 int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout);
733int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait);
734int rb_w32_wrap_io_handle(HANDLE, int);
735int rb_w32_unwrap_io_handle(int);
736WCHAR *rb_w32_mbstr_to_wstr(UINT, const char *, int, long *);
737char *rb_w32_wstr_to_mbstr(UINT, const WCHAR *, int, long *);
738
739 DEPRECATED_BY(rb_w32_ugetcwd, char *rb_w32_getcwd(char *, int));
740 DEPRECATED_BY(rb_w32_ugetenv, char *rb_w32_getenv(const char *));
741 DEPRECATED_BY(rb_w32_urename, int rb_w32_rename(const char *, const char *));
742 DEPRECATED_BY(rb_w32_uopen, int rb_w32_open(const char *, int, ...));
743 DEPRECATED_BY(rb_w32_uchown, int chown(const char *, int, int));
744 DEPRECATED_BY(rb_w32_ulink, int link(const char *, const char *));
745 DEPRECATED_BY(rb_w32_ureadlink, ssize_t readlink(const char *, char *, size_t));
746 DEPRECATED_BY(rb_w32_usymlink, int symlink(const char *src, const char *link));
747 DEPRECATED_BY(rb_w32_umkdir, int rb_w32_mkdir(const char *, int));
748 DEPRECATED_BY(rb_w32_urmdir, int rb_w32_rmdir(const char *));
749 DEPRECATED_BY(rb_w32_uunlink, int rb_w32_unlink(const char *));
750 DEPRECATED_BY(rb_w32_uutime, int rb_w32_utime(const char *, const struct utimbuf *));
751 DEPRECATED_BY(rb_w32_uutimes, int rb_w32_utimes(const char *, const struct timeval *));
752 DEPRECATED_BY(rb_w32_uutimensat, int rb_w32_utimensat(int, const char *, const struct timespec *, int));
753 DEPRECATED_BY(rb_w32_ustati128, int rb_w32_stati128(const char *, struct stati128 *));
754 DEPRECATED_BY(rb_w32_ulstati128, int rb_w32_lstati128(const char *, struct stati128 *));
755 DEPRECATED_BY(rb_w32_uaccess, int rb_w32_access(const char *, int));
756 DEPRECATED_BY(rb_w32_uspawn, rb_pid_t rb_w32_spawn(int, const char *, const char*));
757 DEPRECATED_BY(rb_w32_uaspawn, rb_pid_t rb_w32_aspawn(int, const char *, char *const *));
758 DEPRECATED_BY(rb_w32_uaspawn_flags, rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD));
759
760/*
761== ***CAUTION***
762Since this function is very dangerous, ((*NEVER*))
763* lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
764* use anything like rb_thread_call_without_gvl,
765in asynchronous_func_t.
766*/
767 typedef uintptr_t (*asynchronous_func_t)(uintptr_t self, int argc, uintptr_t* argv);
768 uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t* argv, uintptr_t intrval);
769
770RUBY_SYMBOL_EXPORT_END
771
772#if (defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW64__)) && !defined(__cplusplus)
773#ifdef RUBY_MINGW64_BROKEN_FREXP_MODF
774/* License: Ruby's */
775/* get rid of bugs in math.h of mingw */
776#define frexp(_X, _Y) __extension__ ({\
777 int intpart_frexp_bug = intpart_frexp_bug;\
778 double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\
779 *(_Y) = intpart_frexp_bug;\
780 result_frexp_bug;\
781})
782/* License: Ruby's */
783#define modf(_X, _Y) __extension__ ({\
784 double intpart_modf_bug = intpart_modf_bug;\
785 double result_modf_bug = modf((_X), &intpart_modf_bug);\
786 *(_Y) = intpart_modf_bug;\
787 result_modf_bug;\
788})
789#endif
790
791#if defined(__MINGW64__)
792/*
793 * Use powl() instead of broken pow() of x86_64-w64-mingw32.
794 * This workaround will fix test failures in test_bignum.rb,
795 * test_fixnum.rb and test_float.rb etc.
796 */
797static inline double
798rb_w32_pow(double x, double y)
799{
800 return (double)powl(x, y);
801}
802#elif defined(__MINGW64_VERSION_MAJOR)
803double rb_w32_pow(double x, double y);
804#endif
805#define pow rb_w32_pow
806#endif
807
808#if defined(__cplusplus)
809#if 0
810{ /* satisfy cc-mode */
811#endif
812} /* extern "C" { */
813#endif
814
815#endif /* RUBY_WIN32_H */
DEPRECATED_BY
#define DEPRECATED_BY(n, x)
Definition: attributes.h:60
num
big_t * num
Definition: enough.c:232
INFINITY
#define INFINITY
Definition: missing.h:144
finite
int finite(double)
Definition: finite.c:6
io.h
Internal header for IO.
math.h
Internal header for Math.
argc
int argc
Definition: ruby.c:240
argv
char ** argv
Definition: ruby.c:241
__sFILE
Definition: vsnprintf.c:169
ifaddrs
Definition: win32.h:233
ifaddrs::ifa_flags
u_int ifa_flags
Definition: win32.h:236
ifaddrs::ifa_addr
struct sockaddr * ifa_addr
Definition: win32.h:237
ifaddrs::ifa_name
char * ifa_name
Definition: win32.h:235
ifaddrs::ifa_next
struct ifaddrs * ifa_next
Definition: win32.h:234
ifaddrs::ifa_data
void * ifa_data
Definition: win32.h:241
ifaddrs::ifa_dstaddr
struct sockaddr * ifa_dstaddr
Definition: win32.h:240
ifaddrs::ifa_broadaddr
struct sockaddr * ifa_broadaddr
Definition: win32.h:239
ifaddrs::ifa_netmask
struct sockaddr * ifa_netmask
Definition: win32.h:238
iovec
Definition: win32.h:218
iovec::iov_base
void * iov_base
Definition: win32.h:219
iovec::iov_len
size_t iov_len
Definition: win32.h:220
msghdr
Definition: win32.h:222
msghdr::msg_iov
struct iovec * msg_iov
Definition: win32.h:225
msghdr::msg_name
void * msg_name
Definition: win32.h:223
msghdr::msg_iovlen
int msg_iovlen
Definition: win32.h:226
msghdr::msg_namelen
int msg_namelen
Definition: win32.h:224
msghdr::msg_flags
int msg_flags
Definition: win32.h:229
msghdr::msg_controllen
int msg_controllen
Definition: win32.h:228
msghdr::msg_control
void * msg_control
Definition: win32.h:227
stati128
Definition: win32.h:176
stati128::st_mode
unsigned short st_mode
Definition: win32.h:180
stati128::st_ctime
__time64_t st_ctime
Definition: win32.h:190
stati128::st_inohigh
__int64 st_inohigh
Definition: win32.h:179
stati128::st_atime
__time64_t st_atime
Definition: win32.h:186
stati128::st_nlink
short st_nlink
Definition: win32.h:181
stati128::st_mtimensec
long st_mtimensec
Definition: win32.h:189
stati128::st_ctimensec
long st_ctimensec
Definition: win32.h:191
stati128::st_atimensec
long st_atimensec
Definition: win32.h:187
stati128::st_uid
short st_uid
Definition: win32.h:182
stati128::st_ino
unsigned __int64 st_ino
Definition: win32.h:178
stati128::st_gid
short st_gid
Definition: win32.h:183
stati128::st_mtime
__time64_t st_mtime
Definition: win32.h:188
stati128::st_dev
_dev_t st_dev
Definition: win32.h:177
stati128::st_size
__int64 st_size
Definition: win32.h:185
stati128::st_rdev
_dev_t st_rdev
Definition: win32.h:184
timespec
Definition: missing.h:62
timeval
Definition: missing.h:51
timezone
Definition: missing.h:69
tms
Definition: win32.h:705
tms::tms_stime
long tms_stime
Definition: win32.h:707
tms::tms_cutime
long tms_cutime
Definition: win32.h:708
tms::tms_utime
long tms_utime
Definition: win32.h:706
tms::tms_cstime
long tms_cstime
Definition: win32.h:709
utimbuf
Definition: file.c:2928
u_long
#define u_long
Definition: vsnprintf.c:64
u_int
#define u_int
Definition: vsnprintf.c:66
rb_w32_stati128
#define rb_w32_stati128(path, st)
Definition: win32.c:79
wait
int wait(int *status)
Definition: win32.c:5245
rb_w32_close
int rb_w32_close(int)
Definition: win32.c:6985
rb_w32_write_console
long rb_w32_write_console(uintptr_t, int)
Definition: win32.c:7300
rb_w32_sendto
int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int)
Definition: win32.c:3633
rb_w32_access
int rb_w32_access(const char *, int)
Definition: win32.c:5890
gettimeofday
int gettimeofday(struct timeval *, struct timezone *)
Definition: win32.c:4654
rb_w32_fclose
int rb_w32_fclose(FILE *)
Definition: win32.c:6454
rb_w32_getprotobynumber
struct protoent *WSAAPI rb_w32_getprotobynumber(int)
Definition: win32.c:3947
rb_w32_accept
int WSAAPI rb_w32_accept(int, struct sockaddr *, int *)
Definition: win32.c:3330
intptr_t
int intptr_t
Definition: win32.h:90
rb_w32_ftruncate
int rb_w32_ftruncate(int fd, off_t length)
Definition: win32.c:5969
rb_w32_map_errno
int rb_w32_map_errno(DWORD)
Definition: win32.c:280
rb_w32_ulstati128
int rb_w32_ulstati128(const char *, struct stati128 *)
Definition: win32.c:5849
rb_w32_is_socket
int rb_w32_is_socket(int)
Definition: win32.c:2747
rb_w32_get_osfhandle
SOCKET rb_w32_get_osfhandle(int)
Definition: win32.c:1115
rb_w32_free_environ
void rb_w32_free_environ(char **)
Definition: win32.c:6142
rb_w32_fd_is_text
char rb_w32_fd_is_text(int)
Definition: win32.c:7831
rb_w32_rename
int rb_w32_rename(const char *, const char *)
Definition: win32.c:5389
rb_w32_utimensat
int rb_w32_utimensat(int, const char *, const struct timespec *, int)
Definition: win32.c:7523
readlink
ssize_t readlink(const char *, char *, size_t)
Definition: win32.c:5155
rb_w32_uchdir
int rb_w32_uchdir(const char *)
Definition: win32.c:7530
rb_w32_ustati128
int rb_w32_ustati128(const char *, struct stati128 *)
Definition: win32.c:5821
rb_w32_ureadlink
ssize_t rb_w32_ureadlink(const char *, char *, size_t)
Definition: win32.c:5148
recvmsg
int recvmsg(int, struct msghdr *, int)
Definition: win32.c:3677
rb_w32_uutimes
int rb_w32_uutimes(const char *, const struct timeval *)
Definition: win32.c:7490
getuid
rb_uid_t getuid(void)
Definition: win32.c:2821
rb_w32_mbstr_to_wstr
WCHAR * rb_w32_mbstr_to_wstr(UINT, const char *, int, long *)
Definition: win32.c:2186
waitpid
rb_pid_t waitpid(rb_pid_t, int *, int)
Definition: win32.c:4532
setgid
int setgid(rb_gid_t)
Definition: win32.c:2856
rb_w32_uchmod
int rb_w32_uchmod(const char *, int)
Definition: win32.c:7699
rb_w32_wait_events_blocking
int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout)
rb_w32_sleep
int rb_w32_sleep(unsigned long msec)
rb_w32_unwrap_io_handle
int rb_w32_unwrap_io_handle(int)
Definition: win32.c:7983
rb_w32_gethostname
int WSAAPI rb_w32_gethostname(char *, int)
Definition: win32.c:3917
symlink
int symlink(const char *src, const char *link)
Definition: win32.c:5238
rb_w32_osid
DWORD rb_w32_osid(void)
rb_w32_wstr_to_mbstr
char * rb_w32_wstr_to_mbstr(UINT, const WCHAR *, int, long *)
Definition: win32.c:2170
rb_w32_truncate
int rb_w32_truncate(const char *path, off_t length)
Definition: win32.c:5962
rb_w32_fdclr
void rb_w32_fdclr(int, fd_set *)
Definition: win32.c:2883
setuid
int setuid(rb_uid_t)
Definition: win32.c:2849
rb_w32_unlink
int rb_w32_unlink(const char *)
Definition: win32.c:7685
localtime_r
struct tm * localtime_r(const time_t *, struct tm *)
Definition: win32.c:7937
rb_w32_uchown
int rb_w32_uchown(const char *, int, int)
Definition: win32.c:4826
rb_w32_getservbyname
struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *)
Definition: win32.c:3962
rb_w32_ulink
int rb_w32_ulink(const char *, const char *)
Definition: win32.c:4967
rb_w32_aspawn
rb_pid_t rb_w32_aspawn(int, const char *, char *const *)
Definition: win32.c:1600
rb_w32_uutime
int rb_w32_uutime(const char *, const struct utimbuf *)
Definition: win32.c:7464
rb_w32_recv
int WSAAPI rb_w32_recv(int, char *, int, int)
Definition: win32.c:3611
rb_w32_send
int WSAAPI rb_w32_send(int, const char *, int, int)
Definition: win32.c:3626
rb_w32_gethostbyname
struct hostent *WSAAPI rb_w32_gethostbyname(const char *)
Definition: win32.c:3902
rb_w32_aspawn_flags
rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD)
Definition: win32.c:1585
rb_w32_bind
int WSAAPI rb_w32_bind(int, const struct sockaddr *, int)
Definition: win32.c:3357
geteuid
rb_uid_t geteuid(void)
Definition: win32.c:2828
rb_w32_select
int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
Definition: win32.c:3306
sendmsg
int sendmsg(int, const struct msghdr *, int)
Definition: win32.c:3732
rb_w32_uaccess
int rb_w32_uaccess(const char *, int)
Definition: win32.c:5897
rb_w32_ioctlsocket
int WSAAPI rb_w32_ioctlsocket(int, long, u_long *)
Definition: win32.c:3454
rb_w32_inet_ntop
const char *WSAAPI rb_w32_inet_ntop(int, const void *, char *, size_t)
Definition: win32.c:7798
rb_w32_uaspawn_flags
rb_pid_t rb_w32_uaspawn_flags(int, const char *, char *const *, DWORD)
Definition: win32.c:1593
rb_w32_read
ssize_t rb_w32_read(int, void *, size_t)
Definition: win32.c:7056
rb_w32_listen
int WSAAPI rb_w32_listen(int, int)
Definition: win32.c:3469
rb_w32_fdisset
int rb_w32_fdisset(int, fd_set *)
Definition: win32.c:2901
rb_w32_wrap_io_handle
int rb_w32_wrap_io_handle(HANDLE, int)
Definition: win32.c:7961
rb_w32_shutdown
int WSAAPI rb_w32_shutdown(int, int)
Definition: win32.c:3796
rb_w32_fdset
void rb_w32_fdset(int, fd_set *)
Definition: win32.c:2874
rb_w32_socket
int WSAAPI rb_w32_socket(int, int, int)
Definition: win32.c:3861
rb_w32_dup2
int rb_w32_dup2(int, int)
Definition: win32.c:6199
clockid_t
int clockid_t
Definition: win32.h:132
kill
int kill(int, int)
Definition: win32.c:4845
rb_w32_connect
int WSAAPI rb_w32_connect(int, const struct sockaddr *, int)
Definition: win32.c:3373
rb_w32_mkdir
int rb_w32_mkdir(const char *, int)
Definition: win32.c:7578
rb_w32_get_environ
char ** rb_w32_get_environ(void)
Definition: win32.c:6105
uintptr_t
unsigned int uintptr_t
Definition: win32.h:106
rb_w32_uutimensat
int rb_w32_uutimensat(int, const char *, const struct timespec *, int)
Definition: win32.c:7516
rb_w32_open
int rb_w32_open(const char *, int,...)
Definition: win32.c:6246
rb_w32_getcwd
char * rb_w32_getcwd(char *, int)
Definition: win32.c:4787
rb_w32_strerror
char * rb_w32_strerror(int)
Definition: win32.c:2762
rb_w32_urmdir
int rb_w32_urmdir(const char *)
Definition: win32.c:7627
rb_w32_sysinit
void rb_w32_sysinit(int *, char ***)
Definition: win32.c:884
rb_w32_wreadlink
ssize_t rb_w32_wreadlink(const WCHAR *, WCHAR *, size_t)
rb_w32_getppid
rb_pid_t rb_w32_getppid(void)
Definition: win32.c:6160
rb_w32_usymlink
int rb_w32_usymlink(const char *src, const char *link)
Definition: win32.c:5231
flock
int flock(int fd, int oper)
Definition: flock.c:125
rb_w32_io_cancelable_p
int rb_w32_io_cancelable_p(int)
Definition: win32.c:2647
rb_w32_uunlink
int rb_w32_uunlink(const char *)
Definition: win32.c:7671
rb_w32_getpid
rb_pid_t rb_w32_getpid(void)
Definition: win32.c:6152
rb_w32_fstati128
int rb_w32_fstati128(int, struct stati128 *)
Definition: win32.c:5471
link
int link(const char *, const char *)
Definition: win32.c:4987
clock_gettime
int clock_gettime(clockid_t, struct timespec *)
Definition: win32.c:4668
rb_w32_getsockopt
int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *)
Definition: win32.c:3439
fcntl
int fcntl(int, int,...)
Definition: win32.c:4338
rb_w32_setsockopt
int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int)
Definition: win32.c:3781
rb_w32_write
ssize_t rb_w32_write(int, const void *, size_t)
Definition: win32.c:7195
getegid
rb_gid_t getegid(void)
Definition: win32.c:2842
freeifaddrs
void freeifaddrs(struct ifaddrs *)
Definition: win32.c:4232
rb_w32_lstati128
int rb_w32_lstati128(const char *, struct stati128 *)
Definition: win32.c:5856
rb_w32_inet_pton
int WSAAPI rb_w32_inet_pton(int, const char *, void *)
Definition: win32.c:7817
rb_w32_utruncate
int rb_w32_utruncate(const char *path, off_t length)
Definition: win32.c:5955
asynchronous_func_t
uintptr_t(* asynchronous_func_t)(uintptr_t self, int argc, uintptr_t *argv)
Definition: win32.h:767
socketpair
int socketpair(int, int, int, int *)
Definition: win32.c:4078
rb_w32_getenv
char * rb_w32_getenv(const char *)
Definition: win32.c:5293
rb_w32_ugetenv
char * rb_w32_ugetenv(const char *)
Definition: win32.c:5286
rb_w32_set_nonblock
int rb_w32_set_nonblock(int)
Definition: win32.c:4446
rb_w32_getpeername
int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *)
Definition: win32.c:3394
getifaddrs
int getifaddrs(struct ifaddrs **)
Definition: win32.c:4145
clock_getres
int clock_getres(clockid_t, struct timespec *)
Definition: win32.c:4708
chown
int chown(const char *, int, int)
Definition: win32.c:4819
rb_w32_time_subtract
int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait)
Definition: win32.c:3130
gmtime_r
struct tm * gmtime_r(const time_t *, struct tm *)
Definition: win32.c:7913
rb_w32_Sleep
int WINAPI rb_w32_Sleep(unsigned long msec)
rb_w32_getservbyport
struct servent *WSAAPI rb_w32_getservbyport(int, const char *)
Definition: win32.c:3977
rb_w32_umkdir
int rb_w32_umkdir(const char *, int)
Definition: win32.c:7564
rb_w32_times
int rb_w32_times(struct tms *)
Definition: win32.c:5991
rb_w32_uspawn
rb_pid_t rb_w32_uspawn(int, const char *, const char *)
Definition: win32.c:1505
rb_w32_getprotobyname
struct protoent *WSAAPI rb_w32_getprotobyname(const char *)
Definition: win32.c:3932
rb_w32_urename
int rb_w32_urename(const char *, const char *)
Definition: win32.c:5370
rb_w32_utimes
int rb_w32_utimes(const char *, const struct timeval *)
Definition: win32.c:7503
rb_w32_uopen
int rb_w32_uopen(const char *, int,...)
Definition: win32.c:6212
ioctl
int ioctl(int, int,...)
Definition: win32.c:2867
rb_w32_ugetcwd
char * rb_w32_ugetcwd(char *, int)
Definition: win32.c:4794
off_t
#define off_t
Definition: win32.h:194
rb_w32_lseek
off_t rb_w32_lseek(int, off_t, int)
Definition: win32.c:5863
rb_w32_utime
int rb_w32_utime(const char *, const struct utimbuf *)
Definition: win32.c:7477
rb_w32_recvfrom
int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *)
Definition: win32.c:3618
rb_w32_spawn
rb_pid_t rb_w32_spawn(int, const char *, const char *)
Definition: win32.c:1497
rb_w32_isatty
int rb_w32_isatty(int)
Definition: win32.c:7754
rb_w32_getsockname
int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *)
Definition: win32.c:3409
rb_w32_asynchronize
uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t *argv, uintptr_t intrval)
Definition: win32.c:6042
rb_w32_uaspawn
rb_pid_t rb_w32_uaspawn(int, const char *, char *const *)
Definition: win32.c:1607
rb_w32_wopen
int rb_w32_wopen(const WCHAR *, int,...)
Definition: win32.c:6266
rb_w32_pipe
int rb_w32_pipe(int[2])
Definition: win32.c:6477
rb_w32_rmdir
int rb_w32_rmdir(const char *)
Definition: win32.c:7613
getgid
rb_gid_t getgid(void)
Definition: win32.c:2835
rb_w32_gethostbyaddr
struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int)
Definition: win32.c:3887
rb_w32_osver
DWORD rb_w32_osver(void)
Definition: win32.c:326
DWORD
IUnknown DWORD
Definition: win32ole.c:33