14#ifndef SQUID_OS_MSWINDOWS_H
15#define SQUID_OS_MSWINDOWS_H
31#define _WIN32_WINNT WINVER
53#define _CRT_SECURE_NO_DEPRECATE
54#pragma warning( disable : 4290 )
55#pragma warning( disable : 4996 )
63#if defined(__GNUC__) && !NOMINMAX
68#if !defined(IPV6_V6ONLY)
72#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
73# define __USE_FILE_OFFSET64 1
78#if defined(__USE_FILE_OFFSET64)
79typedef uint64_t ino_t;
81typedef unsigned long ino_t;
84#define INT64_MAX _I64_MAX
85#define INT64_MIN _I64_MIN
87#include "default_config_file.h"
90#define THREADLOCAL __declspec(thread)
92#elif defined(__GNUC__)
94#define THREADLOCAL __attribute__((section(".tls")))
100#define alloca _alloca
101#define fileno _fileno
102#define fstat _fstati64
103#define lseek _lseeki64
104#define memccpy _memccpy
105#define mktemp _mktemp
106#define snprintf _snprintf
108#define strcasecmp _stricmp
109#define strlwr _strlwr
110#define strncasecmp _strnicmp
111#define tempnam _tempnam
112#define vsnprintf _vsnprintf
116#if defined(_MSC_VER) || _SQUID_CYGWIN_
118#define ftruncate WIN32_ftruncate
119SQUIDCEXTERN int WIN32_truncate(
const char *pathname, off_t length);
120#define truncate WIN32_truncate
127#define fdopen _fdopen
128#define getcwd _getcwd
129#define getpid _getpid
130#define mkdir(p,F) mkdir((p))
131#define pclose _pclose
133#define putenv _putenv
134#define setmode _setmode
135#define sleep(t) Sleep((t)*1000)
137#define unlink _unlink
140#define O_RDONLY _O_RDONLY
143#define O_WRONLY _O_WRONLY
146#define O_RDWR _O_RDWR
149#define O_APPEND _O_APPEND
152#define O_CREAT _O_CREAT
155#define O_TRUNC _O_TRUNC
158#define O_EXCL _O_EXCL
161#define O_TEXT _O_TEXT
164#define O_BINARY _O_BINARY
167#define O_RAW _O_BINARY
170#define O_TEMPORARY _O_TEMPORARY
173#define O_NOINHERIT _O_NOINHERIT
176#define O_SEQUENTIAL _O_SEQUENTIAL
179#define O_RANDOM _O_RANDOM
186#define S_IFMT _S_IFMT
189#define S_IFDIR _S_IFDIR
192#define S_IFCHR _S_IFCHR
195#define S_IFREG _S_IFREG
198#define S_IREAD _S_IREAD
201#define S_IWRITE _S_IWRITE
204#define S_IEXEC _S_IEXEC
229#define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
241typedef unsigned char boolean;
242typedef unsigned char u_char;
243typedef unsigned int u_int;
268#if !HAVE_GETTIMEOFDAY
275#define CHANGE_FD_SETSIZE 1
276#if CHANGE_FD_SETSIZE && SQUID_MAXFD > DEFAULT_FD_SETSIZE
277#define FD_SETSIZE SQUID_MAXFD
293#if (EAI_NODATA == EAI_NONAME)
295#define EAI_NODATA WSANO_DATA
300#pragma warning (push)
301#pragma warning (disable:4142)
314typedef char * caddr_t;
317#define _PATH_DEVNULL "NUL"
326#define EISCONN WSAEISCONN
329#define EINPROGRESS WSAEINPROGRESS
332#define EWOULDBLOCK WSAEWOULDBLOCK
335#define EALREADY WSAEALREADY
338#define ETIMEDOUT WSAETIMEDOUT
341#define ECONNREFUSED WSAECONNREFUSED
344#define ECONNRESET WSAECONNRESET
347#define ENOTCONN WSAENOTCONN
350#define ERESTART WSATRY_AGAIN
353#define EAFNOSUPPORT WSAEAFNOSUPPORT
356#define ENETUNREACH WSAENETUNREACH
359#define ENOTSUP WSAEOPNOTSUPP
362#define ECONNABORTED WSAECONNABORTED
369#define FD_CLR(fd, set) do { \
371 SOCKET __sock = _get_osfhandle(fd); \
372 for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
373 if (((fd_set FAR *)(set))->fd_array[__i] == __sock) { \
374 while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
375 ((fd_set FAR *)(set))->fd_array[__i] = \
376 ((fd_set FAR *)(set))->fd_array[__i+1]; \
379 ((fd_set FAR *)(set))->fd_count--; \
386#define FD_SET(fd, set) do { \
388 SOCKET __sock = _get_osfhandle(fd); \
389 for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count; __i++) { \
390 if (((fd_set FAR *)(set))->fd_array[__i] == (__sock)) { \
394 if (__i == ((fd_set FAR *)(set))->fd_count) { \
395 if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) { \
396 ((fd_set FAR *)(set))->fd_array[__i] = (__sock); \
397 ((fd_set FAR *)(set))->fd_count++; \
403#define FD_ISSET(fd, set) Win32__WSAFDIsSet(fd, (fd_set FAR *)(set))
412 CRITICAL_SECTION lock;
416#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
417#define _pioinfo(i) ( __pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)) )
418#define _osfile(i) ( _pioinfo(i)->osfile )
419#define _osfhnd(i) ( _pioinfo(i)->osfhnd )
430__MINGW_IMPORT ioinfo * __pioinfo[];
436#if defined(__cplusplus)
441 char l_so_type[
sizeof(
int)];
442 int l_so_type_siz =
sizeof(l_so_type);
443 SOCKET sock = _get_osfhandle(fd);
445 if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0) {
447 if (closesocket(sock) == SOCKET_ERROR) {
448 errno = WSAGetLastError();
461#define _S_IREAD 0x0100
465#define _S_IWRITE 0x0080
469open(
const char *filename,
int oflag,
int pmode = 0)
471 return _open(filename, oflag, pmode & (_S_IREAD | _S_IWRITE));
476read(
int fd,
void * buf,
size_t siz)
478 char l_so_type[
sizeof(
int)];
479 int l_so_type_siz =
sizeof(l_so_type);
480 SOCKET sock = _get_osfhandle(fd);
482 if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0)
483 return ::recv(sock, (
char FAR *) buf, (
int)siz, 0);
485 return _read(fd, buf, (
unsigned int)siz);
489write(
int fd,
const void * buf,
size_t siz)
491 char l_so_type[
sizeof(
int)];
492 int l_so_type_siz =
sizeof(l_so_type);
493 SOCKET sock = _get_osfhandle(fd);
495 if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0)
496 return ::send(sock, (
char FAR *) buf, siz, 0);
498 return _write(fd, buf, siz);
522accept(
int s,
struct sockaddr * a,
socklen_t * l)
525 if ((result = ::accept(_get_osfhandle(s), a, l)) == INVALID_SOCKET) {
526 if (WSAEMFILE == (errno = WSAGetLastError()))
530 return _open_osfhandle(result, 0);
532#define accept(s,a,l) Squid::accept(s,a,reinterpret_cast<socklen_t*>(l))
535bind(
int s,
const struct sockaddr * n,
socklen_t l)
537 if (::bind(_get_osfhandle(s),n,l) == SOCKET_ERROR) {
538 errno = WSAGetLastError();
543#define bind(s,n,l) Squid::bind(s,n,l)
546connect(
int s,
const struct sockaddr * n,
socklen_t l)
548 if (::connect(_get_osfhandle(s),n,l) == SOCKET_ERROR) {
549 if (WSAEMFILE == (errno = WSAGetLastError()))
555#define connect(s,n,l) Squid::connect(s,n,l)
559 HOSTENT FAR * result;
561 errno = WSAGetLastError();
564#define gethostbyname(n) Squid::gethostbyname(n)
569 SERVENT FAR * result;
571 errno = WSAGetLastError();
574#define getservbyname(n,p) Squid::getservbyname(n,p)
579 HOSTENT FAR * result;
581 errno = WSAGetLastError();
584#define gethostbyaddr(a,l,t) Squid::gethostbyaddr(a,l,t)
587getsockname(
int s,
struct sockaddr * n,
socklen_t * l)
590 if (::getsockname(_get_osfhandle(s), n, &i) == SOCKET_ERROR) {
591 errno = WSAGetLastError();
596#define getsockname(s,a,l) Squid::getsockname(s,a,reinterpret_cast<socklen_t*>(l))
599gethostname(
char * n,
size_t l)
601 if ((::gethostname(n, l)) == SOCKET_ERROR) {
602 errno = WSAGetLastError();
607#define gethostname(n,l) Squid::gethostname(n,l)
610getsockopt(
int s,
int l,
int o,
void * v,
socklen_t * n)
613 if ((::getsockopt(_get_osfhandle(s), l, o,(
char *) v, n)) == SOCKET_ERROR) {
614 errno = WSAGetLastError();
619#define getsockopt(s,l,o,v,n) Squid::getsockopt(s,l,o,v,n)
621#if HAVE_DECL_INETNTOPA || HAVE_DECL_INET_NTOP
625#if HAVE_DECL_INETNTOPA
626 return (
char*)InetNtopA(af,
const_cast<void*
>(src), dst,
size);
631#define inet_ntop(a,s,d,l) Squid::inet_ntop(a,s,d,l)
634#if HAVE_DECL_INETPTONA || HAVE_DECL_INET_PTON
636inet_pton(
int af,
const void *src,
char *dst)
638#if HAVE_DECL_INETPTONA
639 return (
char*)InetPtonA(af,
const_cast<void*
>(src), dst);
644#define inet_pton(a,s,d) Squid::inet_pton(a,s,d)
649ioctl(
int s,
int c,
void * a)
651 if ((::ioctlsocket(_get_osfhandle(s), c, (u_long FAR *)a)) == SOCKET_ERROR) {
652 errno = WSAGetLastError();
657#define ioctl(s,c,a) Squid::ioctl(s,c,a)
660ioctlsocket(
int s,
long c, u_long FAR * a)
662 if ((::ioctlsocket(_get_osfhandle(s), c, a)) == SOCKET_ERROR) {
663 errno = WSAGetLastError();
668#define ioctlsocket(s,c,a) Squid::ioctlsocket(s,c,a)
673 if (::listen(_get_osfhandle(s), b) == SOCKET_ERROR) {
674 if (WSAEMFILE == (errno = WSAGetLastError()))
680#define listen(s,b) Squid::listen(s,b)
683recv(
int s,
void * b,
size_t l,
int f)
686 if ((result = ::recv(_get_osfhandle(s), (
char *)b, l, f)) == SOCKET_ERROR) {
687 errno = WSAGetLastError();
692#define recv(s,b,l,f) Squid::recv(s,b,l,f)
695recvfrom(
int s,
void * b,
size_t l,
int f,
struct sockaddr * fr,
socklen_t * fl)
699 if ((result = ::recvfrom(_get_osfhandle(s), (
char *)b, l, f, fr, &ifl)) == SOCKET_ERROR) {
700 errno = WSAGetLastError();
705#define recvfrom(s,b,l,f,r,n) Squid::recvfrom(s,b,l,f,r,reinterpret_cast<socklen_t*>(n))
708select(
int n, fd_set * r, fd_set * w, fd_set * e,
struct timeval * t)
711 if ((result = ::select(n,r,w,e,t)) == SOCKET_ERROR) {
712 errno = WSAGetLastError();
717#define select(n,r,w,e,t) Squid::select(n,r,w,e,t)
720send(
int s,
const char * b,
size_t l,
int f)
723 if ((result = ::send(_get_osfhandle(s), b, l, f)) == SOCKET_ERROR) {
724 errno = WSAGetLastError();
729#define send(s,b,l,f) Squid::send(s,reinterpret_cast<const char*>(b),l,f)
732sendto(
int s,
const void * b,
size_t l,
int f,
const struct sockaddr * t,
socklen_t tl)
735 if ((result = ::sendto(_get_osfhandle(s), (
char *)b, l, f, t, tl)) == SOCKET_ERROR) {
736 errno = WSAGetLastError();
741#define sendto(a,b,l,f,t,n) Squid::sendto(a,b,l,f,t,n)
744setsockopt(SOCKET s,
int l,
int o,
const void * v,
socklen_t n)
748 socket = ((s == INVALID_SOCKET) ? s : (SOCKET)_get_osfhandle((
int)s));
750 if (::setsockopt(socket, l, o, (
const char *)v, n) == SOCKET_ERROR) {
751 errno = WSAGetLastError();
756#define setsockopt(s,l,o,v,n) Squid::setsockopt(s,l,o,v,n)
759shutdown(
int s,
int h)
761 if (::shutdown(_get_osfhandle(s),h) == SOCKET_ERROR) {
762 errno = WSAGetLastError();
767#define shutdown(s,h) Squid::shutdown(s,h)
770socket(
int f,
int t,
int p)
773 if ((result = ::socket(f, t, p)) == INVALID_SOCKET) {
774 if (WSAEMFILE == (errno = WSAGetLastError()))
778 return _open_osfhandle(result, 0);
780#define socket(f,t,p) Squid::socket(f,t,p)
785 return _pipe(pipefd,4096,_O_BINARY);
787#define pipe(a) Squid::pipe(a)
790WSAAsyncSelect(
int s, HWND h,
unsigned int w,
long e)
792 if (::WSAAsyncSelect(_get_osfhandle(s), h, w, e) == SOCKET_ERROR) {
793 errno = WSAGetLastError();
798#define WSAAsyncSelect(s,h,w,e) Squid::WSAAsyncSelect(s,h,w,e)
800#undef WSADuplicateSocket
802WSADuplicateSocket(
int s, DWORD n, LPWSAPROTOCOL_INFO l)
805 if (::WSADuplicateSocketW(_get_osfhandle(s), n, l) == SOCKET_ERROR) {
807 if (::WSADuplicateSocketA(_get_osfhandle(s), n, l) == SOCKET_ERROR) {
809 errno = WSAGetLastError();
814#define WSADuplicateSocket(s,n,l) Squid::WSADuplicateSocket(s,n,l)
818WSASocket(
int a,
int t,
int p, LPWSAPROTOCOL_INFO i, GROUP g, DWORD f)
822 if ((result = ::WSASocketW(a, t, p, i, g, f)) == INVALID_SOCKET) {
824 if ((result = ::WSASocketA(a, t, p, i, g, f)) == INVALID_SOCKET) {
826 if (WSAEMFILE == (errno = WSAGetLastError()))
830 return _open_osfhandle(result, 0);
832#define WSASocket(a,t,p,i,g,f) Squid::WSASocket(a,t,p,i,g,f)
837#define connect(s,n,l) \
838 (SOCKET_ERROR == connect(_get_osfhandle(s),n,l) ? \
839 (WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1, -1) : 0)
840#define gethostbyname(n) \
841 (NULL == ((HOSTENT FAR*)(ws32_result = (int)gethostbyname(n))) ? \
842 (errno = WSAGetLastError()), (HOSTENT FAR*)NULL : (HOSTENT FAR*)ws32_result)
843#define gethostname(n,l) \
844 (SOCKET_ERROR == gethostname(n,l) ? \
845 (errno = WSAGetLastError()), -1 : 0)
846#define recv(s,b,l,f) \
847 (SOCKET_ERROR == (ws32_result = recv(_get_osfhandle(s),b,l,f)) ? \
848 (errno = WSAGetLastError()), -1 : ws32_result)
849#define sendto(s,b,l,f,t,tl) \
850 (SOCKET_ERROR == (ws32_result = sendto(_get_osfhandle(s),b,l,f,t,tl)) ? \
851 (errno = WSAGetLastError()), -1 : ws32_result)
852#define select(n,r,w,e,t) \
853 (SOCKET_ERROR == (ws32_result = select(n,r,w,e,t)) ? \
854 (errno = WSAGetLastError()), -1 : ws32_result)
855#define socket(f,t,p) \
856 (INVALID_SOCKET == ((SOCKET)(ws32_result = (int)socket(f,t,p))) ? \
857 ((WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1), -1) : \
858 (SOCKET)_open_osfhandle(ws32_result,0))
868#if HAVE_SYS_RESOURCE_H
869#include <sys/resource.h>
872#define RUSAGE_CHILDREN -1
875 struct timeval ru_utime;
876 struct timeval ru_stime;
943#if HAVE_GETPAGESIZE && _SQUID_MINGW_
944#undef HAVE_GETPAGESIZE
950#define HAVE_GETPAGESIZE 2
961#define PRINTF_FORMAT_ARG1
962#define PRINTF_FORMAT_ARG2
963#define PRINTF_FORMAT_ARG3
973#define ACL WindowsACL
974#define _MSWIN_ACL_WAS_NOT_DEFINED 1
977#if _MSWIN_ACL_WAS_NOT_DEFINED
979#undef _MSWIN_ACL_WAS_NOT_DEFINED
993#define LOG_DAEMON (3<<3)
995void openlog(
const char *ident,
int logopt,
int facility);
996void syslog(
int priority,
const char *fmt, ...);
1009#define WIFEXITED(w) (((w) & 0xff) == 0)
1010#define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
1011#define WIFSTOPPED(w) (((w) & 0xff) == 0x7f)
1012#define WEXITSTATUS(w) (((w) >> 8) & 0xff)
1013#define WTERMSIG(w) ((w) & 0x7f)
1014#define WSTOPSIG WEXITSTATUS
1018void WIN32_maperror(
unsigned long WIN32_oserrno);
DWORD WIN32_IpAddrChangeMonitorInit()
struct hostent * gethostbyaddr()
struct servent * getservbyname()
struct hostent * gethostbyname()