#endif /* !HAVE_STRUCT_RUSAGE */
-/* templates require C++ */
-#ifdef __cplusplus
-
#ifndef min
+#ifdef __cplusplus
/**
* min() comparison may not always be provided.
* Squid bundles this template for when its needed.
return rhs;
return lhs;
}
-#endif
-#define XMIN(x,y) (min (x,y))
+#else /* !__cplusplus */
+/* for non-C++ we are stuck with the < and ? operator */
+#define min(a,b) ((a) < (b) ? (a) : (b))
+#endif /* __cplusplus */
+#endif /* min */
#ifndef max
+#ifdef __cplusplus
/**
* max() comparison may not always be provided.
* Squid bundles this template for when its needed.
return rhs;
return lhs;
}
-#endif
-#define XMAX(a,b) (max (a,b))
-
+#else /* !__cplusplus */
+/* for non-C++ we are stuck with the < and ? operator */
+#define max(a,b) ((a) < (b) ? (b) : (a))
#endif /* __cplusplus */
+#endif /* max */
/**
* tempnam() not provided by all systems
Range<C>
Range<C>::intersection (Range const &rhs) const
{
- Range<C> result (XMAX(start, rhs.start), XMIN(end, rhs.end));
+ Range<C> result (max(start, rhs.start), min(end, rhs.end));
return result;
}
SQUIDCEXTERN double drand48(void);
#endif
-#ifndef xmax
-#define xmax(a,b) ((a) < (b) ? (b) : (a))
-#endif
-#ifndef xmin
-#define xmin(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
typedef struct {
size_t count;
size_t bytes;
BodyPipe::putMoreData(const char *buf, size_t size)
{
if (bodySizeKnown())
- size = XMIN((uint64_t)size, unproducedSize());
+ size = min((uint64_t)size, unproducedSize());
const size_t spaceSize = static_cast<size_t>(theBuf.potentialSpaceSize());
- if ((size = XMIN(size, spaceSize))) {
+ if ((size = min(size, spaceSize))) {
theBuf.append(buf, size);
postAppend(size);
return size;
if (buf.isNull())
buf.init();
- const size_t size = XMIN(theBuf.contentSize(), buf.potentialSpaceSize());
+ const size_t size = min(theBuf.contentSize(), buf.potentialSpaceSize());
buf.append(theBuf.content(), size);
theBuf.consume(size);
postConsume(size);
{
Must(theLeftBodySize > 0); // Should, really
- const size_t availSize = XMIN(theLeftBodySize, (uint64_t)theIn->contentSize());
- const size_t safeSize = XMIN(availSize, (size_t)theOut->potentialSpaceSize());
+ const size_t availSize = min(theLeftBodySize, (uint64_t)theIn->contentSize());
+ const size_t safeSize = min(availSize, (size_t)theOut->potentialSpaceSize());
doNeedMoreData = availSize < theLeftBodySize;
// and we may also need more space
Must(virgin.body_pipe != NULL);
const size_t sizeMax = (size_t)virgin.body_pipe->buf().contentSize();
- const size_t size = XMIN(preview.debt(), sizeMax);
+ const size_t size = min(preview.debt(), sizeMax);
writeSomeBody("preview body", size);
// change state once preview is written
writeBuf.init(); // note: we assume that last-chunk will fit
const size_t writableSize = virginContentSize(virginBodyWriting);
- const size_t chunkSize = XMIN(writableSize, size);
+ const size_t chunkSize = min(writableSize, size);
if (chunkSize) {
debugs(93, 7, HERE << "will write " << chunkSize <<
" from " << virgin.body_pipe->status());
if (virginBodyWriting.active())
- offset = XMIN(virginBodyWriting.offset(), offset);
+ offset = min(virginBodyWriting.offset(), offset);
if (virginBodySending.active())
- offset = XMIN(virginBodySending.offset(), offset);
+ offset = min(virginBodySending.offset(), offset);
Must(virginConsumed <= offset && offset <= end);
Must(wantedSize >= 0);
// cannot preview more than we can backup
- size_t ad = XMIN(wantedSize, TheBackupLimit);
+ size_t ad = min(wantedSize, TheBackupLimit);
if (!virginBody.expected())
ad = 0;
else
if (virginBody.knownSize())
- ad = XMIN(static_cast<uint64_t>(ad), virginBody.size()); // not more than we have
+ ad = min(static_cast<uint64_t>(ad), virginBody.size()); // not more than we have
debugs(93, 5, HERE << "should offer " << ad << "-byte preview " <<
"(service wanted " << wantedSize << ")");
if (available.start < http->range_iter.currentSpec()->offset)
return 0;
- return XMIN(http->range_iter.debt(), (int64_t)maximum);
+ return min(http->range_iter.debt(), (int64_t)maximum);
}
void
/* Keep a few file descriptors free so that we don't run out of FD's
* after accepting a client but before it opens a socket or a file.
* Since Squid_MaxFD can be as high as several thousand, don't waste them */
- RESERVED_FD = XMIN(100, Squid_MaxFD / 4);
+ RESERVED_FD = min(100, Squid_MaxFD / 4);
conn_close_pool = memPoolCreate("close_handler", sizeof(close_handler));
/*
* Calculate a new reserve, based on current usage and a small extra
*/
- newReserve = Squid_MaxFD - Number_FD + XMIN(25, Squid_MaxFD / 16);
+ newReserve = Squid_MaxFD - Number_FD + min(25, Squid_MaxFD / 16);
if (newReserve <= RESERVED_FD)
return;
- x = Squid_MaxFD - 20 - XMIN(25, Squid_MaxFD / 16);
+ x = Squid_MaxFD - 20 - min(25, Squid_MaxFD / 16);
if (newReserve > x) {
/* perhaps this should be fatal()? -DW */
newReserve = x;
}
- if (Squid_MaxFD - newReserve < XMIN(256, Squid_MaxFD / 2))
+ if (Squid_MaxFD - newReserve < min(256, Squid_MaxFD / 2))
fatalf("Too few filedescriptors available in the system (%d usable of %d).\n", Squid_MaxFD - newReserve, Squid_MaxFD);
debugs(51, 0, "Reserved FD adjusted from " << RESERVED_FD << " to " << newReserve << " due to failures");
/* thats okay, our default is known */
if ( IsAnyAddr() ) {
#if USE_IPV6
- memcpy(buf,"::\0", xmin(3,blen));
+ memcpy(buf,"::\0", min((const unsigned int)3,blen));
#else
- memcpy(buf,"0.0.0.0\0", xmin(8,blen));
+ memcpy(buf,"0.0.0.0\0", min((const unsigned int)8,blen));
#endif
return buf;
}
/* However IPv4 CAN. */
if ( force == AF_INET && !IsIPv4() ) {
if ( IsIPv6() ) {
- memcpy(buf, "{!IPv4}\0", xmin(8,blen));
+ memcpy(buf, "{!IPv4}\0", min((const unsigned int)8,blen));
}
return buf;
}
force << "). accepted={" << AF_UNSPEC << "," << AF_INET << "," << AF_INET6 << "}");
fprintf(stderr,"WARNING: Corrupt IP Address details OR required to display in unknown format (%d). accepted={%d,%d,%d} ",
force, AF_UNSPEC, AF_INET, AF_INET6);
- memcpy(buf,"dead:beef::\0", xmin(13,blen));
+ memcpy(buf,"dead:beef::\0", min((const unsigned int)13,blen));
assert(false);
}
if (!ia->bad_mask[k]) {
ia->bad_mask[k] = TRUE;
ia->badcount++;
- i->expires = XMIN(squid_curtime + XMAX((time_t)60, Config.negativeDnsTtl), i->expires);
+ i->expires = min(squid_curtime + max((time_t)60, Config.negativeDnsTtl), i->expires);
debugs(14, 2, "ipcacheMarkBadAddr: " << name << " " << addr );
}
/* these two can go I think */
assert (location - aNode->nodeBuffer.offset == (int64_t)aNode->nodeBuffer.length);
- size_t copyLen = XMIN (amount, aNode->space());
+ size_t copyLen = min(amount, aNode->space());
xmemcpy(aNode->nodeBuffer.data + aNode->nodeBuffer.length, source, copyLen);
size_t copyOffset = location - aNode->nodeBuffer.offset;
- size_t copyLen = XMIN (amount, aNode->nodeBuffer.length - copyOffset);
+ size_t copyLen = min(amount, aNode->nodeBuffer.length - copyOffset);
xmemcpy(target, aNode->nodeBuffer.data + copyOffset, copyLen);
/*
* we have (part of) what they want
*/
- size_t copy_sz = XMIN(copyInto.length, body_sz);
+ size_t copy_sz = min(copyInto.length, body_sz);
debugs(90, 3, "storeClientReadHeader: copying " << copy_sz << " bytes of body");
xmemmove(copyInto.data, copyInto.data + mem->swap_hdr_sz, copy_sz);
/* Keep a few file descriptors free so that we don't run out of FD's
* after accepting a client but before it opens a socket or a file.
* Since Squid_MaxFD can be as high as several thousand, don't waste them */
- RESERVED_FD = XMIN(100, Squid_MaxFD / 4);
+ RESERVED_FD = min(100, Squid_MaxFD / 4);
}
/* MinGW needs also a stub of _comm_close() */