/tools/Ruby/lib/ruby/1.8/i386-mingw32/win32/win32.h

http://github.com/agross/netopenspace · C Header · 626 lines · 513 code · 76 blank · 37 comment · 21 complexity · 9aab4c77e6ac66ba004888efa335edae MD5 · raw file

  1. #ifndef RUBY_WIN32_H
  2. #define RUBY_WIN32_H
  3. /*
  4. * Copyright (c) 1993, Intergraph Corporation
  5. *
  6. * You may distribute under the terms of either the GNU General Public
  7. * License or the Artistic License, as specified in the perl README file.
  8. *
  9. */
  10. //
  11. // Definitions for NT port of Perl
  12. //
  13. //
  14. // Ok now we can include the normal include files.
  15. //
  16. // #include <stdarg.h> conflict with varargs.h?
  17. #if !defined(IN) && !defined(FLOAT)
  18. #ifdef __BORLANDC__
  19. #define USE_WINSOCK2
  20. #endif
  21. #ifdef USE_WINSOCK2
  22. #include <winsock2.h>
  23. #include <ws2tcpip.h>
  24. #include <windows.h>
  25. #else
  26. #include <windows.h>
  27. #include <winsock.h>
  28. #endif
  29. #endif
  30. #define NT 1 /* deprecated */
  31. #ifdef _WIN32_WCE
  32. #undef CharNext
  33. #define CharNext CharNextA
  34. #endif
  35. //
  36. // We're not using Microsoft's "extensions" to C for
  37. // Structured Exception Handling (SEH) so we can nuke these
  38. //
  39. #undef try
  40. #undef except
  41. #undef finally
  42. #undef leave
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <direct.h>
  47. #include <process.h>
  48. #include <time.h>
  49. #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
  50. extern "C++" { /* template without extern "C++" */
  51. #endif
  52. #include <math.h>
  53. #if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
  54. }
  55. #endif
  56. #include <signal.h>
  57. #include <sys/stat.h>
  58. #include <sys/types.h>
  59. #if !defined(__BORLANDC__)
  60. # include <sys/utime.h>
  61. #else
  62. # include <utime.h>
  63. #endif
  64. #include <io.h>
  65. #include <malloc.h>
  66. #ifdef _M_IX86
  67. # define WIN95 1
  68. #else
  69. # undef WIN95
  70. #endif
  71. #ifdef WIN95
  72. extern DWORD rb_w32_osid(void);
  73. #define rb_w32_iswinnt() (rb_w32_osid() == VER_PLATFORM_WIN32_NT)
  74. #define rb_w32_iswin95() (rb_w32_osid() == VER_PLATFORM_WIN32_WINDOWS)
  75. #else
  76. #define rb_w32_iswinnt() TRUE
  77. #define rb_w32_iswin95() FALSE
  78. #endif
  79. #define WNOHANG -1
  80. #undef getc
  81. #undef putc
  82. #undef fgetc
  83. #undef fputc
  84. #undef getchar
  85. #undef putchar
  86. #undef fgetchar
  87. #undef fputchar
  88. #undef utime
  89. #define getc(_stream) rb_w32_getc(_stream)
  90. #define putc(_c, _stream) rb_w32_putc(_c, _stream)
  91. #define fgetc(_stream) getc(_stream)
  92. #define fputc(_c, _stream) putc(_c, _stream)
  93. #define getchar() rb_w32_getc(stdin)
  94. #define putchar(_c) rb_w32_putc(_c, stdout)
  95. #define fgetchar() getchar()
  96. #define fputchar(_c) putchar(_c)
  97. #define utime(_p, _t) rb_w32_utime(_p, _t)
  98. #define strcasecmp(s1, s2) stricmp(s1, s2)
  99. #define strncasecmp(s1, s2, n) strnicmp(s1, s2, n)
  100. #define close(h) rb_w32_close(h)
  101. #define fclose(f) rb_w32_fclose(f)
  102. #define read(f, b, s) rb_w32_read(f, b, s)
  103. #define write(f, b, s) rb_w32_write(f, b, s)
  104. #define getpid() rb_w32_getpid()
  105. #define sleep(x) rb_w32_sleep((x)*1000)
  106. #ifdef __BORLANDC__
  107. #define creat(p, m) _creat(p, m)
  108. #define eof() _eof()
  109. #define filelength(h) _filelength(h)
  110. #define mktemp(t) _mktemp(t)
  111. #define tell(h) _tell(h)
  112. #define unlink(p) _unlink(p)
  113. #define _open _sopen
  114. #define sopen _sopen
  115. #undef fopen
  116. #define fopen(p, m) rb_w32_fopen(p, m)
  117. #undef fdopen
  118. #define fdopen(h, m) rb_w32_fdopen(h, m)
  119. #undef fsopen
  120. #define fsopen(p, m, sh) rb_w32_fsopen(p, m, sh)
  121. #endif
  122. #define fsync(h) _commit(h)
  123. #undef stat
  124. #define stat(path,st) rb_w32_stat(path,st)
  125. #undef execv
  126. #define execv(path,argv) do_aspawn(P_OVERLAY,path,argv)
  127. #if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
  128. #undef isatty
  129. #define isatty(h) rb_w32_isatty(h)
  130. #endif
  131. #undef mkdir
  132. #define mkdir(p, m) rb_w32_mkdir(p, m)
  133. #undef rmdir
  134. #define rmdir(p) rb_w32_rmdir(p)
  135. #undef unlink
  136. #define unlink(p) rb_w32_unlink(p)
  137. struct timezone;
  138. #ifdef __MINGW32__
  139. #undef isascii
  140. #define isascii __isascii
  141. #endif
  142. extern void NtInitialize(int *, char ***);
  143. extern int rb_w32_cmdvector(const char *, char ***);
  144. extern rb_pid_t pipe_exec(const char *, int, FILE **, FILE **);
  145. extern int flock(int fd, int oper);
  146. extern int rb_w32_accept(int, struct sockaddr *, int *);
  147. extern int rb_w32_bind(int, struct sockaddr *, int);
  148. extern int rb_w32_connect(int, struct sockaddr *, int);
  149. extern void rb_w32_fdset(int, fd_set*);
  150. extern void rb_w32_fdclr(int, fd_set*);
  151. extern int rb_w32_fdisset(int, fd_set*);
  152. extern long rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
  153. extern int rb_w32_getpeername(int, struct sockaddr *, int *);
  154. extern int rb_w32_getsockname(int, struct sockaddr *, int *);
  155. extern int rb_w32_getsockopt(int, int, int, char *, int *);
  156. extern int rb_w32_ioctlsocket(int, long, u_long *);
  157. extern int rb_w32_listen(int, int);
  158. extern int rb_w32_recv(int, char *, int, int);
  159. extern int rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *);
  160. extern int rb_w32_send(int, const char *, int, int);
  161. extern int rb_w32_sendto(int, const char *, int, int, struct sockaddr *, int);
  162. extern int rb_w32_setsockopt(int, int, int, char *, int);
  163. extern int rb_w32_shutdown(int, int);
  164. extern int rb_w32_socket(int, int, int);
  165. extern SOCKET rb_w32_get_osfhandle(int);
  166. extern struct hostent * rb_w32_gethostbyaddr(char *, int, int);
  167. extern struct hostent * rb_w32_gethostbyname(char *);
  168. extern int rb_w32_gethostname(char *, int);
  169. extern struct protoent * rb_w32_getprotobyname(char *);
  170. extern struct protoent * rb_w32_getprotobynumber(int);
  171. extern struct servent * rb_w32_getservbyname(char *, char *);
  172. extern struct servent * rb_w32_getservbyport(int, char *);
  173. extern char * rb_w32_getcwd(char *, int);
  174. extern char * rb_w32_getenv(const char *);
  175. extern int rb_w32_rename(const char *, const char *);
  176. extern int rb_w32_stat(const char *, struct stat *);
  177. extern char **rb_w32_get_environ(void);
  178. extern void rb_w32_free_environ(char **);
  179. extern int rb_w32_map_errno(DWORD);
  180. #define vsnprintf(s,n,f,l) rb_w32_vsnprintf(s,n,f,l)
  181. #define snprintf rb_w32_snprintf
  182. extern int rb_w32_vsnprintf(char *, size_t, const char *, va_list);
  183. extern int rb_w32_snprintf(char *, size_t, const char *, ...);
  184. extern int chown(const char *, int, int);
  185. extern int link(char *, char *);
  186. extern int gettimeofday(struct timeval *, struct timezone *);
  187. extern rb_pid_t waitpid (rb_pid_t, int *, int);
  188. extern int do_spawn(int, const char *);
  189. extern int do_aspawn(int, const char *, char **);
  190. extern int kill(int, int);
  191. extern int fcntl(int, int, ...);
  192. extern rb_pid_t rb_w32_getpid(void);
  193. #if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
  194. extern int rb_w32_isatty(int);
  195. #endif
  196. extern int rb_w32_mkdir(const char *, int);
  197. extern int rb_w32_rmdir(const char *);
  198. extern int rb_w32_unlink(const char*);
  199. #ifdef __BORLANDC__
  200. extern FILE *rb_w32_fopen(const char *, const char *);
  201. extern FILE *rb_w32_fdopen(int, const char *);
  202. extern FILE *rb_w32_fsopen(const char *, const char *, int);
  203. #endif
  204. #include <float.h>
  205. #if !defined __MINGW32__ || defined __NO_ISOCEXT
  206. #ifndef isnan
  207. #define isnan(x) _isnan(x)
  208. #endif
  209. #ifndef finite
  210. #define finite(x) _finite(x)
  211. #endif
  212. #ifndef copysign
  213. #define copysign(a, b) _copysign(a, b)
  214. #endif
  215. #ifndef scalb
  216. #define scalb(a, b) _scalb(a, b)
  217. #endif
  218. #endif
  219. #if !defined S_IFIFO && defined _S_IFIFO
  220. #define S_IFIFO _S_IFIFO
  221. #endif
  222. #ifdef __BORLANDC__
  223. #undef S_ISDIR
  224. #undef S_ISFIFO
  225. #undef S_ISBLK
  226. #undef S_ISCHR
  227. #undef S_ISREG
  228. #define S_ISDIR(m) (((unsigned short)(m) & S_IFMT) == S_IFDIR)
  229. #define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO)
  230. #define S_ISBLK(m) (((unsigned short)(m) & S_IFMT) == S_IFBLK)
  231. #define S_ISCHR(m) (((unsigned short)(m) & S_IFMT) == S_IFCHR)
  232. #define S_ISREG(m) (((unsigned short)(m) & S_IFMT) == S_IFREG)
  233. #endif
  234. #if !defined S_IRUSR && !defined __MINGW32__
  235. #define S_IRUSR 0400
  236. #endif
  237. #ifndef S_IRGRP
  238. #define S_IRGRP 0040
  239. #endif
  240. #ifndef S_IROTH
  241. #define S_IROTH 0004
  242. #endif
  243. #if !defined S_IWUSR && !defined __MINGW32__
  244. #define S_IWUSR 0200
  245. #endif
  246. #ifndef S_IWGRP
  247. #define S_IWGRP 0020
  248. #endif
  249. #ifndef S_IWOTH
  250. #define S_IWOTH 0002
  251. #endif
  252. #if !defined S_IXUSR && !defined __MINGW32__
  253. #define S_IXUSR 0100
  254. #endif
  255. #ifndef S_IXGRP
  256. #define S_IXGRP 0010
  257. #endif
  258. #ifndef S_IXOTH
  259. #define S_IXOTH 0001
  260. #endif
  261. //
  262. // define this so we can do inplace editing
  263. //
  264. #define SUFFIX
  265. //
  266. // stubs
  267. //
  268. #if !defined(__BORLANDC__)
  269. extern int ioctl (int, unsigned int, long);
  270. #endif
  271. extern rb_uid_t getuid (void);
  272. extern rb_uid_t geteuid (void);
  273. extern rb_gid_t getgid (void);
  274. extern rb_gid_t getegid (void);
  275. extern int setuid (rb_uid_t);
  276. extern int setgid (rb_gid_t);
  277. extern char *rb_w32_strerror(int);
  278. #define strerror(e) rb_w32_strerror(e)
  279. #define PIPE_BUF 1024
  280. #define LOCK_SH 1
  281. #define LOCK_EX 2
  282. #define LOCK_NB 4
  283. #define LOCK_UN 8
  284. #ifndef SIGINT
  285. #define SIGINT 2
  286. #endif
  287. #ifndef SIGKILL
  288. #define SIGKILL 9
  289. #endif
  290. /* #undef va_start */
  291. /* #undef va_end */
  292. /* winsock error map */
  293. #include <errno.h>
  294. #ifndef EWOULDBLOCK
  295. # define EWOULDBLOCK WSAEWOULDBLOCK
  296. #endif
  297. #ifndef EINPROGRESS
  298. # define EINPROGRESS WSAEINPROGRESS
  299. #endif
  300. #ifndef EALREADY
  301. # define EALREADY WSAEALREADY
  302. #endif
  303. #ifndef ENOTSOCK
  304. # define ENOTSOCK WSAENOTSOCK
  305. #endif
  306. #ifndef EDESTADDRREQ
  307. # define EDESTADDRREQ WSAEDESTADDRREQ
  308. #endif
  309. #ifndef EMSGSIZE
  310. # define EMSGSIZE WSAEMSGSIZE
  311. #endif
  312. #ifndef EPROTOTYPE
  313. # define EPROTOTYPE WSAEPROTOTYPE
  314. #endif
  315. #ifndef ENOPROTOOPT
  316. # define ENOPROTOOPT WSAENOPROTOOPT
  317. #endif
  318. #ifndef EPROTONOSUPPORT
  319. # define EPROTONOSUPPORT WSAEPROTONOSUPPORT
  320. #endif
  321. #ifndef ESOCKTNOSUPPORT
  322. # define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
  323. #endif
  324. #ifndef EOPNOTSUPP
  325. # define EOPNOTSUPP WSAEOPNOTSUPP
  326. #endif
  327. #ifndef EPFNOSUPPORT
  328. # define EPFNOSUPPORT WSAEPFNOSUPPORT
  329. #endif
  330. #ifndef EAFNOSUPPORT
  331. # define EAFNOSUPPORT WSAEAFNOSUPPORT
  332. #endif
  333. #ifndef EADDRINUSE
  334. # define EADDRINUSE WSAEADDRINUSE
  335. #endif
  336. #ifndef EADDRNOTAVAIL
  337. # define EADDRNOTAVAIL WSAEADDRNOTAVAIL
  338. #endif
  339. #ifndef ENETDOWN
  340. # define ENETDOWN WSAENETDOWN
  341. #endif
  342. #ifndef ENETUNREACH
  343. # define ENETUNREACH WSAENETUNREACH
  344. #endif
  345. #ifndef ENETRESET
  346. # define ENETRESET WSAENETRESET
  347. #endif
  348. #ifndef ECONNABORTED
  349. # define ECONNABORTED WSAECONNABORTED
  350. #endif
  351. #ifndef ECONNRESET
  352. # define ECONNRESET WSAECONNRESET
  353. #endif
  354. #ifndef ENOBUFS
  355. # define ENOBUFS WSAENOBUFS
  356. #endif
  357. #ifndef EISCONN
  358. # define EISCONN WSAEISCONN
  359. #endif
  360. #ifndef ENOTCONN
  361. # define ENOTCONN WSAENOTCONN
  362. #endif
  363. #ifndef ESHUTDOWN
  364. # define ESHUTDOWN WSAESHUTDOWN
  365. #endif
  366. #ifndef ETOOMANYREFS
  367. # define ETOOMANYREFS WSAETOOMANYREFS
  368. #endif
  369. #ifndef ETIMEDOUT
  370. # define ETIMEDOUT WSAETIMEDOUT
  371. #endif
  372. #ifndef ECONNREFUSED
  373. # define ECONNREFUSED WSAECONNREFUSED
  374. #endif
  375. #ifndef ELOOP
  376. # define ELOOP WSAELOOP
  377. #endif
  378. /*#define ENAMETOOLONG WSAENAMETOOLONG*/
  379. #ifndef EHOSTDOWN
  380. # define EHOSTDOWN WSAEHOSTDOWN
  381. #endif
  382. #ifndef EHOSTUNREACH
  383. # define EHOSTUNREACH WSAEHOSTUNREACH
  384. #endif
  385. /*#define ENOTEMPTY WSAENOTEMPTY*/
  386. #ifndef EPROCLIM
  387. # define EPROCLIM WSAEPROCLIM
  388. #endif
  389. #ifndef EUSERS
  390. # define EUSERS WSAEUSERS
  391. #endif
  392. #ifndef EDQUOT
  393. # define EDQUOT WSAEDQUOT
  394. #endif
  395. #ifndef ESTALE
  396. # define ESTALE WSAESTALE
  397. #endif
  398. #ifndef EREMOTE
  399. # define EREMOTE WSAEREMOTE
  400. #endif
  401. #define F_SETFL 1
  402. #define O_NONBLOCK 1
  403. #ifdef accept
  404. #undef accept
  405. #endif
  406. #define accept(s, a, l) rb_w32_accept(s, a, l)
  407. #ifdef bind
  408. #undef bind
  409. #endif
  410. #define bind(s, a, l) rb_w32_bind(s, a, l)
  411. #ifdef connect
  412. #undef connect
  413. #endif
  414. #define connect(s, a, l) rb_w32_connect(s, a, l)
  415. #undef FD_SET
  416. #define FD_SET(f, s) rb_w32_fdset(f, s)
  417. #undef FD_CLR
  418. #define FD_CLR(f, s) rb_w32_fdclr(f, s)
  419. #undef FD_ISSET
  420. #define FD_ISSET(f, s) rb_w32_fdisset(f, s)
  421. #undef select
  422. #define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t)
  423. #ifdef getpeername
  424. #undef getpeername
  425. #endif
  426. #define getpeername(s, a, l) rb_w32_getpeername(s, a, l)
  427. #ifdef getsockname
  428. #undef getsockname
  429. #endif
  430. #define getsockname(s, a, l) rb_w32_getsockname(s, a, l)
  431. #ifdef getsockopt
  432. #undef getsockopt
  433. #endif
  434. #define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
  435. #ifdef ioctlsocket
  436. #undef ioctlsocket
  437. #endif
  438. #define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a)
  439. #ifdef listen
  440. #undef listen
  441. #endif
  442. #define listen(s, b) rb_w32_listen(s, b)
  443. #ifdef recv
  444. #undef recv
  445. #endif
  446. #define recv(s, b, l, f) rb_w32_recv(s, b, l, f)
  447. #ifdef recvfrom
  448. #undef recvfrom
  449. #endif
  450. #define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
  451. #ifdef send
  452. #undef send
  453. #endif
  454. #define send(s, b, l, f) rb_w32_send(s, b, l, f)
  455. #ifdef sendto
  456. #undef sendto
  457. #endif
  458. #define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
  459. #ifdef setsockopt
  460. #undef setsockopt
  461. #endif
  462. #define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
  463. #ifdef shutdown
  464. #undef shutdown
  465. #endif
  466. #define shutdown(s, h) rb_w32_shutdown(s, h)
  467. #ifdef socket
  468. #undef socket
  469. #endif
  470. #define socket(s, t, p) rb_w32_socket(s, t, p)
  471. #ifdef gethostbyaddr
  472. #undef gethostbyaddr
  473. #endif
  474. #define gethostbyaddr(a, l, t) rb_w32_gethostbyaddr(a, l, t)
  475. #ifdef gethostbyname
  476. #undef gethostbyname
  477. #endif
  478. #define gethostbyname(n) rb_w32_gethostbyname(n)
  479. #ifdef gethostname
  480. #undef gethostname
  481. #endif
  482. #define gethostname(n, l) rb_w32_gethostname(n, l)
  483. #ifdef getprotobyname
  484. #undef getprotobyname
  485. #endif
  486. #define getprotobyname(n) rb_w32_getprotobyname(n)
  487. #ifdef getprotobynumber
  488. #undef getprotobynumber
  489. #endif
  490. #define getprotobynumber(n) rb_w32_getprotobynumber(n)
  491. #ifdef getservbyname
  492. #undef getservbyname
  493. #endif
  494. #define getservbyname(n, p) rb_w32_getservbyname(n, p)
  495. #ifdef getservbyport
  496. #undef getservbyport
  497. #endif
  498. #define getservbyport(p, pr) rb_w32_getservbyport(p, pr)
  499. #ifdef get_osfhandle
  500. #undef get_osfhandle
  501. #endif
  502. #define get_osfhandle(h) rb_w32_get_osfhandle(h)
  503. #ifdef getcwd
  504. #undef getcwd
  505. #endif
  506. #define getcwd(b, s) rb_w32_getcwd(b, s)
  507. #ifdef getenv
  508. #undef getenv
  509. #endif
  510. #define getenv(n) rb_w32_getenv(n)
  511. #ifdef rename
  512. #undef rename
  513. #endif
  514. #define rename(o, n) rb_w32_rename(o, n)
  515. struct tms {
  516. long tms_utime;
  517. long tms_stime;
  518. long tms_cutime;
  519. long tms_cstime;
  520. };
  521. #ifdef times
  522. #undef times
  523. #endif
  524. #define times(t) rb_w32_times(t)
  525. int rb_w32_times(struct tms *);
  526. /* thread stuff */
  527. HANDLE GetCurrentThreadHandle(void);
  528. void rb_w32_interrupted(void);
  529. int rb_w32_main_context(int arg, void (*handler)(int));
  530. int rb_w32_sleep(unsigned long msec);
  531. void rb_w32_enter_critical(void);
  532. void rb_w32_leave_critical(void);
  533. int rb_w32_putc(int, FILE*);
  534. int rb_w32_getc(FILE*);
  535. int rb_w32_close(int);
  536. int rb_w32_fclose(FILE*);
  537. size_t rb_w32_read(int, void *, size_t);
  538. size_t rb_w32_write(int, const void *, size_t);
  539. int rb_w32_utime(const char *, struct utimbuf *);
  540. #define Sleep(msec) (void)rb_w32_sleep(msec)
  541. /*
  542. == ***CAUTION***
  543. Since this function is very dangerous, ((*NEVER*))
  544. * lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
  545. * use anything like TRAP_BEG...TRAP_END block structure,
  546. in asynchronous_func_t.
  547. */
  548. typedef DWORD (*asynchronous_func_t)(DWORD self, int argc, DWORD* argv);
  549. DWORD rb_w32_asynchronize(asynchronous_func_t func, DWORD self, int argc, DWORD* argv, DWORD intrval);
  550. #endif