14#ifndef SQUID_OS_MSWINDOWS_H
15#define SQUID_OS_MSWINDOWS_H
43#define _CRT_SECURE_NO_DEPRECATE
44#pragma warning( disable : 4290 )
45#pragma warning( disable : 4996 )
49#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
50# define __USE_FILE_OFFSET64 1
55#if defined(__USE_FILE_OFFSET64)
56typedef uint64_t ino_t;
58typedef unsigned long ino_t;
61#define INT64_MAX _I64_MAX
62#define INT64_MIN _I64_MIN
64#include "default_config_file.h"
67#define THREADLOCAL __declspec(thread)
69#elif defined(__GNUC__)
71#define THREADLOCAL __attribute__((section(".tls")))
79#define fstat _fstati64
80#define lseek _lseeki64
81#define memccpy _memccpy
83#define snprintf _snprintf
85#define strcasecmp _stricmp
87#define strncasecmp _strnicmp
88#define tempnam _tempnam
89#define vsnprintf _vsnprintf
93#if defined(_MSC_VER) || _SQUID_CYGWIN_
95#define ftruncate WIN32_ftruncate
96SQUIDCEXTERN int WIN32_truncate(
const char *pathname, off_t length);
97#define truncate WIN32_truncate
104#define fdopen _fdopen
105#define getcwd _getcwd
106#define getpid _getpid
107#define mkdir(p,F) mkdir((p))
108#define pclose _pclose
110#define putenv _putenv
111#define setmode _setmode
112#define sleep(t) Sleep((t)*1000)
114#define unlink _unlink
117#define O_RDONLY _O_RDONLY
120#define O_WRONLY _O_WRONLY
123#define O_RDWR _O_RDWR
126#define O_APPEND _O_APPEND
129#define O_CREAT _O_CREAT
132#define O_TRUNC _O_TRUNC
135#define O_EXCL _O_EXCL
138#define O_TEXT _O_TEXT
141#define O_BINARY _O_BINARY
144#define O_RAW _O_BINARY
147#define O_TEMPORARY _O_TEMPORARY
150#define O_NOINHERIT _O_NOINHERIT
153#define O_SEQUENTIAL _O_SEQUENTIAL
156#define O_RANDOM _O_RANDOM
163#define S_IFMT _S_IFMT
166#define S_IFDIR _S_IFDIR
169#define S_IFCHR _S_IFCHR
172#define S_IFREG _S_IFREG
175#define S_IREAD _S_IREAD
178#define S_IWRITE _S_IWRITE
181#define S_IEXEC _S_IEXEC
206#define S_ISDIR(m) (((m) & _S_IFDIR) == _S_IFDIR)
239#if !HAVE_GETTIMEOFDAY
246#define CHANGE_FD_SETSIZE 1
247#if CHANGE_FD_SETSIZE && SQUID_MAXFD > DEFAULT_FD_SETSIZE
248#define FD_SETSIZE SQUID_MAXFD
262#if (EAI_NODATA == EAI_NONAME)
264#define EAI_NODATA WSANO_DATA
269#pragma warning (push)
270#pragma warning (disable:4142)
284#define _PATH_DEVNULL "NUL"
293#define EISCONN WSAEISCONN
296#define EINPROGRESS WSAEINPROGRESS
299#define EWOULDBLOCK WSAEWOULDBLOCK
302#define EALREADY WSAEALREADY
305#define ETIMEDOUT WSAETIMEDOUT
308#define ECONNREFUSED WSAECONNREFUSED
311#define ECONNRESET WSAECONNRESET
314#define ENOTCONN WSAENOTCONN
317#define ERESTART WSATRY_AGAIN
320#define EAFNOSUPPORT WSAEAFNOSUPPORT
323#define ENETUNREACH WSAENETUNREACH
326#define ENOTSUP WSAEOPNOTSUPP
329#define ECONNABORTED WSAECONNABORTED
336#define FD_CLR(fd, set) do { \
338 SOCKET __sock = _get_osfhandle(fd); \
339 for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count ; __i++) { \
340 if (((fd_set FAR *)(set))->fd_array[__i] == __sock) { \
341 while (__i < ((fd_set FAR *)(set))->fd_count-1) { \
342 ((fd_set FAR *)(set))->fd_array[__i] = \
343 ((fd_set FAR *)(set))->fd_array[__i+1]; \
346 ((fd_set FAR *)(set))->fd_count--; \
353#define FD_SET(fd, set) do { \
355 SOCKET __sock = _get_osfhandle(fd); \
356 for (__i = 0; __i < ((fd_set FAR *)(set))->fd_count; __i++) { \
357 if (((fd_set FAR *)(set))->fd_array[__i] == (__sock)) { \
361 if (__i == ((fd_set FAR *)(set))->fd_count) { \
362 if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) { \
363 ((fd_set FAR *)(set))->fd_array[__i] = (__sock); \
364 ((fd_set FAR *)(set))->fd_count++; \
370#define FD_ISSET(fd, set) Win32__WSAFDIsSet(fd, (fd_set FAR *)(set))
379 CRITICAL_SECTION lock;
383#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
384#define _pioinfo(i) ( __pioinfo[(i) >> IOINFO_L2E] + ((i) & (IOINFO_ARRAY_ELTS - 1)) )
385#define _osfile(i) ( _pioinfo(i)->osfile )
386#define _osfhnd(i) ( _pioinfo(i)->osfhnd )
398#if defined(__cplusplus)
403 char l_so_type[
sizeof(
int)];
404 int l_so_type_siz =
sizeof(l_so_type);
405 SOCKET sock = _get_osfhandle(fd);
407 if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0) {
409 if (closesocket(sock) == SOCKET_ERROR) {
410 errno = WSAGetLastError();
423#define _S_IREAD 0x0100
427#define _S_IWRITE 0x0080
431open(
const char *filename,
int oflag,
int pmode = 0)
433 return _open(filename, oflag, pmode & (_S_IREAD | _S_IWRITE));
438read(
int fd,
void * buf,
size_t siz)
440 char l_so_type[
sizeof(
int)];
441 int l_so_type_siz =
sizeof(l_so_type);
442 SOCKET sock = _get_osfhandle(fd);
444 if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0)
445 return ::recv(sock, (
char FAR *) buf, (
int)siz, 0);
447 return _read(fd, buf, (
unsigned int)siz);
451write(
int fd,
const void * buf,
size_t siz)
453 char l_so_type[
sizeof(
int)];
454 int l_so_type_siz =
sizeof(l_so_type);
455 SOCKET sock = _get_osfhandle(fd);
457 if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0)
458 return ::send(sock, (
char FAR *) buf, siz, 0);
460 return _write(fd, buf, siz);
484accept(
int s,
struct sockaddr * a,
socklen_t * l)
487 if ((result = ::accept(_get_osfhandle(s), a, l)) == INVALID_SOCKET) {
488 if (WSAEMFILE == (errno = WSAGetLastError()))
492 return _open_osfhandle(result, 0);
494#define accept(s,a,l) Squid::accept(s,a,reinterpret_cast<socklen_t*>(l))
497bind(
int s,
const struct sockaddr * n,
socklen_t l)
499 if (::bind(_get_osfhandle(s),n,l) == SOCKET_ERROR) {
500 errno = WSAGetLastError();
505#define bind(s,n,l) Squid::bind(s,n,l)
508connect(
int s,
const struct sockaddr * n,
socklen_t l)
510 if (::connect(_get_osfhandle(s),n,l) == SOCKET_ERROR) {
511 if (WSAEMFILE == (errno = WSAGetLastError()))
517#define connect(s,n,l) Squid::connect(s,n,l)
519inline struct hostent *
520gethostbyname(
const char *n) {
521 HOSTENT FAR * result;
522 if ((result = ::gethostbyname(n)) ==
NULL)
523 errno = WSAGetLastError();
526#define gethostbyname(n) Squid::gethostbyname(n)
529getservbyname(
const char * n,
const char * p)
531 SERVENT FAR * result;
532 if ((result = ::getservbyname(n, p)) ==
NULL)
533 errno = WSAGetLastError();
536#define getservbyname(n,p) Squid::getservbyname(n,p)
539gethostbyaddr(
const void * a,
size_t l,
int t)
541 HOSTENT FAR * result;
542 if ((result = ::gethostbyaddr((
const char*)a, l, t)) ==
NULL)
543 errno = WSAGetLastError();
546#define gethostbyaddr(a,l,t) Squid::gethostbyaddr(a,l,t)
549getsockname(
int s,
struct sockaddr * n,
socklen_t * l)
552 if (::getsockname(_get_osfhandle(s), n, &i) == SOCKET_ERROR) {
553 errno = WSAGetLastError();
558#define getsockname(s,a,l) Squid::getsockname(s,a,reinterpret_cast<socklen_t*>(l))
561gethostname(
char * n,
size_t l)
563 if ((::gethostname(n, l)) == SOCKET_ERROR) {
564 errno = WSAGetLastError();
569#define gethostname(n,l) Squid::gethostname(n,l)
572getsockopt(
int s,
int l,
int o,
void * v,
socklen_t * n)
575 if ((::getsockopt(_get_osfhandle(s), l, o,(
char *) v, n)) == SOCKET_ERROR) {
576 errno = WSAGetLastError();
581#define getsockopt(s,l,o,v,n) Squid::getsockopt(s,l,o,v,n)
585ioctl(
int s,
int c,
void * a)
587 if ((::ioctlsocket(_get_osfhandle(s), c, (u_long FAR *)a)) == SOCKET_ERROR) {
588 errno = WSAGetLastError();
593#define ioctl(s,c,a) Squid::ioctl(s,c,a)
596ioctlsocket(
int s,
long c, u_long FAR * a)
598 if ((::ioctlsocket(_get_osfhandle(s), c, a)) == SOCKET_ERROR) {
599 errno = WSAGetLastError();
604#define ioctlsocket(s,c,a) Squid::ioctlsocket(s,c,a)
609 if (::listen(_get_osfhandle(s), b) == SOCKET_ERROR) {
610 if (WSAEMFILE == (errno = WSAGetLastError()))
616#define listen(s,b) Squid::listen(s,b)
619recv(
int s,
void * b,
size_t l,
int f)
622 if ((result = ::recv(_get_osfhandle(s), (
char *)b, l, f)) == SOCKET_ERROR) {
623 errno = WSAGetLastError();
628#define recv(s,b,l,f) Squid::recv(s,b,l,f)
631recvfrom(
int s,
void * b,
size_t l,
int f,
struct sockaddr * fr,
socklen_t * fl)
635 if ((result = ::recvfrom(_get_osfhandle(s), (
char *)b, l, f, fr, &ifl)) == SOCKET_ERROR) {
636 errno = WSAGetLastError();
641#define recvfrom(s,b,l,f,r,n) Squid::recvfrom(s,b,l,f,r,reinterpret_cast<socklen_t*>(n))
644select(
int n, fd_set * r, fd_set * w, fd_set * e,
struct timeval * t)
647 if ((result = ::select(n,r,w,e,t)) == SOCKET_ERROR) {
648 errno = WSAGetLastError();
653#define select(n,r,w,e,t) Squid::select(n,r,w,e,t)
656send(
int s,
const char * b,
size_t l,
int f)
659 if ((result = ::send(_get_osfhandle(s), b, l, f)) == SOCKET_ERROR) {
660 errno = WSAGetLastError();
665#define send(s,b,l,f) Squid::send(s,reinterpret_cast<const char*>(b),l,f)
668sendto(
int s,
const void * b,
size_t l,
int f,
const struct sockaddr * t,
socklen_t tl)
671 if ((result = ::sendto(_get_osfhandle(s), (
char *)b, l, f, t, tl)) == SOCKET_ERROR) {
672 errno = WSAGetLastError();
677#define sendto(a,b,l,f,t,n) Squid::sendto(a,b,l,f,t,n)
680setsockopt(SOCKET s,
int l,
int o,
const void * v,
socklen_t n)
684 socket = ((s == INVALID_SOCKET) ? s : (SOCKET)_get_osfhandle((
int)s));
686 if (::setsockopt(socket, l, o, (
const char *)v, n) == SOCKET_ERROR) {
687 errno = WSAGetLastError();
692#define setsockopt(s,l,o,v,n) Squid::setsockopt(s,l,o,v,n)
695shutdown(
int s,
int h)
697 if (::shutdown(_get_osfhandle(s),h) == SOCKET_ERROR) {
698 errno = WSAGetLastError();
703#define shutdown(s,h) Squid::shutdown(s,h)
706socket(
int f,
int t,
int p)
709 if ((result = ::socket(f, t, p)) == INVALID_SOCKET) {
710 if (WSAEMFILE == (errno = WSAGetLastError()))
714 return _open_osfhandle(result, 0);
716#define socket(f,t,p) Squid::socket(f,t,p)
721 return _pipe(pipefd,4096,_O_BINARY);
723#define pipe(a) Squid::pipe(a)
726WSAAsyncSelect(
int s, HWND h,
unsigned int w,
long e)
728 if (::WSAAsyncSelect(_get_osfhandle(s), h, w, e) == SOCKET_ERROR) {
729 errno = WSAGetLastError();
734#define WSAAsyncSelect(s,h,w,e) Squid::WSAAsyncSelect(s,h,w,e)
736#undef WSADuplicateSocket
738WSADuplicateSocket(
int s, DWORD n, LPWSAPROTOCOL_INFO l)
741 if (::WSADuplicateSocketW(_get_osfhandle(s), n, l) == SOCKET_ERROR) {
743 if (::WSADuplicateSocketA(_get_osfhandle(s), n, l) == SOCKET_ERROR) {
745 errno = WSAGetLastError();
750#define WSADuplicateSocket(s,n,l) Squid::WSADuplicateSocket(s,n,l)
754WSASocket(
int a,
int t,
int p, LPWSAPROTOCOL_INFO i, GROUP g, DWORD f)
758 if ((result = ::WSASocketW(a, t, p, i, g, f)) == INVALID_SOCKET) {
760 if ((result = ::WSASocketA(a, t, p, i, g, f)) == INVALID_SOCKET) {
762 if (WSAEMFILE == (errno = WSAGetLastError()))
766 return _open_osfhandle(result, 0);
768#define WSASocket(a,t,p,i,g,f) Squid::WSASocket(a,t,p,i,g,f)
773#define connect(s,n,l) \
774 (SOCKET_ERROR == connect(_get_osfhandle(s),n,l) ? \
775 (WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1, -1) : 0)
776#define gethostbyname(n) \
777 (NULL == ((HOSTENT FAR*)(ws32_result = (int)gethostbyname(n))) ? \
778 (errno = WSAGetLastError()), (HOSTENT FAR*)NULL : (HOSTENT FAR*)ws32_result)
779#define gethostname(n,l) \
780 (SOCKET_ERROR == gethostname(n,l) ? \
781 (errno = WSAGetLastError()), -1 : 0)
782#define recv(s,b,l,f) \
783 (SOCKET_ERROR == (ws32_result = recv(_get_osfhandle(s),b,l,f)) ? \
784 (errno = WSAGetLastError()), -1 : ws32_result)
785#define sendto(s,b,l,f,t,tl) \
786 (SOCKET_ERROR == (ws32_result = sendto(_get_osfhandle(s),b,l,f,t,tl)) ? \
787 (errno = WSAGetLastError()), -1 : ws32_result)
788#define select(n,r,w,e,t) \
789 (SOCKET_ERROR == (ws32_result = select(n,r,w,e,t)) ? \
790 (errno = WSAGetLastError()), -1 : ws32_result)
791#define socket(f,t,p) \
792 (INVALID_SOCKET == ((SOCKET)(ws32_result = (int)socket(f,t,p))) ? \
793 ((WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1), -1) : \
794 (SOCKET)_open_osfhandle(ws32_result,0))
804#if HAVE_SYS_RESOURCE_H
805#include <sys/resource.h>
808#define RUSAGE_CHILDREN -1
811 struct timeval ru_utime;
812 struct timeval ru_stime;
881#define HAVE_GETPAGESIZE 2
895#define ACL WindowsACL
896#define _MSWIN_ACL_WAS_NOT_DEFINED 1
899#if _MSWIN_ACL_WAS_NOT_DEFINED
901#undef _MSWIN_ACL_WAS_NOT_DEFINED
915#define LOG_DAEMON (3<<3)
917void openlog(
const char *ident,
int logopt,
int facility);
918void syslog(
int priority,
const char *fmt, ...);
922void WIN32_maperror(
unsigned long WIN32_oserrno);
DWORD WIN32_IpAddrChangeMonitorInit()