#define debug(X...) \
if (debug_enabled) { \
- fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, (long)getpid() ); \
+ fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, static_cast<long>(getpid())); \
fprintf(stderr,X); \
} else (void)0
if (p == NULL) {
if (failure_notify) {
static char msg[128];
- snprintf(msg, 128, "xcalloc: Unable to allocate %lu blocks of %lu bytes!\n", (unsigned long)n, (unsigned long)sz);
+ snprintf(msg, 128, "xcalloc: Unable to allocate %" PRIuSIZE " blocks of %" PRIuSIZE " bytes!\n", n, sz);
failure_notify(msg);
} else {
perror("xcalloc");
if (p == NULL) {
if (failure_notify) {
static char msg[128];
- snprintf(msg, 128, "xmalloc: Unable to allocate %lu bytes!\n", (unsigned long)sz);
+ snprintf(msg, 128, "xmalloc: Unable to allocate %" PRIuSIZE " bytes!\n", sz);
failure_notify(msg);
} else {
perror("malloc");
if (p == NULL) {
if (failure_notify) {
static char msg[128];
- snprintf(msg, 128, "xrealloc: Unable to reallocate %lu bytes!\n", (unsigned long)sz);
+ snprintf(msg, 128, "xrealloc: Unable to reallocate %" PRIuSIZE " bytes!\n", sz);
failure_notify(msg);
} else {
perror("realloc");
#if HAVE_CTYPE_H
#include <ctype.h>
#endif
+
+#if __cplusplus
+#define xisspace(x) isspace(static_cast<unsigned char>(x))
+#define xtoupper(x) toupper(static_cast<unsigned char>(x))
+#define xtolower(x) tolower(static_cast<unsigned char>(x))
+#define xisdigit(x) isdigit(static_cast<unsigned char>(x))
+#define xisascii(x) isascii(static_cast<unsigned char>(x))
+#define xislower(x) islower(static_cast<unsigned char>(x))
+#define xisalpha(x) isalpha(static_cast<unsigned char>(x))
+#define xisprint(x) isprint(static_cast<unsigned char>(x))
+#define xisalnum(x) isalnum(static_cast<unsigned char>(x))
+#define xiscntrl(x) iscntrl(static_cast<unsigned char>(x))
+#define xispunct(x) ispunct(static_cast<unsigned char>(x))
+#define xisupper(x) isupper(static_cast<unsigned char>(x))
+#define xisxdigit(x) isxdigit(static_cast<unsigned char>(x))
+#define xisgraph(x) isgraph(static_cast<unsigned char>(x))
+
+#else /* ! __cplusplus */
#define xisspace(x) isspace((unsigned char)x)
#define xtoupper(x) toupper((unsigned char)x)
#define xtolower(x) tolower((unsigned char)x)
#define xisupper(x) isupper((unsigned char)x)
#define xisxdigit(x) isxdigit((unsigned char)x)
#define xisgraph(x) isgraph((unsigned char)x)
+#endif
#endif /* _SQUID_COMPAT_XIS_H */
char *
xstrdup(const char *s)
{
- size_t sz;
- char *p;
-
- if (s == NULL) {
+ if (!s) {
if (failure_notify) {
(*failure_notify) ("xstrdup: tried to dup a NULL pointer!\n");
} else {
}
/* copy string, including terminating character */
- sz = strlen(s) + 1;
- p = (char *)xmalloc(sz);
+ size_t sz = strlen(s) + 1;
+ char *p = static_cast<char *>(xmalloc(sz));
memcpy(p, s, sz);
return p;
char *
xstrndup(const char *s, size_t n)
{
- size_t sz;
- char *p;
-
- if (s == NULL) {
+ if (!s) {
errno = EINVAL;
if (failure_notify) {
(*failure_notify) ("xstrndup: tried to dup a NULL pointer!\n");
exit(1);
}
- sz = strlen(s) + 1;
+ size_t sz = strlen(s) + 1;
// size_t is unsigned, as mandated by c99 and c++ standards.
if (sz > n)
sz = n;
- p = xstrncpy((char *)xmalloc(sz), s, sz);
+ char *p = xstrncpy(static_cast<char *>(xmalloc(sz)), s, sz);
return p;
}