]> git.ipfire.org Git - thirdparty/squid.git/blob - include/squid_mswin.h
Windows port: Visual Studio needs winsock2.h before ws2tcpip.h inclusion.
[thirdparty/squid.git] / include / squid_mswin.h
1 /*
2 * $Id: squid_mswin.h,v 1.8 2008/01/20 17:36:43 serassio Exp $
3 *
4 * AUTHOR: Andrey Shorin <tolsty@tushino.com>
5 * AUTHOR: Guido Serassio <serassio@squid-cache.org>
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 */
34
35 #define ACL WindowsACL
36 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
37 #if _MSC_VER == 1400
38 #define _CRT_SECURE_NO_DEPRECATE
39 #pragma warning( disable : 4290 )
40 #pragma warning( disable : 4996 )
41 #endif
42 #endif
43
44 #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
45 # define __USE_FILE_OFFSET64 1
46 #endif
47
48 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
49
50 typedef unsigned char uint8_t;
51 typedef unsigned short uint16_t;
52 typedef unsigned int uint32_t;
53 typedef unsigned __int64 uint64_t;
54
55 typedef long pid_t;
56
57 #if defined __USE_FILE_OFFSET64
58 typedef int64_t off_t;
59 typedef uint64_t ino_t;
60
61 #else
62 typedef long off_t;
63 typedef unsigned long ino_t;
64
65 #endif
66
67 #define INT64_MAX _I64_MAX
68 #define INT64_MIN _I64_MIN
69
70 #include "default_config_file.h"
71 /* Some tricks for MS Compilers */
72 #define __STDC__ 1
73 #pragma include_alias(<dirent.h>, <direct.h>)
74 #define THREADLOCAL __declspec(thread)
75
76 #elif defined(__GNUC__) /* gcc environment */
77
78 #define THREADLOCAL __attribute__((section(".tls")))
79
80 #endif
81
82 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
83 #define alloca _alloca
84 #endif
85 #define chdir _chdir
86 #define dup _dup
87 #define dup2 _dup2
88 #define fdopen _fdopen
89 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
90 #define fileno _fileno
91 #define fstat _fstati64
92 #endif
93 #define ftruncate WIN32_ftruncate
94 #define getcwd _getcwd
95 #define getpid _getpid
96 #define getrusage WIN32_getrusage
97 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
98 #define lseek _lseeki64
99 #define memccpy _memccpy
100 #define mkdir(p) _mkdir(p)
101 #define mktemp _mktemp
102 #endif
103 #define pclose _pclose
104 #define pipe WIN32_pipe
105 #define popen _popen
106 #define putenv _putenv
107 #define setmode _setmode
108 #define sleep(t) Sleep((t)*1000)
109 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
110 #define snprintf _snprintf
111 #define stat _stati64
112 #define strcasecmp _stricmp
113 #define strdup _strdup
114 #define strlwr _strlwr
115 #define strncasecmp _strnicmp
116 #define tempnam _tempnam
117 #endif
118 #define truncate WIN32_truncate
119 #define umask _umask
120 #define unlink _unlink
121 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
122 #define vsnprintf _vsnprintf
123 #endif
124
125 #define O_RDONLY _O_RDONLY
126 #define O_WRONLY _O_WRONLY
127 #define O_RDWR _O_RDWR
128 #define O_APPEND _O_APPEND
129
130 #define O_CREAT _O_CREAT
131 #define O_TRUNC _O_TRUNC
132 #define O_EXCL _O_EXCL
133
134 #define O_TEXT _O_TEXT
135 #define O_BINARY _O_BINARY
136 #define O_RAW _O_BINARY
137 #define O_TEMPORARY _O_TEMPORARY
138 #define O_NOINHERIT _O_NOINHERIT
139 #define O_SEQUENTIAL _O_SEQUENTIAL
140 #define O_RANDOM _O_RANDOM
141 #define O_NDELAY 0
142
143 #define S_IFMT _S_IFMT
144 #define S_IFDIR _S_IFDIR
145 #define S_IFCHR _S_IFCHR
146 #define S_IFREG _S_IFREG
147 #define S_IREAD _S_IREAD
148 #define S_IWRITE _S_IWRITE
149 #define S_IEXEC _S_IEXEC
150
151 #define S_IRWXO 007
152 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
153 #define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
154 #endif
155
156 #define SIGHUP 1 /* hangup */
157 #define SIGKILL 9 /* kill (cannot be caught or ignored) */
158 #define SIGBUS 10 /* bus error */
159 #define SIGPIPE 13 /* write on a pipe with no one to read it */
160 #define SIGCHLD 20 /* to parent on child stop or exit */
161 #define SIGUSR1 30 /* user defined signal 1 */
162 #define SIGUSR2 31 /* user defined signal 2 */
163
164 typedef unsigned short int ushort;
165 typedef int uid_t;
166 typedef int gid_t;
167
168 struct passwd {
169 char *pw_name; /* user name */
170 char *pw_passwd; /* user password */
171 uid_t pw_uid; /* user id */
172 gid_t pw_gid; /* group id */
173 char *pw_gecos; /* real name */
174 char *pw_dir; /* home directory */
175 char *pw_shell; /* shell program */
176 };
177
178 struct group {
179 char *gr_name; /* group name */
180 char *gr_passwd; /* group password */
181 gid_t gr_gid; /* group id */
182 char **gr_mem; /* group members */
183 };
184
185 struct statfs {
186 long f_type; /* type of filesystem (see below) */
187 long f_bsize; /* optimal transfer block size */
188 long f_blocks; /* total data blocks in file system */
189 long f_bfree; /* free blocks in fs */
190 long f_bavail; /* free blocks avail to non-superuser */
191 long f_files; /* total file nodes in file system */
192 long f_ffree; /* free file nodes in fs */
193 long f_fsid; /* file system id */
194 long f_namelen; /* maximum length of filenames */
195 long f_spare[6]; /* spare for later */
196 };
197
198 #ifndef HAVE_GETTIMEOFDAY
199 struct timezone
200 {
201 int tz_minuteswest; /* minutes west of Greenwich */
202 int tz_dsttime; /* type of dst correction */
203 };
204 #endif
205
206 #define CHANGE_FD_SETSIZE 1
207 #if CHANGE_FD_SETSIZE && SQUID_MAXFD > DEFAULT_FD_SETSIZE
208 #define FD_SETSIZE SQUID_MAXFD
209 #endif
210
211 #include <stddef.h>
212 #include <process.h>
213 #include <errno.h>
214 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
215 #include <winsock2.h>
216 #endif
217 #include <ws2tcpip.h>
218 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
219 /* Hack to suppress compiler warnings on FD_SET() & FD_CLR() */
220 #pragma warning (push)
221 #pragma warning (disable:4142)
222 #endif
223 /* prevent inclusion of wingdi.h */
224 #define NOGDI
225 #include <ws2spi.h>
226 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
227 #pragma warning (pop)
228 #include "readdir.h"
229 #else
230 #include <io.h>
231 #include <stdlib.h>
232 #include <sys/types.h>
233 #endif
234
235 typedef char * caddr_t;
236
237 #undef FD_CLOSE
238 #undef FD_OPEN
239 #undef FD_READ
240 #undef FD_WRITE
241 #define EISCONN WSAEISCONN
242 #define EINPROGRESS WSAEINPROGRESS
243 #define EWOULDBLOCK WSAEWOULDBLOCK
244 #define EALREADY WSAEALREADY
245 #define ETIMEDOUT WSAETIMEDOUT
246 #define ECONNREFUSED WSAECONNREFUSED
247 #define ECONNRESET WSAECONNRESET
248 #define ENOTCONN WSAENOTCONN
249 #define ERESTART WSATRY_AGAIN
250 #define EAFNOSUPPORT WSAEAFNOSUPPORT
251
252 #undef h_errno
253 #define h_errno errno /* we'll set it ourselves */
254
255 #undef FD_CLR
256 #define FD_CLR(fd, set) do { \
257 u_int __i; \
258 SOCKET __sock = fd_table[fd].win32.handle; \
259 for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
260 if (((fd_set FAR *)(set))->fd_array[__i] == __sock) { \
261 while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
262 ((fd_set FAR *)(set))->fd_array[__i] = \
263 ((fd_set FAR *)(set))->fd_array[__i+1]; \
264 __i++; \
265 } \
266 ((fd_set FAR *)(set))->fd_count--; \
267 break; \
268 } \
269 } \
270 } while(0)
271
272 #undef FD_SET
273 #define FD_SET(fd, set) do { \
274 u_int __i; \
275 SOCKET __sock = fd_table[fd].win32.handle; \
276 for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count; __i++) { \
277 if (((fd_set FAR *)(set))->fd_array[__i] == (__sock)) { \
278 break; \
279 } \
280 } \
281 if (__i == ((fd_set FAR *)(set))->fd_count) { \
282 if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) { \
283 ((fd_set FAR *)(set))->fd_array[__i] = (__sock); \
284 ((fd_set FAR *)(set))->fd_count++; \
285 } \
286 } \
287 } while(0)
288
289 #undef FD_ISSET
290 #define FD_ISSET(fd, set) Win32__WSAFDIsSet(fd, (fd_set FAR *)(set))
291
292 /* internal to Microsoft CRTLIB */
293 typedef struct {
294 long osfhnd; /* underlying OS file HANDLE */
295 char osfile; /* attributes of file (e.g., open in text mode?) */
296 char pipech; /* one char buffer for handles opened on pipes */
297 #ifdef _MT
298 int lockinitflag;
299 CRITICAL_SECTION lock;
300 #endif /* _MT */
301 } ioinfo;
302 #define IOINFO_L2E 5
303 #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
304 #define _pioinfo(i) ( __pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)) )
305 #define _osfile(i) ( _pioinfo(i)->osfile )
306 #define _osfhnd(i) ( _pioinfo(i)->osfhnd )
307 #define FOPEN 0x01 /* file handle open */
308
309 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
310
311 SQUIDCEXTERN _CRTIMP ioinfo * __pioinfo[];
312 SQUIDCEXTERN int __cdecl _free_osfhnd(int);
313
314 #elif defined(__MINGW32__) /* MinGW environment */
315
316 __MINGW_IMPORT ioinfo * __pioinfo[];
317 SQUIDCEXTERN int _free_osfhnd(int);
318
319 #endif
320
321 SQUIDCEXTERN THREADLOCAL int ws32_result;
322
323 #define strerror(e) WIN32_strerror(e)
324
325 #ifdef __cplusplus
326
327 inline
328 int close(int fd)
329 {
330 char l_so_type[sizeof(int)];
331 int l_so_type_siz = sizeof(l_so_type);
332 SOCKET sock = _get_osfhandle(fd);
333
334 if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0){
335 int result = 0;
336 if (closesocket(sock) == SOCKET_ERROR) {
337 errno = WSAGetLastError();
338 result = 1;
339 }
340 _free_osfhnd(fd);
341 _osfile(fd) = 0;
342 return result;
343 }
344 else
345 return _close(fd);
346 }
347
348 #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
349
350 #ifndef _S_IREAD
351 #define _S_IREAD 0x0100
352 #endif
353
354 #ifndef _S_IWRITE
355 #define _S_IWRITE 0x0080
356 #endif
357
358 inline
359 int open(const char *filename, int oflag, int pmode = 0)
360 {
361 return _open(filename, oflag, pmode & (_S_IREAD | _S_IWRITE));
362 }
363 #endif
364
365 inline
366 int read(int fd, void * buf, size_t siz)
367 {
368 char l_so_type[sizeof(int)];
369 int l_so_type_siz = sizeof(l_so_type);
370 SOCKET sock = _get_osfhandle(fd);
371
372 if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0)
373 return ::recv(sock, (char FAR *) buf, (int)siz, 0);
374 else
375 return _read(fd, buf, (unsigned int)siz);
376 }
377
378 inline
379 int write(int fd, const void * buf, size_t siz)
380 {
381 char l_so_type[sizeof(int)];
382 int l_so_type_siz = sizeof(l_so_type);
383 SOCKET sock = _get_osfhandle(fd);
384
385 if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0)
386 return ::send(sock, (char FAR *) buf, siz, 0);
387 else
388 return _write(fd, buf, siz);
389 }
390
391 inline
392 char *index(const char *s, int c)
393 {
394 return (char *)strchr(s,c);
395 }
396
397 namespace Squid {
398
399 inline
400 int accept(int s, struct sockaddr * a, size_t * l)
401 {
402 SOCKET result;
403 if ((result = ::accept(_get_osfhandle(s), a, (int *)l)) == INVALID_SOCKET) {
404 if (WSAEMFILE == (errno = WSAGetLastError()))
405 errno = EMFILE;
406 return -1;
407 }
408 else
409 return _open_osfhandle(result, 0);
410 }
411
412 inline
413 int bind(int s, struct sockaddr * n, int l)
414 {
415 if (::bind(_get_osfhandle(s),n,l) == SOCKET_ERROR) {
416 errno = WSAGetLastError();
417 return -1;
418 }
419 else
420 return 0;
421 }
422
423 inline
424 int connect(int s, const struct sockaddr * n, int l)
425 {
426 if (::connect(_get_osfhandle(s),n,l) == SOCKET_ERROR) {
427 if (WSAEMFILE == (errno = WSAGetLastError()))
428 errno = EMFILE;
429 return -1;
430 }
431 else
432 return 0;
433 }
434
435 inline
436 struct hostent * gethostbyname (const char *n)
437 {
438 HOSTENT FAR * result;
439 if ((result = ::gethostbyname(n)) == NULL)
440 errno = WSAGetLastError();
441 return result;
442 }
443 #define gethostbyname(n) Squid::gethostbyname(n)
444
445 inline
446 SERVENT FAR* getservbyname (const char * n, const char * p)
447 {
448 SERVENT FAR * result;
449 if ((result = ::getservbyname(n, p)) == NULL)
450 errno = WSAGetLastError();
451 return result;
452 }
453 #define getservbyname(n,p) Squid::getservbyname(n,p)
454
455 inline
456 HOSTENT FAR * gethostbyaddr(const char * a, int l, int t)
457 {
458 HOSTENT FAR * result;
459 if ((result = ::gethostbyaddr(a, l, t)) == NULL)
460 errno = WSAGetLastError();
461 return result;
462 }
463 #define gethostbyaddr(a,l,t) Squid::gethostbyaddr(a,l,t)
464
465 inline
466 int getsockname(int s, struct sockaddr * n, size_t * l)
467 {
468 if ((::getsockname(_get_osfhandle(s), n, (int *)l)) == SOCKET_ERROR) {
469 errno = WSAGetLastError();
470 return -1;
471 }
472 else
473 return 0;
474 }
475
476 inline
477 int gethostname(char * n, size_t l)
478 {
479 if ((::gethostname(n, l)) == SOCKET_ERROR) {
480 errno = WSAGetLastError();
481 return -1;
482 }
483 else
484 return 0;
485 }
486 #define gethostname(n,l) Squid::gethostname(n,l)
487
488 inline
489 int getsockopt(int s, int l, int o, void * v, int * n)
490 {
491 Sleep(1);
492 if ((::getsockopt(_get_osfhandle(s), l, o,(char *) v, n)) == SOCKET_ERROR) {
493 errno = WSAGetLastError();
494 return -1;
495 }
496 else
497 return 0;
498 }
499
500 /* Simple ioctl() emulation */
501 inline
502 int ioctl(int s, int c, void * a)
503 {
504 if ((::ioctlsocket(_get_osfhandle(s), c, (u_long FAR *)a)) == SOCKET_ERROR) {
505 errno = WSAGetLastError();
506 return -1;
507 }
508 else
509 return 0;
510 }
511
512 inline
513 int ioctlsocket(int s, long c, u_long FAR * a)
514 {
515 if ((::ioctlsocket(_get_osfhandle(s), c, a)) == SOCKET_ERROR) {
516 errno = WSAGetLastError();
517 return -1;
518 }
519 else
520 return 0;
521 }
522
523 inline
524 int listen(int s, int b)
525 {
526 if (::listen(_get_osfhandle(s), b) == SOCKET_ERROR) {
527 if (WSAEMFILE == (errno = WSAGetLastError()))
528 errno = EMFILE;
529 return -1;
530 }
531 else
532 return 0;
533 }
534 #define listen(s,b) Squid::listen(s,b)
535
536 inline
537 int recv(int s, void * b, size_t l, int f)
538 {
539 int result;
540 if ((result = ::recv(_get_osfhandle(s), (char *)b, l, f)) == SOCKET_ERROR) {
541 errno = WSAGetLastError();
542 return -1;
543 }
544 else
545 return result;
546 }
547
548 inline
549 int recvfrom(int s, void * b, size_t l, int f, struct sockaddr * fr, size_t * fl)
550 {
551 int result;
552 if ((result = ::recvfrom(_get_osfhandle(s), (char *)b, l, f, fr, (int *)fl)) == SOCKET_ERROR) {
553 errno = WSAGetLastError();
554 return -1;
555 }
556 else
557 return result;
558 }
559
560 inline
561 int select(int n, fd_set * r, fd_set * w, fd_set * e, struct timeval * t)
562 {
563 int result;
564 if ((result = ::select(n,r,w,e,t)) == SOCKET_ERROR) {
565 errno = WSAGetLastError();
566 return -1;
567 }
568 else
569 return result;
570 }
571 #define select(n,r,w,e,t) Squid::select(n,r,w,e,t)
572
573 inline
574 int send(int s, const void * b, size_t l, int f)
575 {
576 int result;
577 if ((result = ::send(_get_osfhandle(s), (char *)b, l, f)) == SOCKET_ERROR) {
578 errno = WSAGetLastError();
579 return -1;
580 }
581 else
582 return result;
583 }
584
585 inline
586 int sendto(int s, const void * b, size_t l, int f, const struct sockaddr * t, int tl)
587 {
588 int result;
589 if ((result = ::sendto(_get_osfhandle(s), (char *)b, l, f, t, tl)) == SOCKET_ERROR) {
590 errno = WSAGetLastError();
591 return -1;
592 }
593 else
594 return result;
595 }
596
597 inline
598 int setsockopt(SOCKET s, int l, int o, const char * v, int n)
599 {
600 SOCKET socket;
601
602 socket = ((s == INVALID_SOCKET) ? s : (SOCKET)_get_osfhandle((int)s));
603
604 if (::setsockopt(socket, l, o, v, n) == SOCKET_ERROR) {
605 errno = WSAGetLastError();
606 return -1;
607 }
608 else
609 return 0;
610 }
611 #define setsockopt(s,l,o,v,n) Squid::setsockopt(s,l,o,v,n)
612
613 inline
614 int shutdown(int s, int h)
615 {
616 if (::shutdown(_get_osfhandle(s),h) == SOCKET_ERROR) {
617 errno = WSAGetLastError();
618 return -1;
619 }
620 else
621 return 0;
622 }
623
624 inline
625 int socket(int f, int t, int p)
626 {
627 SOCKET result;
628 if ((result = ::socket(f, t, p)) == INVALID_SOCKET) {
629 if (WSAEMFILE == (errno = WSAGetLastError()))
630 errno = EMFILE;
631 return -1;
632 }
633 else
634 return _open_osfhandle(result, 0);
635 }
636 #define socket(f,t,p) Squid::socket(f,t,p)
637
638 inline
639 int WSAAsyncSelect(int s, HWND h, unsigned int w, long e)
640 {
641 if (::WSAAsyncSelect(_get_osfhandle(s), h, w, e) == SOCKET_ERROR) {
642 errno = WSAGetLastError();
643 return -1;
644 }
645 else
646 return 0;
647 }
648
649 #undef WSADuplicateSocket
650 inline
651 int WSADuplicateSocket(int s, DWORD n, LPWSAPROTOCOL_INFO l)
652 {
653 #ifdef UNICODE
654 if (::WSADuplicateSocketW(_get_osfhandle(s), n, l) == SOCKET_ERROR) {
655 #else
656 if (::WSADuplicateSocketA(_get_osfhandle(s), n, l) == SOCKET_ERROR) {
657 #endif
658 errno = WSAGetLastError();
659 return -1;
660 }
661 else
662 return 0;
663 }
664
665 #undef WSASocket
666 inline
667 int WSASocket(int a, int t, int p, LPWSAPROTOCOL_INFO i, GROUP g, DWORD f)
668 {
669 SOCKET result;
670 #ifdef UNICODE
671 if ((result = ::WSASocketW(a, t, p, i, g, f)) == INVALID_SOCKET) {
672 #else
673 if ((result = ::WSASocketA(a, t, p, i, g, f)) == INVALID_SOCKET) {
674 #endif
675 if (WSAEMFILE == (errno = WSAGetLastError()))
676 errno = EMFILE;
677 return -1;
678 }
679 else
680 return _open_osfhandle(result, 0);
681 }
682
683 } /* namespace Squid */
684
685 #else /* #ifdef __cplusplus */
686 #define connect(s,n,l) \
687 (SOCKET_ERROR == connect(_get_osfhandle(s),n,l) ? \
688 (WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1, -1) : 0)
689 #define gethostbyname(n) \
690 (NULL == ((HOSTENT FAR*)(ws32_result = (int)gethostbyname(n))) ? \
691 (errno = WSAGetLastError()), (HOSTENT FAR*)NULL : (HOSTENT FAR*)ws32_result)
692 #define gethostname(n,l) \
693 (SOCKET_ERROR == gethostname(n,l) ? \
694 (errno = WSAGetLastError()), -1 : 0)
695 #define recv(s,b,l,f) \
696 (SOCKET_ERROR == (ws32_result = recv(_get_osfhandle(s),b,l,f)) ? \
697 (errno = WSAGetLastError()), -1 : ws32_result)
698 #define sendto(s,b,l,f,t,tl) \
699 (SOCKET_ERROR == (ws32_result = sendto(_get_osfhandle(s),b,l,f,t,tl)) ? \
700 (errno = WSAGetLastError()), -1 : ws32_result)
701 #define select(n,r,w,e,t) \
702 (SOCKET_ERROR == (ws32_result = select(n,r,w,e,t)) ? \
703 (errno = WSAGetLastError()), -1 : ws32_result)
704 #define socket(f,t,p) \
705 (INVALID_SOCKET == ((SOCKET)(ws32_result = (int)socket(f,t,p))) ? \
706 ((WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1), -1) : \
707 (SOCKET)_open_osfhandle(ws32_result,0))
708 #define write _write /* Needed in util.c */
709 #define open _open /* Needed in win32lib.c */
710 #endif /* #ifdef __cplusplus */
711
712 #define RUSAGE_SELF 0 /* calling process */
713 #define RUSAGE_CHILDREN -1 /* terminated child processes */
714
715 struct rusage {
716 struct timeval ru_utime; /* user time used */
717 struct timeval ru_stime; /* system time used */
718 long ru_maxrss; /* integral max resident set size */
719 long ru_ixrss; /* integral shared text memory size */
720 long ru_idrss; /* integral unshared data size */
721 long ru_isrss; /* integral unshared stack size */
722 long ru_minflt; /* page reclaims */
723 long ru_majflt; /* page faults */
724 long ru_nswap; /* swaps */
725 long ru_inblock; /* block input operations */
726 long ru_oublock; /* block output operations */
727 long ru_msgsnd; /* messages sent */
728 long ru_msgrcv; /* messages received */
729 long ru_nsignals; /* signals received */
730 long ru_nvcsw; /* voluntary context switches */
731 long ru_nivcsw; /* involuntary context switches */
732 };
733
734 #undef ACL