~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to include/squid_mswin.h

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: squid_mswin.h,v 1.2 2006/09/09 15:29:59 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 short uint16_t;
 
51
typedef unsigned int uint32_t;
 
52
typedef unsigned __int64 uint64_t;
 
53
 
 
54
typedef long pid_t;
 
55
 
 
56
#if defined __USE_FILE_OFFSET64
 
57
typedef int64_t off_t;
 
58
typedef uint64_t ino_t;
 
59
 
 
60
#else
 
61
typedef long off_t;
 
62
typedef unsigned long ino_t;
 
63
 
 
64
#endif
 
65
 
 
66
#define INT64_MAX _I64_MAX
 
67
#define INT64_MIN _I64_MIN
 
68
#define PRId64 "I64d"
 
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
struct timezone 
 
199
  {
 
200
    int tz_minuteswest; /* minutes west of Greenwich */
 
201
    int tz_dsttime;     /* type of dst correction */
 
202
  };
 
203
 
 
204
#define CHANGE_FD_SETSIZE 1
 
205
#if CHANGE_FD_SETSIZE && SQUID_MAXFD > DEFAULT_FD_SETSIZE
 
206
#define FD_SETSIZE SQUID_MAXFD
 
207
#endif
 
208
 
 
209
#include <stddef.h>
 
210
#include <process.h>
 
211
#include <errno.h>
 
212
#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
 
213
/* Hack to suppress compiler warnings on FD_SET() & FD_CLR() */
 
214
#pragma warning (push)
 
215
#pragma warning (disable:4142)
 
216
#endif
 
217
/* prevent inclusion of wingdi.h */
 
218
#define NOGDI
 
219
#include <ws2spi.h>
 
220
#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
 
221
#pragma warning (pop)
 
222
#include "readdir.h"
 
223
#else
 
224
#include <io.h>
 
225
#include <stdlib.h>
 
226
#include <sys/types.h> 
 
227
#endif
 
228
 
 
229
typedef char * caddr_t;
 
230
 
 
231
#undef FD_CLOSE
 
232
#undef FD_OPEN
 
233
#undef FD_READ
 
234
#undef FD_WRITE
 
235
#define EISCONN WSAEISCONN
 
236
#define EINPROGRESS WSAEINPROGRESS 
 
237
#define EWOULDBLOCK WSAEWOULDBLOCK
 
238
#define EALREADY WSAEALREADY
 
239
#define ETIMEDOUT WSAETIMEDOUT
 
240
#define ECONNREFUSED WSAECONNREFUSED
 
241
#define ECONNRESET WSAECONNRESET
 
242
#define ENOTCONN WSAENOTCONN
 
243
#define ERESTART WSATRY_AGAIN
 
244
 
 
245
#undef h_errno
 
246
#define h_errno errno /* we'll set it ourselves */
 
247
 
 
248
#undef FD_CLR
 
249
#define FD_CLR(fd, set) do { \
 
250
    u_int __i; \
 
251
    SOCKET __sock = fd_table[fd].win32.handle; \
 
252
    for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
 
253
        if (((fd_set FAR *)(set))->fd_array[__i] == __sock) { \
 
254
            while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
 
255
                ((fd_set FAR *)(set))->fd_array[__i] = \
 
256
                    ((fd_set FAR *)(set))->fd_array[__i+1]; \
 
257
                __i++; \
 
258
            } \
 
259
            ((fd_set FAR *)(set))->fd_count--; \
 
260
            break; \
 
261
        } \
 
262
    } \
 
263
} while(0)
 
264
 
 
265
#undef FD_SET
 
266
#define FD_SET(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
            break; \
 
272
        } \
 
273
    } \
 
274
    if (__i == ((fd_set FAR *)(set))->fd_count) { \
 
275
        if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) { \
 
276
            ((fd_set FAR *)(set))->fd_array[__i] = (__sock); \
 
277
            ((fd_set FAR *)(set))->fd_count++; \
 
278
        } \
 
