Ruby  3.4.0dev (2024-11-22 revision 0989400a925cd201defdca9eb28eb87200b30785)
win32.h
1 #ifndef RUBY_WIN32_H
2 #define RUBY_WIN32_H 1
3 
4 #if defined(__cplusplus)
5 extern "C" {
6 #if 0
7 } /* satisfy cc-mode */
8 #endif
9 #endif
10 
11 RUBY_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  * Ok now we can include the normal include files.
23  */
24 
25 /* #include <stdarg.h> conflict with varargs.h? */
26 #if !defined(WSAAPI)
27 #if defined(__cplusplus) && defined(_MSC_VER)
28 extern "C++" { /* template without extern "C++" */
29 #endif
30 #if !defined(_WIN64) && !defined(WIN32)
31 #define WIN32
32 #endif
33 #if defined(_MSC_VER) && _MSC_VER <= 1200
34 #include <windows.h>
35 #endif
36 #include <winsock2.h>
37 #include <ws2tcpip.h>
38 #include <mswsock.h>
39 #if !defined(_MSC_VER) || _MSC_VER >= 1400
40 #include <iphlpapi.h>
41 #endif
42 #if defined(__cplusplus) && defined(_MSC_VER)
43 }
44 #endif
45 #endif
46 
47 /*
48  * We're not using Microsoft's "extensions" to C for
49  * Structured Exception Handling (SEH) so we can nuke these
50  */
51 #undef try
52 #undef except
53 #undef finally
54 #undef leave
55 
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <direct.h>
60 #include <process.h>
61 #include <time.h>
62 #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
63 extern "C++" { /* template without extern "C++" */
64 #endif
65 #include <math.h>
66 #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
67 }
68 #endif
69 #include <signal.h>
70 #include <sys/stat.h>
71 #include <sys/types.h>
72 #ifdef HAVE_SYS_UTIME_H
73 # include <sys/utime.h>
74 #else
75 # include <utime.h>
76 #endif
77 #include <io.h>
78 #include <malloc.h>
79 #if defined __MINGW32__
80 # include <stdint.h>
81 #else
82 # if !defined(_INTPTR_T_DEFINED)
83 # ifdef _WIN64
84 typedef __int64 intptr_t;
85 # else
86 typedef int intptr_t;
87 # endif
88 # define _INTPTR_T_DEFINED
89 # endif
90 # if !defined(INTPTR_MAX)
91 # ifdef _WIN64
92 # define INTPTR_MAX 9223372036854775807I64
93 # else
94 # define INTPTR_MAX 2147483647
95 # endif
96 # define INTPTR_MIN (-INTPTR_MAX-1)
97 # endif
98 # if !defined(_UINTPTR_T_DEFINED)
99 # ifdef _WIN64
100 typedef unsigned __int64 uintptr_t;
101 # else
102 typedef unsigned int uintptr_t;
103 # endif
104 # define _UINTPTR_T_DEFINED
105 # endif
106 # if !defined(UINTPTR_MAX)
107 # ifdef _WIN64
108 # define UINTPTR_MAX 18446744073709551615UI64
109 # else
110 # define UINTPTR_MAX 4294967295U
111 # endif
112 # endif
113 #endif
114 #ifndef __MINGW32__
115 # define mode_t int
116 #endif
117 #ifdef HAVE_UNISTD_H
118 # include <unistd.h>
119 #endif
120 
121 #define rb_w32_iswinnt() TRUE
122 #define rb_w32_iswin95() FALSE
123 
124 #define WNOHANG -1
125 
126 #define O_SHARE_DELETE 0x20000000 /* for rb_w32_open(), rb_w32_wopen() */
127 
128 typedef int clockid_t;
129 #define CLOCK_REALTIME 0
130 #define CLOCK_MONOTONIC 1
131 
132 #undef utime
133 #undef lseek
134 #undef stat
135 #undef fstat
136 #ifdef RUBY_EXPORT
137 #define utime(_p, _t) rb_w32_uutime(_p, _t)
138 #undef HAVE_UTIMES
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)
146 
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()
156 #undef HAVE_GETPPID
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)
161 
162 #undef HAVE_EXECV
163 #define HAVE_EXECV 1
164 #undef execv
165 #define execv(path,argv) rb_w32_uaspawn(P_OVERLAY,path,argv)
166 #undef isatty
167 #define isatty(h) rb_w32_isatty(h)
168 
169 #undef mkdir
170 #define mkdir(p, m) rb_w32_umkdir(p, m)
171 #undef rmdir
172 #define rmdir(p) rb_w32_urmdir(p)
173 #undef unlink
174 #define unlink(p) rb_w32_uunlink(p)
175 #endif /* RUBY_EXPORT */
176 
177 /* same with stati64 except the size of st_ino and nanosecond timestamps */
178 struct stati128 {
179  _dev_t st_dev;
180  unsigned __int64 st_ino;
181  __int64 st_inohigh;
182  unsigned short st_mode;
183  short st_nlink;
184  short st_uid;
185  short st_gid;
186  _dev_t st_rdev;
187  __int64 st_size;
188  __time64_t st_atime;
189  long st_atimensec;
190  __time64_t st_mtime;
191  long st_mtimensec;
192  __time64_t st_ctime;
193  long st_ctimensec;
194 };
195 
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)
207 
208 #define strcasecmp _stricmp
209 #define strncasecmp _strnicmp
210 #define fsync _commit
211 
212 struct timezone;
213 
214 #ifdef __MINGW32__
215 #undef isascii
216 #define isascii __isascii
217 #endif
218 
219 struct iovec {
220  void *iov_base;
221  size_t iov_len;
222 };
223 struct msghdr {
224  void *msg_name;
225  int msg_namelen;
226  struct iovec *msg_iov;
227  int msg_iovlen;
228  void *msg_control;
229  int msg_controllen;
230  int msg_flags;
231 };
232 
233 /* for getifaddrs() and others */
234 struct ifaddrs {
235  struct ifaddrs *ifa_next;
236  char *ifa_name;
237  u_int ifa_flags;
238  struct sockaddr *ifa_addr;
239  struct sockaddr *ifa_netmask;
240  struct sockaddr *ifa_broadaddr;
241  struct sockaddr *ifa_dstaddr;
242  void *ifa_data;
243 };
244 #ifdef IF_NAMESIZE
245 #define IFNAMSIZ IF_NAMESIZE
246 #else
247 #define IFNAMSIZ 256
248 #endif
249 #ifdef IFF_POINTTOPOINT
250 #define IFF_POINTOPOINT IFF_POINTTOPOINT
251 #endif
252 
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);
299 
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);
304 extern int gettimeofday(struct timeval *, struct timezone *);
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);
312 #undef HAVE_KILL
313 #define HAVE_KILL 1
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);
331 
332 #include <float.h>
333 
334 #if defined _MSC_VER && _MSC_VER >= 1800 && defined INFINITY
335 #pragma warning(push)
336 #pragma warning(disable:4756)
337 static inline float
338 rb_infinity_float(void)
339 {
340  return INFINITY;
341 }
342 #pragma warning(pop)
343 #undef INFINITY
344 #define INFINITY rb_infinity_float()
345 #endif
346 
347 #if !defined __MINGW32__ || defined __NO_ISOCEXT
348 #ifndef copysign
349 #define copysign(a, b) _copysign(a, b)
350 #endif
351 static inline double
352 scalb(double a, long b)
353 {
354  return _scalb(a, b);
355 }
356 #endif
357 
358 #if !defined S_IFIFO && defined _S_IFIFO
359 #define S_IFIFO _S_IFIFO
360 #endif
361 
362 #if !defined S_IRUSR && !defined __MINGW32__
363 #define S_IRUSR 0400
364 #endif
365 #ifndef S_IRGRP
366 #define S_IRGRP 0040
367 #endif
368 #ifndef S_IROTH
369 #define S_IROTH 0004
370 #endif
371 
372 #if !defined S_IWUSR && !defined __MINGW32__
373 #define S_IWUSR 0200
374 #endif
375 #ifndef S_IWGRP
376 #define S_IWGRP 0020
377 #endif
378 #ifndef S_IWOTH
379 #define S_IWOTH 0002
380 #endif
381 
382 #if !defined S_IXUSR && !defined __MINGW32__
383 #define S_IXUSR 0100
384 #endif
385 #ifndef S_IXGRP
386 #define S_IXGRP 0010
387 #endif
388 #ifndef S_IXOTH
389 #define S_IXOTH 0001
390 #endif
391 
392 #define S_IFLNK 0xa000
393 #define S_IFSOCK 0xc000
394 
395 /*
396  * define this so we can do inplace editing
397  */
398 
399 #define SUFFIX
400 
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);
404 
405 #undef HAVE_FTRUNCATE
406 #define HAVE_FTRUNCATE 1
407 #if defined HAVE_FTRUNCATE64
408 #define ftruncate ftruncate64
409 #else
410 #define ftruncate rb_w32_ftruncate
411 #endif
412 
413 #undef HAVE_TRUNCATE
414 #define HAVE_TRUNCATE 1
415 #define truncate rb_w32_utruncate
416 
417 #if defined(_MSC_VER) && _MSC_VER >= 1400 && _MSC_VER < 1800
418 #define strtoll _strtoi64
419 #define strtoull _strtoui64
420 #endif
421 
422 /*
423  * stubs
424  */
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);
432 
433 extern char *rb_w32_strerror(int);
434 
435 #ifdef RUBY_EXPORT
436 #define strerror(e) rb_w32_strerror(e)
437 #endif
438 
439 #define PIPE_BUF 1024
440 
441 #define LOCK_SH 1
442 #define LOCK_EX 2
443 #define LOCK_NB 4
444 #define LOCK_UN 8
445 
446 
447 #ifndef SIGINT
448 #define SIGINT 2
449 #endif
450 #ifndef SIGKILL
451 #define SIGKILL 9
452 #endif
453 
454 
455 /* #undef va_start */
456 /* #undef va_end */
457 
458 /* winsock error map */
459 #include <errno.h>
460 
461 #ifndef EWOULDBLOCK
462 # define EWOULDBLOCK WSAEWOULDBLOCK
463 #endif
464 #ifndef EINPROGRESS
465 # define EINPROGRESS WSAEINPROGRESS
466 #endif
467 #ifndef EALREADY
468 # define EALREADY WSAEALREADY
469 #endif
470 #ifndef ENOTSOCK
471 # define ENOTSOCK WSAENOTSOCK
472 #endif
473 #ifndef EDESTADDRREQ
474 # define EDESTADDRREQ WSAEDESTADDRREQ
475 #endif
476 #ifndef EMSGSIZE
477 # define EMSGSIZE WSAEMSGSIZE
478 #endif
479 #ifndef EPROTOTYPE
480 # define EPROTOTYPE WSAEPROTOTYPE
481 #endif
482 #ifndef ENOPROTOOPT
483 # define ENOPROTOOPT WSAENOPROTOOPT
484 #endif
485 #ifndef EPROTONOSUPPORT
486 # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
487 #endif
488 #ifndef ESOCKTNOSUPPORT
489 # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
490 #endif
491 #ifndef EOPNOTSUPP
492 # define EOPNOTSUPP WSAEOPNOTSUPP
493 #endif
494 #ifndef EPFNOSUPPORT
495 # define EPFNOSUPPORT WSAEPFNOSUPPORT
496 #endif
497 #ifndef EAFNOSUPPORT
498 # define EAFNOSUPPORT WSAEAFNOSUPPORT
499 #endif
500 #ifndef EADDRINUSE
501 # define EADDRINUSE WSAEADDRINUSE
502 #endif
503 #ifndef EADDRNOTAVAIL
504 # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
505 #endif
506 #ifndef ENETDOWN
507 # define ENETDOWN WSAENETDOWN
508 #endif
509 #ifndef ENETUNREACH
510 # define ENETUNREACH WSAENETUNREACH
511 #endif
512 #ifndef ENETRESET
513 # define ENETRESET WSAENETRESET
514 #endif
515 #ifndef ECONNABORTED
516 # define ECONNABORTED WSAECONNABORTED
517 #endif
518 #ifndef ECONNRESET
519 # define ECONNRESET WSAECONNRESET
520 #endif
521 #ifndef ENOBUFS
522 # define ENOBUFS WSAENOBUFS
523 #endif
524 #ifndef EISCONN
525 # define EISCONN WSAEISCONN
526 #endif
527 #ifndef ENOTCONN
528 # define ENOTCONN WSAENOTCONN
529 #endif
530 #ifndef ESHUTDOWN
531 # define ESHUTDOWN WSAESHUTDOWN
532 #endif
533 #ifndef ETOOMANYREFS
534 # define ETOOMANYREFS WSAETOOMANYREFS
535 #endif
536 #ifndef ETIMEDOUT
537 # define ETIMEDOUT WSAETIMEDOUT
538 #endif
539 #ifndef ECONNREFUSED
540 # define ECONNREFUSED WSAECONNREFUSED
541 #endif
542 #ifndef ELOOP
543 # define ELOOP WSAELOOP
544 #endif
545 /*#define ENAMETOOLONG WSAENAMETOOLONG*/
546 #ifndef EHOSTDOWN
547 # define EHOSTDOWN WSAEHOSTDOWN
548 #endif
549 #ifndef EHOSTUNREACH
550 # define EHOSTUNREACH WSAEHOSTUNREACH
551 #endif
552 /*#define ENOTEMPTY WSAENOTEMPTY*/
553 #ifndef EPROCLIM
554 # define EPROCLIM WSAEPROCLIM
555 #endif
556 #ifndef EUSERS
557 # define EUSERS WSAEUSERS
558 #endif
559 #ifndef EDQUOT
560 # define EDQUOT WSAEDQUOT
561 #endif
562 #ifndef ESTALE
563 # define ESTALE WSAESTALE
564 #endif
565 #ifndef EREMOTE
566 # define EREMOTE WSAEREMOTE
567 #endif
568 
569 #define F_DUPFD 0
570 #define F_GETFD 1
571 #define F_SETFD 2
572 #if 0
573 #define F_GETFL 3
574 #endif
575 #define F_SETFL 4
576 #define F_DUPFD_CLOEXEC 67
577 #define FD_CLOEXEC 1 /* F_GETFD, F_SETFD */
578 #define O_NONBLOCK 1
579 
580 #undef FD_SET
581 #define FD_SET(fd, set) do {\
582  unsigned int i;\
583  SOCKET s = _get_osfhandle(fd);\
584 \
585  for (i = 0; i < (set)->fd_count; i++) {\
586  if ((set)->fd_array[i] == s) {\
587  break;\
588  }\
589  }\
590  if (i == (set)->fd_count) {\
591  if ((set)->fd_count < FD_SETSIZE) {\
592  (set)->fd_array[i] = s;\
593  (set)->fd_count++;\
594  }\
595  }\
596 } while(0)
597 
598 #undef FD_CLR
599 #define FD_CLR(f, s) rb_w32_fdclr(f, s)
600 
601 #undef FD_ISSET
602 #define FD_ISSET(f, s) rb_w32_fdisset(f, s)
603 
604 #ifdef RUBY_EXPORT
605 #undef inet_ntop
606 #define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l)
607 
608 #undef inet_pton
609 #define inet_pton(f,s,d) rb_w32_inet_pton(f,s,d)
610 
611 #undef accept
612 #define accept(s, a, l) rb_w32_accept(s, a, l)
613 
614 #undef bind
615 #define bind(s, a, l) rb_w32_bind(s, a, l)
616 
617 #undef connect
618 #define connect(s, a, l) rb_w32_connect(s, a, l)
619 
620 #undef select
621 #define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t)
622 
623 #undef getpeername
624 #define getpeername(s, a, l) rb_w32_getpeername(s, a, l)
625 
626 #undef getsockname
627 #define getsockname(s, a, l) rb_w32_getsockname(s, a, l)
628 
629 #undef getsockopt
630 #define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
631 
632 #undef ioctlsocket
633 #define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a)
634 
635 #undef listen
636 #define listen(s, b) rb_w32_listen(s, b)
637 
638 #undef recv
639 #define recv(s, b, l, f) rb_w32_recv(s, b, l, f)
640 
641 #undef recvfrom
642 #define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
643 
644 #undef send
645 #define send(s, b, l, f) rb_w32_send(s, b, l, f)
646 
647 #undef sendto
648 #define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
649 
650 #undef setsockopt
651 #define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
652 
653 #undef HAVE_SHUTDOWN
654 #define HAVE_SHUTDOWN 1
655 #undef shutdown
656 #define shutdown(s, h) rb_w32_shutdown(s, h)
657 
658 #undef socket
659 #define socket(s, t, p) rb_w32_socket(s, t, p)
660 
661 #undef gethostbyaddr
662 #define gethostbyaddr(a, l, t) rb_w32_gethostbyaddr(a, l, t)
663 
664 #undef gethostbyname
665 #define gethostbyname(n) rb_w32_gethostbyname(n)
666 
667 #undef gethostname
668 #define gethostname(n, l) rb_w32_gethostname(n, l)
669 
670 #undef getprotobyname
671 #define getprotobyname(n) rb_w32_getprotobyname(n)
672 
673 #undef getprotobynumber
674 #define getprotobynumber(n) rb_w32_getprotobynumber(n)
675 
676 #undef getservbyname
677 #define getservbyname(n, p) rb_w32_getservbyname(n, p)
678 
679 #undef getservbyport
680 #define getservbyport(p, pr) rb_w32_getservbyport(p, pr)
681 
682 #undef get_osfhandle
683 #define get_osfhandle(h) rb_w32_get_osfhandle(h)
684 
685 #undef getcwd
686 #define getcwd(b, s) rb_w32_ugetcwd(b, s)
687 
688 #undef getenv
689 #define getenv(n) rb_w32_ugetenv(n)
690 
691 #undef rename
692 #define rename(o, n) rb_w32_urename(o, n)
693 
694 #undef times
695 #define times(t) rb_w32_times(t)
696 
697 #undef dup2
698 #define dup2(o, n) rb_w32_dup2(o, n)
699 #endif
700 
701 struct tms {
702  long tms_utime;
703  long tms_stime;
704  long tms_cutime;
705  long tms_cstime;
706 };
707 
708 int rb_w32_times(struct tms *);
709 
710 struct tm *gmtime_r(const time_t *, struct tm *);
711 struct tm *localtime_r(const time_t *, struct tm *);
712 
713 /* thread stuff */
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 /* must be AT_FDCWD */, const char *, const struct timespec *, int /* must be 0 */);
728 long rb_w32_write_console(uintptr_t, int); /* use uintptr_t instead of VALUE because it's not defined yet here */
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 *);
736 
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));
757 
758 /*
759 == ***CAUTION***
760 Since this function is very dangerous, ((*NEVER*))
761 * lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
762 * use anything like rb_thread_call_without_gvl,
763 in asynchronous_func_t.
764 */
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);
767 
768 RUBY_SYMBOL_EXPORT_END
769 
770 #if (defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW64__)) && !defined(__cplusplus)
771 #ifdef RUBY_MINGW64_BROKEN_FREXP_MODF
772 /* License: Ruby's */
773 /* get rid of bugs in math.h of mingw */
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;\
778  result_frexp_bug;\
779 })
780 /* License: Ruby's */
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;\
785  result_modf_bug;\
786 })
787 #endif
788 
789 #if defined(__MINGW64__)
790 /*
791  * Use powl() instead of broken pow() of x86_64-w64-mingw32.
792  * This workaround will fix test failures in test_bignum.rb,
793  * test_fixnum.rb and test_float.rb etc.
794  */
795 static inline double
796 rb_w32_pow(double x, double y)
797 {
798  return (double)powl(x, y);
799 }
800 #elif defined(__MINGW64_VERSION_MAJOR)
801 double rb_w32_pow(double x, double y);
802 #endif
803 #define pow rb_w32_pow
804 #endif
805 
806 // mmap tiny emulation
807 #define MAP_FAILED ((void *)-1)
808 
809 #define PROT_READ 0x01
810 #define PROT_WRITE 0x02
811 #define PROT_EXEC 0x04
812 
813 #define MAP_PRIVATE 0x0002
814 #define MAP_ANON 0x1000
815 #define MAP_ANONYMOUS MAP_ANON
816 
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);
820 
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)
824 
825 #if defined(__cplusplus)
826 #if 0
827 { /* satisfy cc-mode */
828 #endif
829 } /* extern "C" { */
830 #endif
831 
832 #endif /* RUBY_WIN32_H */
Definition: win32.h:234
Definition: win32.h:219
Definition: win32.h:223
Definition: win32.h:701
Definition: file.c:3021