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