279
    } \
 
280
} while(0)
 
281
 
 
282
#undef FD_ISSET
 
283
#define FD_ISSET(fd, set) Win32__WSAFDIsSet(fd, (fd_set FAR *)(set))
 
284
 
 
285
/* internal to Microsoft CRTLIB */
 
286
typedef struct {
 
287
        long osfhnd;    /* underlying OS file HANDLE */
 
288
        char osfile;    /* attributes of file (e.g., open in text mode?) */
 
289
        char pipech;    /* one char buffer for handles opened on pipes */
 
290
#ifdef _MT
 
291
        int lockinitflag;
 
292
        CRITICAL_SECTION lock;
 
293
#endif  /* _MT */
 
294
    }   ioinfo;
 
295
#define IOINFO_L2E          5
 
296
#define IOINFO_ARRAY_ELTS   (1 << IOINFO_L2E)
 
297
#define _pioinfo(i) ( __pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)) )
 
298
#define _osfile(i)  ( _pioinfo(i)->osfile )
 
299
#define _osfhnd(i)  ( _pioinfo(i)->osfhnd )
 
300
#define FOPEN           0x01    /* file handle open */
 
301
 
 
302
#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
 
303
 
 
304
SQUIDCEXTERN _CRTIMP ioinfo * __pioinfo[];
 
305
SQUIDCEXTERN int __cdecl _free_osfhnd(int);
 
306
 
 
307
#elif defined(__MINGW32__) /* MinGW environment */
 
308
 
 
309
__MINGW_IMPORT ioinfo * __pioinfo[];
 
310
SQUIDCEXTERN int _free_osfhnd(int);
 
311
 
 
312
#endif
 
313
 
 
314
SQUIDCEXTERN THREADLOCAL int ws32_result;
 
315
 
 
316
#define strerror(e) WIN32_strerror(e)
 
317
 
 
318
#ifdef __cplusplus
 
319
 
 
320
inline
 
321
int close(int fd)
 
322
{
 
323
    char l_so_type[sizeof(int)];
 
324
    int l_so_type_siz = sizeof(l_so_type);
 
325
    SOCKET sock = _get_osfhandle(fd);
 
326
 
 
327
    if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0){
 
328
        int result = 0;
 
329
            if (closesocket(sock) == SOCKET_ERROR) {
 
330
                errno = WSAGetLastError();
 
331
                result = 1;
 
332
            }
 
333
            _free_osfhnd(fd);
 
334
            _osfile(fd) = 0;
 
335
            return result;
 
336
    }
 
337
    else
 
338
            return _close(fd);
 
339
}
 
340
 
 
341
#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
 
342
 
 
343
#ifndef _S_IREAD
 
344
#define _S_IREAD 0x0100
 
345
#endif
 
346
 
 
347
#ifndef _S_IWRITE
 
348
#define _S_IWRITE 0x0080
 
349
#endif
 
350
 
 
351
inline
 
352
int open(const char *filename, int oflag, int pmode = 0)
 
353
{
 
354
    return _open(filename, oflag, pmode & (_S_IREAD | _S_IWRITE));
 
355
}
 
356
#endif
 
357
 
 
358
inline
 
359
int read(int fd, void * buf, size_t siz)
 
360
{
 
361
    char l_so_type[sizeof(int)];
 
362
    int l_so_type_siz = sizeof(l_so_type);
 
363
    SOCKET sock = _get_osfhandle(fd);
 
364
 
 
365
    if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0)
 
366
        return ::recv(sock, (char FAR *) buf, (int)siz, 0);
 
367
    else
 
368
        return _read(fd, buf, (unsigned int)siz);
 
369
}
 
370
 
 
371
inline
 
372
int write(int fd, const void * buf, size_t siz)
 
373
{
 
374
    char l_so_type[sizeof(int)];
 
375
    int l_so_type_siz = sizeof(l_so_type);
 
376
    SOCKET sock = _get_osfhandle(fd);
 
377
 
 
378
    if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0)
 
