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