#ifndef CMSG_FIRSTHDR
# define CMSG_FIRSTHDR(mhdr) \
((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
- ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
+ ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) nullptr)
#endif
#ifndef CMSG_ALIGN
#include "squid.h"
#include "compat.h"
-void (*failure_notify) (const char *) = NULL;
+void (*failure_notify) (const char *) = nullptr;
struct addrinfo *ret;
ret = (struct addrinfo *)malloc(sizeof (struct addrinfo));
- if (ret == NULL)
- return NULL;
+ if (!ret)
+ return nullptr;
memcpy (ret, info, sizeof (struct addrinfo));
ret->ai_addr = (struct sockaddr*)malloc(addrlen);
- if (ret->ai_addr == NULL) {
+ if (!ret->ai_addr) {
free (ret);
- return NULL;
+ return nullptr;
}
memcpy (ret->ai_addr, addr, addrlen);
ret->ai_addrlen = addrlen;
struct addrinfo *ai, *sai, *eai;
char **addrs;
- if (servname == NULL && nodename == NULL)
+ if (!servname && !nodename)
return EAI_NONAME;
memset (&result, 0, sizeof result);
/* default for hints */
- if (hints == NULL) {
+ if (!hints) {
memset (&hint, 0, sizeof hint);
hint.ai_family = PF_UNSPEC;
hints = &hint;
}
- if (servname == NULL)
+ if (!servname)
port = 0;
else {
/* check for tcp or udp sockets only */
/* Note: maintain port in host byte order to make debugging easier */
if (isdigit (*servname))
- port = strtol (servname, NULL, 10);
- else if ((servent = getservbyname (servname, socktype)) != NULL)
+ port = strtol (servname, nullptr, 10);
+ else if ((servent = getservbyname (servname, socktype)))
port = ntohs (servent->s_port);
else
return EAI_NONAME;
}
- /* if nodename == NULL refer to the local host for a client or any
+ /* if !nodename, refer to the local host for a client or any
for a server */
- if (nodename == NULL) {
+ if (!nodename) {
struct sockaddr_in sin;
/* check protocol family is PF_UNSPEC or PF_INET - could try harder
sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
/* Duplicate result and addr and return */
*res = dup_addrinfo (&result, &sin, sizeof sin);
- return (*res == NULL) ? EAI_MEMORY : 0;
+ return (!*res) ? EAI_MEMORY : 0;
}
/* If AI_NUMERIC is specified, use inet_pton to translate numbers and
sin.sin_addr.s_addr = inet_addr (nodename);
/* Duplicate result and addr and return */
*res = dup_addrinfo (&result, &sin, sizeof sin);
- return (*res == NULL) ? EAI_MEMORY : 0;
+ return (!*res) ? EAI_MEMORY : 0;
}
#if HAVE_H_ERRNO
#endif
errno = 0;
hp = gethostbyname(nodename);
- if (hp == NULL) {
+ if (!hp) {
#ifdef EAI_SYSTEM
if (errno != 0) {
return EAI_SYSTEM;
/* For each element pointed to by hp, create an element in the
result linked list. */
- sai = eai = NULL;
- for (addrs = hp->h_addr_list; *addrs != NULL; addrs++) {
+ sai = eai = nullptr;
+ for (addrs = hp->h_addr_list; *addrs; addrs++) {
struct sockaddr sa;
size_t addrlen;
result.ai_family = hp->h_addrtype;
ai = dup_addrinfo (&result, &sa, addrlen);
- if (ai == NULL) {
+ if (!ai) {
xfreeaddrinfo (sai);
return EAI_MEMORY;
}
- if (sai == NULL)
+ if (!sai)
sai = ai;
else
eai->ai_next = ai;
eai = ai;
}
- if (sai == NULL) {
+ if (!sai) {
return EAI_NODATA;
}
if (hints->ai_flags & AI_CANONNAME) {
sai->ai_canonname = (char *)malloc(strlen(hp->h_name) + 1);
- if (sai->ai_canonname == NULL) {
+ if (!sai->ai_canonname) {
xfreeaddrinfo (sai);
return EAI_MEMORY;
}
{
struct addrinfo *next;
- while (ai != NULL) {
+ while (ai) {
next = ai->ai_next;
- if (ai->ai_canonname != NULL)
+ if (ai->ai_canonname)
free (ai->ai_canonname);
- if (ai->ai_addr != NULL)
+ if (ai->ai_addr)
free (ai->ai_addr);
free (ai);
ai = next;
uint32_t v4a;
char numserv[512];
- if (sa == NULL)
+ if (!sa)
return EAI_FAIL;
#if HAVE_SA_LEN /*XXX*/
memcpy(&port, (const char *)sa + afd->a_portoff, sizeof(port));
addr = (const char *)sa + afd->a_off;
- if (serv == NULL || servlen == 0) {
+ if (!serv || servlen == 0) {
/*
* do nothing in this case.
* in case you are wondering if "&&" is more correct than
- * "||" here: RFC3493 says that serv == NULL OR servlen == 0
+ * "||" here: RFC3493 says that !serv OR servlen == 0
* means that the caller does not want the result.
*/
} else {
if (flags & NI_NUMERICSERV)
- sp = NULL;
+ sp = nullptr;
else {
sp = getservbyport(port,
(flags & NI_DGRAM) ? "udp" : "tcp");
break;
#endif
}
- if (host == NULL || hostlen == 0) {
+ if (!host || hostlen == 0) {
/*
* do nothing in this case.
* in case you are wondering if "&&" is more correct than
- * "||" here: RFC3493 says that host == NULL or hostlen == 0
+ * "||" here: RFC3493 says that !host or hostlen == 0
* means that the caller does not want the result.
*/
} else if (flags & NI_NUMERICHOST) {
}
#endif
default:
- if (inet_ntop(afd->a_af, addr, host,
- hostlen) == NULL)
+ if (!inet_ntop(afd->a_af, addr, host, hostlen))
return EAI_SYSTEM;
break;
}
int numaddrlen;
char numaddr[512];
- if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL)
+ if (!inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)))
return EAI_SYSTEM;
numaddrlen = strlen(numaddr);
* inet_ntop(af, src, dst, size)
* convert a network format address to presentation format.
* return:
- * pointer to presentation format address (`dst'), or NULL (see errno).
+ * pointer to presentation format address (`dst'), or nullptr (see errno).
* author:
* Paul Vixie, 1996.
*/
return (inet_ntop6((const u_char*)src, dst, size));
default:
errno = EAFNOSUPPORT;
- return (NULL);
+ return nullptr;
}
/* NOTREACHED */
}
if ((size_t)snprintf(tmp, min(sizeof(tmp),size), fmt, src[0], src[1], src[2], src[3]) >= size) {
errno = ENOSPC;
- return (NULL);
+ return nullptr;
}
strcpy(dst, tmp);
return (dst);
(best.len == 7 && words[7] != 0x0001) ||
(best.len == 5 && words[5] == 0xffff))) {
if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
- return (NULL);
+ return nullptr;
tp += strlen(tp);
break;
}
*/
if ((size_t)(tp - tmp) > size) {
errno = ENOSPC;
- return (NULL);
+ return nullptr;
}
strcpy(dst, tmp);
return (dst);
while ((ch = *src++) != '\0') {
const char *pch;
- if ((pch = strchr(digits, ch)) != NULL) {
+ if ((pch = strchr(digits, ch))) {
u_int nw = *tp * 10 + (pch - digits);
if (saw_digit && *tp == 0)
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
endp = tp + NS_IN6ADDRSZ;
- colonp = NULL;
+ colonp = nullptr;
/* Leading :: requires some special handling. */
if (*src == ':')
if (*++src != ':')
while ((ch = *src++) != '\0') {
const char *pch;
- if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+ if (!(pch = strchr((xdigits = xdigits_l), ch)))
pch = strchr((xdigits = xdigits_u), ch);
- if (pch != NULL) {
+ if (pch) {
val <<= 4;
val |= (pch - xdigits);
if (++seen_xdigits > 4)
*tp++ = (u_char) (val >> 8) & 0xff;
*tp++ = (u_char) val & 0xff;
}
- if (colonp != NULL) {
+ if (colonp) {
/*
* Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand.
#endif
THREADLOCAL int ws32_result;
-LPCRITICAL_SECTION dbg_mutex = NULL;
+LPCRITICAL_SECTION dbg_mutex = nullptr;
void GetProcessName(pid_t, char *);
/* Get a handle to the process. */
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
/* Get the process name. */
- if (NULL != hProcess) {
+ if (hProcess) {
HMODULE hMod;
DWORD cbNeeded;
char ProcessNameToCheck[MAX_PATH];
if (sig == 0) {
- if ((hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
- PROCESS_VM_READ,
- FALSE, pid)) == NULL)
+ if (!(hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)))
return -1;
else {
CloseHandle(hProcess);
return -1;
hfile = (HANDLE) _get_osfhandle(fd);
- curpos = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
+ curpos = SetFilePointer(hfile, 0, nullptr, FILE_CURRENT);
if (curpos == 0xFFFFFFFF
- || SetFilePointer(hfile, size, NULL, FILE_BEGIN) == 0xFFFFFFFF
+ || SetFilePointer(hfile, size, nullptr, FILE_BEGIN) == 0xFFFFFFFF
|| !SetEndOfFile(hfile)) {
int error = GetLastError();
struct passwd *
getpwnam(char *unused) {
- static struct passwd pwd = {NULL, NULL, 100, 100, NULL, NULL, NULL};
+ static struct passwd pwd = {nullptr, nullptr, 100, 100, nullptr, nullptr, nullptr};
return &pwd;
}
struct group *
getgrnam(char *unused) {
- static struct group grp = {NULL, NULL, 100, NULL};
+ static struct group grp = {nullptr, nullptr, 100, nullptr};
return &grp;
}
(_osfhnd(filehandle) != (long) INVALID_HANDLE_VALUE)) {
switch (filehandle) {
case 0:
- SetStdHandle(STD_INPUT_HANDLE, NULL);
+ SetStdHandle(STD_INPUT_HANDLE, nullptr);
break;
case 1:
- SetStdHandle(STD_OUTPUT_HANDLE, NULL);
+ SetStdHandle(STD_OUTPUT_HANDLE, nullptr);
break;
case 2:
- SetStdHandle(STD_ERROR_HANDLE, NULL);
+ SetStdHandle(STD_ERROR_HANDLE, nullptr);
break;
}
_osfhnd(filehandle) = (long) INVALID_HANDLE_VALUE;
if (ms_eventlog)
return;
- ms_eventlog = RegisterEventSourceA(NULL, ident);
+ ms_eventlog = RegisterEventSourceA(nullptr, ident);
- // note: RegisterEventAtSourceA may fail and return NULL.
+ // note: RegisterEventAtSourceA may fail and return nullptr.
// in that case we'll just retry at the next message or not log
}
#define SYSLOG_MAX_MSG_SIZE 1024
}
//Windows API suck. They are overengineered
- ReportEventA(ms_eventlog, logtype, 0, 0, NULL, 1, 0,
- const_cast<const char **>(&str), NULL);
+ ReportEventA(ms_eventlog, logtype, 0, 0, nullptr, 1, 0,
+ const_cast<const char **>(&str), nullptr);
}
/* note: this is all MSWindows-specific code; all of it should be conditional */
#elif _SQUID_FREEBSD_
int jailed = 0;
size_t len = sizeof(jailed);
- ::sysctlbyname("security.jail.jailed", &jailed, &len, NULL, 0);
+ ::sysctlbyname("security.jail.jailed", &jailed, &len, nullptr, 0);
return !jailed;
#else
return false;
errno = ENOENT;
return -1;
}
- if (!GetVolumeInformation(drive, NULL, 0, &vsn, &maxlen, &flags, NULL, 0)) {
+ if (!GetVolumeInformation(drive, nullptr, 0, &vsn, &maxlen, &flags, nullptr, 0)) {
errno = ENOENT;
return -1;
}
do {
do {
if (slen < 1 || (sc = *s) == '\0')
- return (NULL);
+ return nullptr;
--slen;
++s;
} while (sc != c);
if (len > slen)
- return (NULL);
+ return nullptr;
} while (strncmp(s, find, len) != 0);
--s;
}
void *p = calloc(n, sz);
- if (p == NULL) {
+ if (!p) {
if (failure_notify) {
static char msg[128];
snprintf(msg, 128, "xcalloc: Unable to allocate %" PRIuSIZE " blocks of %" PRIuSIZE " bytes!\n", n, sz);
void *p = malloc(sz);
- if (p == NULL) {
+ if (!p) {
if (failure_notify) {
static char msg[128];
snprintf(msg, 128, "xmalloc: Unable to allocate %" PRIuSIZE " bytes!\n", sz);
void *p= realloc(s, sz);
- if (p == NULL) {
+ if (!p) {
if (failure_notify) {
static char msg[128];
snprintf(msg, 128, "xrealloc: Unable to reallocate %" PRIuSIZE " bytes!\n", sz);
/**
* xcalloc() - same as calloc(3). Used for portability.
- * Never returns NULL; fatal on error.
+ * Never returns nullptr; fatal on error.
*
* Define failure_notify to receive error message.
* otherwise perror() is used to display it.
/**
* xmalloc() - same as malloc(3). Used for portability.
- * Never returns NULL; fatal on error.
+ * Never returns nullptr; fatal on error.
*
* Define failure_notify to receive error message.
* otherwise perror() is used to display it.
/**
* xrealloc() - same as realloc(3). Used for portability.
- * Never returns NULL; fatal on error.
+ * Never returns nullptr; fatal on error.
*/
void *xrealloc(void *s, size_t sz);
/**
* xfree() - same as free(3). Used for portability.
* Accepts pointers to dynamically allocated const data.
- * Will not call free(3) if the pointer is NULL.
+ * Will not call free(3) if the pointer is nullptr.
*
* Pointer is left with a value on completion.
- * Use safe_free() if the pointer needs to be set to NULL afterward.
+ * Use safe_free() if the pointer needs to be set to nullptr afterward.
*
* Define failure_notify to receive error message.
* otherwise perror() is used to display it.
/**
* safe_free() - same as free(3). Used for portability.
* Accepts pointers to dynamically allocated const data.
- * Will not call free(3) if the pointer is NULL.
- * Sets the pointer to NULL on completion.
+ * Will not call free(3) if the pointer is nullptr.
+ * Sets the pointer to nullptr on completion.
*
* Use xfree() if the pointer does not need to be set afterward.
*
* Define failure_notify to receive error message.
* otherwise perror() is used to display it.
*/
-#define safe_free(x) while ((x)) { free_const((x)); (x) = NULL; }
+#define safe_free(x) while ((x)) { free_const((x)); (x) = nullptr; }
#ifdef __cplusplus
}
/** Provide the textual display of a system error number.
* A string is always returned.
- * Where strerror() would have provided NULL this will report the error as unknown.
+ * Where strerror() would have provided nullptr this will report the error as unknown.
* On MS Windows the native Win32 errors are also translated.
*/
extern const char * xstrerr(int error);
{
if (!s) {
if (failure_notify) {
- (*failure_notify) ("xstrdup: tried to dup a NULL pointer!\n");
+ (*failure_notify) ("xstrdup: tried to dup a nullptr!\n");
} else {
errno = EINVAL;
- perror("xstrdup: tried to dup a NULL pointer!");
+ perror("xstrdup: tried to dup a nullptr!");
}
exit(1);
}
if (!s) {
errno = EINVAL;
if (failure_notify) {
- (*failure_notify) ("xstrndup: tried to dup a NULL pointer!\n");
+ (*failure_notify) ("xstrndup: tried to dup a nullptr!\n");
} else {
- perror("xstrndup: tried to dup a NULL pointer!");
+ perror("xstrndup: tried to dup a nullptr!");
}
exit(1);
}
/**
* xstrdup() - same as strdup(3). Used for portability.
- * Never returns NULL; fatal on error.
+ * Never returns nullptr; fatal on error.
*
- * Sets errno to EINVAL if a NULL pointer is passed.
+ * Sets errno to EINVAL if a nullptr pointer is passed.
*
* Define failure_notify to receive error message.
* otherwise perror() is used to display it.
/*
* xstrncpy() - similar to strncpy(3) but terminates string
- * always with '\0' if (n != 0 and dst != NULL),
+ * always with '\0' if (n != 0 and dst != nullptr),
* and doesn't do padding
*/
char *xstrncpy(char *dst, const char *src, size_t n);
* while strndup(3) copies up to n bytes and allocates up to n+1 bytes
* to fit the terminating character. Assumes s is 0-terminated (another XXX).
*
- * Never returns NULL; fatal on error.
+ * Never returns nullptr; fatal on error.
*
- * Sets errno to EINVAL if a NULL pointer or negative
+ * Sets errno to EINVAL if a nullptr pointer or negative
* length is passed.
*
* Define failure_notify to receive error message.
xstrtoul(const char *s, char **end, unsigned long *value,
unsigned long min, unsigned long max)
{
- char *my_end = NULL;
+ char *my_end = nullptr;
errno = 0;
unsigned long v = strtoul(s, &my_end, 0);
if (my_end == s)
return false;
- if (end != NULL)
+ if (end)
*end = my_end;
if (errno != ERANGE && min <= v && (max == 0 || v <= max)) {
- if (value != NULL)
+ if (value)
*value = v;
- if (end == NULL)
+ if (!end)
return *my_end == '\0';
return true;
}
{
unsigned long v = 0;
bool ret = xstrtoul(s, end, &v, min, max);
- if (value != NULL) {
+ if (value) {
*value = v;
if (v != static_cast<unsigned long>(*value)) {
* \param min minimum accepted value
* \param max maximum accepted value
*
- * If @end is NULL, we assume the caller wants a "strict strtoul", and hence
+ * If @end is nullptr, we assume the caller wants a "strict strtoul", and hence
* "15a" is rejected.
* In either case, the value obtained is compared for min-max compliance.
* Base is always 0, i.e. autodetect depending on @s.