379
        return ::send(sock, (char FAR *) buf, siz, 0);
 
380
    else
 
381
        return _write(fd, buf, siz);
 
382
}
 
383
 
 
384
inline 
 
385
char *index(const char *s, int c)
 
386
{
 
387
    return (char *)strchr(s,c);
 
388
}
 
389
 
 
390
namespace Squid {
 
391
 
 
392
inline
 
393
int accept(int s, struct sockaddr * a, int * l)
 
394
{
 
395
    SOCKET result;
 
396
    if ((result = ::accept(_get_osfhandle(s), a, l)) == INVALID_SOCKET) {
 
397
        if (WSAEMFILE == (errno = WSAGetLastError()))
 
398
            errno = EMFILE;
 
399
        return -1;
 
400
    }
 
401
    else
 
402
        return _open_osfhandle(result, 0);
 
403
}
 
404
 
 
405
inline
 
406
int bind(int s, struct sockaddr * n, int l)
 
407
{
 
408
    if (::bind(_get_osfhandle(s),n,l) == SOCKET_ERROR) {
 
409
        errno = WSAGetLastError();
 
410
        return -1;
 
411
    }
 
412
    else
 
413
        return 0;
 
414
}
 
415
 
 
416
inline
 
417
int connect(int s, const struct sockaddr * n, int l)
 
418
{
 
419
    if (::connect(_get_osfhandle(s),n,l) == SOCKET_ERROR) {
 
420
        if (WSAEMFILE == (errno = WSAGetLastError()))
 
421
            errno = EMFILE;
 
422
        return -1;
 
423
    }
 
424
    else
 
425
        return 0;
 
426
}
 
427
 
 
428
inline 
 
429
struct hostent * gethostbyname (const char *n)
 
430
{
 
431
    HOSTENT FAR * result; 
 
432
    if ((result = ::gethostbyname(n)) == NULL)
 
433
        errno = WSAGetLastError();
 
434
    return result;
 
435
}
 
436
#define gethostbyname(n) Squid::gethostbyname(n)
 
437
 
 
438
inline
 
439
SERVENT FAR* getservbyname (const char * n, const char * p)
 
440
{
 
441
    SERVENT FAR * result;
 
442
    if ((result = ::getservbyname(n, p)) == NULL)
 
443
        errno = WSAGetLastError();
 
444
    return result;
 
445
}
 
446
#define getservbyname(n,p) Squid::getservbyname(n,p)
 
447
 
 
448
inline
 
449
HOSTENT FAR * gethostbyaddr(const char * a, int l, int t)
 
450
{
 
451
    HOSTENT FAR * result;
 
452
    if ((result = ::gethostbyaddr(a, l, t)) == NULL)
 
453
        errno = WSAGetLastError();
 
454
    return result;
 
455
}
 
456
#define gethostbyaddr(a,l,t) Squid::gethostbyaddr(a,l,t)
 
457
 
 
458
inline
 
459
int getsockname(int s, struct sockaddr * n, int * l)
 
460
{
 
461
    if ((::getsockname(_get_osfhandle(s), n, l)) == SOCKET_ERROR) {
 
462
        errno = WSAGetLastError();
 
463
        return -1;
 
464
    }
 
465
    else
 
466
        return 0;
 
467
}
 
468
 
 
469
inline
 
470
int gethostname(char * n, size_t l)
 
471
{
 
472
    if ((::gethostname(n, l)) == SOCKET_ERROR) {
 
473
        errno = WSAGetLastError();
 
474
        return -1;
 
475
    }
 
476
    else
 
477
        return 0;
 
478
}
 
479
#define gethostname(n,l) Squid::gethostname(n,l)
 
480
 
 
481
inline
 
482
int getsockopt(int s, int l, int o, void * v, int * n)
 
483
{
 
484
    Sleep(1);
 
485
    if ((::getsockopt(_get_osfhandle(s), l, o,(char *) v, n)) == SOCKET_ERROR) {
 
486
        errno = WSAGetLastError();
 
487
        return -1;
 
488
    }
 
489
    else
 
490
        return 0;
 
491
}
 
492
 
 
493
/* Simple ioctl() emulation */
 
494
inline
 
495
int ioctl(int s, int c, void * a)
 
496
{
 
497
    if ((::ioctlsocket(_get_osfhandle(s), c, (u_long FAR *)a)) == SOCKET_ERROR) {
 
498
        errno = WSAGetLastError();
 
499
        return -1;
 
500
    }
 
501
    else
 
502
        return 0;
 
503
}
 
504
 
 
505
inline
 
506
int ioctlsocket(int s, long c, u_long FAR * a)
 
507
{
 
508
    if ((::ioctlsocket(_get_osfhandle(s), c, a)) == SOCKET_ERROR) {
 
509
        errno = WSAGetLastError();
 
510
        return -1;
 
511
    }
 
512
    else
 
513
        return 0;
 
514
}
 
515
 
 
516
inline
 
517
int listen(int s, int b)
 
518
{
 
519
    if (::listen(_get_osfhandle(s), b) == SOCKET_ERROR) {
 
520
        if (WSAEMFILE == (errno = WSAGetLastError()))
 
521
            errno = EMFILE;
 
522
        return -1;
 
523
    }
 
524
    else
 
525
        return 0;
 
526
}
 
527
#define listen(s,b) Squid::listen(s,b)
 
528
 
 
529
inline
 
530
int recv(int s, void * b, size_t l, int f)
 
531
{
 
532
    int result;
 
533
    if ((result = ::recv(_get_osfhandle(s), (char *)b, l, f)) == SOCKET_ERROR) {
 
534
        errno = WSAGetLastError();
 
535
        return -1;
 
536
    }
 
537
    else
 
538
        return result;
 
539
}
 
540
 
 
541
inline
 
542
int recvfrom(int s, void * b, size_t l, int f, struct sockaddr * fr, int * fl)
 
543
{
 
544
    int result;
 
545
    if ((result = ::recvfrom(_get_osfhandle(s), (char *)b, l, f, fr, fl)) == SOCKET_ERROR) {
 
546
        errno = WSAGetLastError();
 
547
        return -1;
 
548
    }
 
549
    else
 
550
        return result;
 
551
}
 
552
 
 
553
inline
 
554
int select(int n, fd_set * r, fd_set * w, fd_set * e, struct timeval * t)
 
555
{
 
556
    int result;
 
557
    if ((result = ::select(n,r,w,e,t)) == SOCKET_ERROR) {
 
558
        errno = WSAGetLastError();
 
559
        return -1;
 
560
    }
 
561
    else
 
562
        return result;
 
563
}
 
564
#define select(n,r,w,e,t) Squid::select(n,r,w,e,t)
 
565
 
 
566
inline
 
567
int send(int s, const void * b, size_t l, int f)
 
568
{
 
569
    int result;
 
570
    if ((result = ::send(_get_osfhandle(s), (char *)b, l, f)) == SOCKET_ERROR) {
 
571
        errno = WSAGetLastError();
 
572
        return -1;
 
573
    }
 
574
    else
 
575
        return result;
 
576
}
 
577
 
 
578
inline
 
579
int sendto(int s, const void * b, size_t l, int f, const struct sockaddr * t, int tl)
 
580
{
 
581
    int result;
 
582
    if ((result = ::sendto(_get_osfhandle(s), (char *)b, l, f, t, tl)) == SOCKET_ERROR) {
 
583
        errno = WSAGetLastError();
 
584
        return -1;
 
585
    }
 
586
    else
 
587
        return result;
 
588
}
 
589
 
 
590
inline
 
591
int setsockopt(SOCKET s, int l, int o, const char * v, int n)
 
592
{
 
593
    SOCKET socket;
 
594
 
 
595
    socket = ((s == INVALID_SOCKET) ? s : (SOCKET)_get_osfhandle((int)s));
 
596
 
 
597
    if (::setsockopt(socket, l, o, v, n) == SOCKET_ERROR) {
 
598
        errno = WSAGetLastError();
 
599
        return -1;
 
600
    }
 
601
    else
 
602
        return 0;
 
603
}
 
604
#define setsockopt(s,l,o,v,n) Squid::setsockopt(s,l,o,v,n)
 
605
 
 
606
inline
 
607
int shutdown(int s, int h)
 
608
{
 
609
    if (::shutdown(_get_osfhandle(s),h) == SOCKET_ERROR) {
 
610
        errno = WSAGetLastError();
 
611
        return -1;
 
612
    }
 
613
    else
 
614
        return 0;
 
615
}
 
616
 
 
617
inline
 
618
int socket(int f, int t, int p)
 
619
{
 
620
    SOCKET result;
 
621
    if ((result = ::socket(f, t, p)) == INVALID_SOCKET) {
 
622
        if (WSAEMFILE == (errno = WSAGetLastError()))
 
623
            errno = EMFILE;
 
624
        return -1;
 
625
    }
 
626
    else
 
627
        return _open_osfhandle(result, 0);
 
628
}
 
629
#define socket(f,t,p) Squid::socket(f,t,p)
 
630
 
 
631
inline
 
632
int WSAAsyncSelect(int s, HWND h, unsigned int w, long e)
 
633
{
 
634
    if (::WSAAsyncSelect(_get_osfhandle(s), h, w, e) == SOCKET_ERROR) {
 
635
        errno = WSAGetLastError();
 
636
        return -1;
 
637
    }
 
638
    else
 
639
        return 0;
 
640
}
 
641
 
 
642
#undef WSADuplicateSocket
 
643
inline
 
644
int WSADuplicateSocket(int s, DWORD n, LPWSAPROTOCOL_INFO l)
 
645
{
 
646
#ifdef UNICODE
 
647
    if (::WSADuplicateSocketW(_get_osfhandle(s), n, l) == SOCKET_ERROR) {
 
648
#else
 
649
    if (::WSADuplicateSocketA(_get_osfhandle(s), n, l) == SOCKET_ERROR) {
 
650
#endif
 
651
        errno = WSAGetLastError();
 
652
        return -1;
 
653
    }
 
654
    else
 
655
        return 0;
 
656
}
 
657
 
 
658
#undef WSASocket
 
659
inline
 
660
int WSASocket(int a, int t, int p, LPWSAPROTOCOL_INFO i, GROUP g, DWORD f)
 
661
{
 
662
    SOCKET result;
 
663
#ifdef UNICODE
 
664
    if ((result = ::WSASocketW(a, t, p, i, g, f)) == INVALID_SOCKET) {
 
665
#else
 
666
    if ((result = ::WSASocketA(a, t, p, i, g, f)) == INVALID_SOCKET) {
 
667
#endif
 
668
        if (WSAEMFILE == (errno = WSAGetLastError()))
 
669
            errno = EMFILE;
 
670
        return -1;
 
671
    }
 
672
    else
 
673
        return _open_osfhandle(result, 0);
 
674
}
 
675
 
 
676
} /* namespace Squid */
 
677
 
 
678
#else /* #ifdef __cplusplus */
 
679
#define connect(s,n,l) \
 
680
        (SOCKET_ERROR == connect(_get_osfhandle(s),n,l) ? \
 
681
        (WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1, -1) : 0)
 
682
#define gethostbyname(n) \
 
683
        (NULL == ((HOSTENT FAR*)(ws32_result = (int)gethostbyname(n))) ? \
 
684
        (errno = WSAGetLastError()), (HOSTENT FAR*)NULL : (HOSTENT FAR*)ws32_result)
 
685
#define gethostname(n,l) \
 
686
        (SOCKET_ERROR == gethostname(n,l) ? \
 
687
        (errno = WSAGetLastError()), -1 : 0)
 
688
#define recv(s,b,l,f) \
 
689
        (SOCKET_ERROR == (ws32_result = recv(_get_osfhandle(s),b,l,f)) ? \
 
690
        (errno = WSAGetLastError()), -1 : ws32_result)
 
691
#define sendto(s,b,l,f,t,tl) \
 
692
        (SOCKET_ERROR == (ws32_result = sendto(_get_osfhandle(s),b,l,f,t,tl)) ? \
 
693
        (errno = WSAGetLastError()), -1 : ws32_result)
 
694
#define select(n,r,w,e,t) \
 
695
        (SOCKET_ERROR == (ws32_result = select(n,r,w,e,t)) ? \
 
696
        (errno = WSAGetLastError()), -1 : ws32_result)
 
697
#define socket(f,t,p) \
 
698
        (INVALID_SOCKET == ((SOCKET)(ws32_result = (int)socket(f,t,p))) ? \
 
699
        ((WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1), -1) : \
 
700
        (SOCKET)_open_osfhandle(ws32_result,0))
 
701
#define write      _write /* Needed in util.c */
 
702
#define open       _open /* Needed in win32lib.c */
 
703
#endif /* #ifdef __cplusplus */
 
704
 
 
705
#define RUSAGE_SELF     0               /* calling process */
 
706
#define RUSAGE_CHILDREN -1              /* terminated child processes */
 
707
 
 
708
struct rusage {
 
709
        struct timeval ru_utime;        /* user time used */
 
710
        struct timeval ru_stime;        /* system time used */
 
711
        long ru_maxrss;                 /* integral max resident set size */
 
712
        long ru_ixrss;                  /* integral shared text memory size */
 
713
        long ru_idrss;                  /* integral unshared data size */
 
714
        long ru_isrss;                  /* integral unshared stack size */
 
715
        long ru_minflt;                 /* page reclaims */
 
716
        long ru_majflt;                 /* page faults */
 
717
        long ru_nswap;                  /* swaps */
 
718
        long ru_inblock;                /* block input operations */
 
719
        long ru_oublock;                /* block output operations */
 
720
        long ru_msgsnd;                 /* messages sent */
 
721
        long ru_msgrcv;                 /* messages received */
 
722
        long ru_nsignals;               /* signals received */
 
723
        long ru_nvcsw;                  /* voluntary context switches */
 
724
        long ru_nivcsw;                 /* involuntary context switches */
 
725
};
 
726
 
 
727
#undef ACL
 
728
 
 
729
SQUIDCEXTERN int chroot (const char *);
 
730
SQUIDCEXTERN int ftruncate(int, off_t);
 
731
SQUIDCEXTERN int gettimeofday(struct timeval * ,void *);
 
732
SQUIDCEXTERN int kill(pid_t, int);
 
733
SQUIDCEXTERN int statfs(const char *, struct statfs *);
 
734
SQUIDCEXTERN int truncate(const char *, off_t);
 
735
SQUIDCEXTERN const char * wsastrerror(int);
 
736
SQUIDCEXTERN struct passwd *getpwnam(char *);
 
737
SQUIDCEXTERN struct group *getgrnam(char *);
 
738
SQUIDCEXTERN uid_t geteuid(void);
 
739
SQUIDCEXTERN uid_t getuid(void);
 
740
SQUIDCEXTERN int setuid(uid_t);
 
741
SQUIDCEXTERN int seteuid(uid_t);
 
742
SQUIDCEXTERN gid_t getgid(void);
 
743
SQUIDCEXTERN gid_t getegid(void);
 
744
SQUIDCEXTERN int setgid(gid_t);
 
745
SQUIDCEXTERN int setegid(gid_t);
 
746
SQUIDCEXTERN const char *WIN32_strerror(int);
 
747
SQUIDCEXTERN void WIN32_maperror(unsigned long);