if (sz <= XMS_DBG_SPLIT)
return (sz + XMS_DBG_GRAIN_SM - 1) / XMS_DBG_GRAIN_SM;
-
+
return (sz + XMS_DBG_GRAIN - 1) / XMS_DBG_GRAIN + XMS_DBG_OFFSET;
}
{
for (int i = 0; i <= XMS_DBG_MAXINDEX; i++)
malloc_sizes[i] = malloc_histo[i] = 0;
-
+
dbg_stat_init = 1;
}
-
+
static int
malloc_stat(int sz)
{
if (!dbg_stat_init)
- stat_init();
-
+ stat_init();
+
return malloc_sizes[XMS_DBG_INDEX(sz)] += 1;
}
}
void *
-xrealloc(void *s, size_t sz)
+xrealloc(void *s, size_t sz)
{
PROF_start(xrealloc);
#if XMALLOC_TRACE
xmalloc_show_trace(s, -1);
-#endif
-
- if (sz < 1)
+#endif
+
+ if (sz < 1)
sz = 1;
-
+
#if XMALLOC_DEBUG
if (s != NULL)
check_free(s);
} else {
perror("realloc");
}
-
+
exit(1);
}
-
+
#if XMALLOC_DEBUG
check_malloc(p, sz);
#endif
#if XMALLOC_STATISTICS
- malloc_stat(sz);
+ malloc_stat(sz);
#endif
#if XMALLOC_TRACE
xmalloc_show_trace(p, 1);
PROF_start(free_const);
#if XMALLOC_TRACE
- xmalloc_show_trace(s, -1);
+ xmalloc_show_trace(s, -1);
#endif
#if XMALLOC_DEBUG
extern "C" {
#endif
-/**
- * xcalloc() - same as calloc(3). Used for portability.
- * Never returns NULL; fatal on error.
- *
- * Define failure_notify to receive error message.
- * otherwise perror() is used to display it.
- */
-void *xcalloc(size_t n, size_t sz);
+ /**
+ * xcalloc() - same as calloc(3). Used for portability.
+ * Never returns NULL; fatal on error.
+ *
+ * Define failure_notify to receive error message.
+ * otherwise perror() is used to display it.
+ */
+ void *xcalloc(size_t n, size_t sz);
-/**
- * xmalloc() - same as malloc(3). Used for portability.
- * Never returns NULL; fatal on error.
- *
- * Define failure_notify to receive error message.
- * otherwise perror() is used to display it.
- */
-void *xmalloc(size_t sz);
+ /**
+ * xmalloc() - same as malloc(3). Used for portability.
+ * Never returns NULL; fatal on error.
+ *
+ * Define failure_notify to receive error message.
+ * otherwise perror() is used to display it.
+ */
+ void *xmalloc(size_t sz);
-/**
- * xrealloc() - same as realloc(3). Used for portability.
- * Never returns NULL; fatal on error.
- */
-void *xrealloc(void *s, size_t sz);
+ /**
+ * xrealloc() - same as realloc(3). Used for portability.
+ * Never returns NULL; fatal on error.
+ */
+ void *xrealloc(void *s, size_t sz);
-/**
- * xfree() - same as free(3). Used for portability.
- * Will not call free(3) if s == NULL.
- *
- * Define failure_notify to receive error message.
- * otherwise perror() is used to display it.
- */
-void xfree(void *s);
+ /**
+ * xfree() - same as free(3). Used for portability.
+ * Will not call free(3) if s == NULL.
+ *
+ * Define failure_notify to receive error message.
+ * otherwise perror() is used to display it.
+ */
+ void xfree(void *s);
-/**
- * xxfree() / free_const() - Same as free(3). Used for portability.
- * Accepts pointers to dynamically allocated const data.
- *
- * Define failure_notify to receive error message.
- * otherwise perror() is used to display it.
- */
-void free_const(const void *s);
+ /**
+ * xxfree() / free_const() - Same as free(3). Used for portability.
+ * Accepts pointers to dynamically allocated const data.
+ *
+ * Define failure_notify to receive error message.
+ * otherwise perror() is used to display it.
+ */
+ void free_const(const void *s);
/// Backward compatibility alias for free_const(const void *s)
#define xxfree(x) free_const((x))
-/**
- * Accepts pointers to dynamically allocated const data.
- * Will not call free(3) if the pointer is NULL.
- * Sets the pointer to NULL 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.
- */
+ /**
+ * Accepts pointers to dynamically allocated const data.
+ * Will not call free(3) if the pointer is NULL.
+ * Sets the pointer to NULL 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) { xxfree(x); (x) = NULL; }
#if XMALLOC_STATISTICS
-void malloc_statistics(void (*func) (int, int, int, void *), void *data);
+ void malloc_statistics(void (*func) (int, int, int, void *), void *data);
#endif
#ifdef __cplusplus
extern "C" {
#endif
-/**
- * xstrdup() - same as strdup(3). Used for portability.
- * Never returns NULL; fatal on error.
- *
- * Sets errno to EINVAL if a NULL pointer is passed.
- *
- * Define failure_notify to receive error message.
- * otherwise perror() is used to display it.
- */
-char *xstrdup(const char *s);
+ /**
+ * xstrdup() - same as strdup(3). Used for portability.
+ * Never returns NULL; fatal on error.
+ *
+ * Sets errno to EINVAL if a NULL pointer is passed.
+ *
+ * Define failure_notify to receive error message.
+ * otherwise perror() is used to display it.
+ */
+ char *xstrdup(const char *s);
#ifdef strdup
#undef strdup
#endif
#define strdup(X) xstrdup((X))
-/*
- * xstrncpy() - similar to strncpy(3) but terminates string
- * always with '\0' if (n != 0 and dst != NULL),
- * and doesn't do padding
- */
-char *xstrncpy(char *dst, const char *src, size_t n);
-
-/**
- * xstrndup() - same as strndup(3). Used for portability.
- * Never returns NULL; fatal on error.
- *
- * Sets errno to EINVAL if a NULL pointer or negative
- * length is passed.
- *
- * Define failure_notify to receive error message.
- * otherwise perror() is used to display it.
- */
-char *xstrndup(const char *s, size_t n);
+ /*
+ * xstrncpy() - similar to strncpy(3) but terminates string
+ * always with '\0' if (n != 0 and dst != NULL),
+ * and doesn't do padding
+ */
+ char *xstrncpy(char *dst, const char *src, size_t n);
+
+ /**
+ * xstrndup() - same as strndup(3). Used for portability.
+ * Never returns NULL; fatal on error.
+ *
+ * Sets errno to EINVAL if a NULL pointer or negative
+ * length is passed.
+ *
+ * Define failure_notify to receive error message.
+ * otherwise perror() is used to display it.
+ */
+ char *xstrndup(const char *s, size_t n);
#ifdef strndup
#undef strndup
extern "C" {
#endif
-extern char *base64_decode(const char *coded);
-extern const char *base64_encode(const char *decoded);
-extern const char *base64_encode_bin(const char *data, int len);
+ extern char *base64_decode(const char *coded);
+ extern const char *base64_encode(const char *decoded);
+ extern const char *base64_encode_bin(const char *data, int len);
#ifdef __cplusplus
}
extern "C" {
#endif
-extern const char *mkhttpdlogtime(const time_t *);
-extern const char *mkrfc1123(time_t);
-extern time_t parse_rfc1123(const char *str);
+ extern const char *mkhttpdlogtime(const time_t *);
+ extern const char *mkrfc1123(time_t);
+ extern time_t parse_rfc1123(const char *str);
#ifdef __cplusplus
}
extern "C" {
#endif
-/* Encoder rfc1738_do_escape flag values. */
+ /* Encoder rfc1738_do_escape flag values. */
#define RFC1738_ESCAPE_UNSAFE 0
#define RFC1738_ESCAPE_RESERVED 1
#define RFC1738_ESCAPE_UNESCAPED -1
-/**
- * \group rfc1738 RFC 1738 URL-escaping library
- *
- * Public API is formed of a triplet of encode functions mapping to the rfc1738_do_encode() engine.
- *
- * ASCII characters are split into three groups:
- * \item SAFE Characters which are safe to occur in any URL. For example A,B,C
- * \item UNSAFE Characters which are completely usafe to occur in any URL. For example; backspace, tab, space, newline
- * \item RESERVED Characters which are reserved for special meaning and may only occur in certain parts of a URL.
- *
- * Returns a static buffer containing the RFC 1738 compliant, escaped version of the given url.
- *
- * \param flags RFC1738_ESCAPE_UNSAFE Only encode unsafe characters. Ignore reserved.
- * \param flags RFC1738_ESCAPE_RESERVED Encode all unsafe and reserved characters.
- * \param flags RFC1738_ESCAPE_UNESCAPED Encode all unsafe characters which have not already been encoded.
- */
-extern char *rfc1738_do_escape(const char *url, int flags);
-
-/* Old API functions */
+ /**
+ * \group rfc1738 RFC 1738 URL-escaping library
+ *
+ * Public API is formed of a triplet of encode functions mapping to the rfc1738_do_encode() engine.
+ *
+ * ASCII characters are split into three groups:
+ * \item SAFE Characters which are safe to occur in any URL. For example A,B,C
+ * \item UNSAFE Characters which are completely usafe to occur in any URL. For example; backspace, tab, space, newline
+ * \item RESERVED Characters which are reserved for special meaning and may only occur in certain parts of a URL.
+ *
+ * Returns a static buffer containing the RFC 1738 compliant, escaped version of the given url.
+ *
+ * \param flags RFC1738_ESCAPE_UNSAFE Only encode unsafe characters. Ignore reserved.
+ * \param flags RFC1738_ESCAPE_RESERVED Encode all unsafe and reserved characters.
+ * \param flags RFC1738_ESCAPE_UNESCAPED Encode all unsafe characters which have not already been encoded.
+ */
+ extern char *rfc1738_do_escape(const char *url, int flags);
+
+ /* Old API functions */
#define rfc1738_escape(x) rfc1738_do_escape(x, RFC1738_ESCAPE_UNSAFE)
#define rfc1738_escape_part(x) rfc1738_do_escape(x, RFC1738_ESCAPE_RESERVED)
#define rfc1738_escape_unescaped(x) rfc1738_do_escape(x, RFC1738_ESCAPE_UNESCAPED)
-/**
- * Unescape a URL string according to RFC 1738 specification.
- * String is unescaped in-place
- */
-extern void rfc1738_unescape(char *url);
+ /**
+ * Unescape a URL string according to RFC 1738 specification.
+ * String is unescaped in-place
+ */
+ extern void rfc1738_unescape(char *url);
#ifdef __cplusplus
}
#endif
#define HASHLEN 16
-typedef char HASH[HASHLEN];
+ typedef char HASH[HASHLEN];
#define HASHHEXLEN 32
-typedef char HASHHEX[HASHHEXLEN + 1];
+ typedef char HASHHEX[HASHHEXLEN + 1];
-/* calculate H(A1) as per HTTP Digest spec */
-extern void DigestCalcHA1(
- const char *pszAlg,
- const char *pszUserName,
- const char *pszRealm,
- const char *pszPassword,
- const char *pszNonce,
- const char *pszCNonce,
- HASH HA1,
- HASHHEX SessionKey
-);
+ /* calculate H(A1) as per HTTP Digest spec */
+ extern void DigestCalcHA1(
+ const char *pszAlg,
+ const char *pszUserName,
+ const char *pszRealm,
+ const char *pszPassword,
+ const char *pszNonce,
+ const char *pszCNonce,
+ HASH HA1,
+ HASHHEX SessionKey
+ );
-/* calculate request-digest/response-digest as per HTTP Digest spec */
-extern void DigestCalcResponse(
- const HASHHEX HA1, /* H(A1) */
- const char *pszNonce, /* nonce from server */
- const char *pszNonceCount, /* 8 hex digits */
- const char *pszCNonce, /* client nonce */
- const char *pszQop, /* qop-value: "", "auth", "auth-int" */
- const char *pszMethod, /* method from the request */
- const char *pszDigestUri, /* requested URL */
- const HASHHEX HEntity, /* H(entity body) if qop="auth-int" */
- HASHHEX Response /* request-digest or response-digest */
-);
+ /* calculate request-digest/response-digest as per HTTP Digest spec */
+ extern void DigestCalcResponse(
+ const HASHHEX HA1, /* H(A1) */
+ const char *pszNonce, /* nonce from server */
+ const char *pszNonceCount, /* 8 hex digits */
+ const char *pszCNonce, /* client nonce */
+ const char *pszQop, /* qop-value: "", "auth", "auth-int" */
+ const char *pszMethod, /* method from the request */
+ const char *pszDigestUri, /* requested URL */
+ const HASHHEX HEntity, /* H(entity body) if qop="auth-int" */
+ HASHHEX Response /* request-digest or response-digest */
+ );
-extern void CvtHex(const HASH Bin, HASHHEX Hex);
+ extern void CvtHex(const HASH Bin, HASHHEX Hex);
-extern void CvtBin(const HASHHEX Hex, HASH Bin);
+ extern void CvtBin(const HASHHEX Hex, HASH Bin);
#ifdef __cplusplus
}
#define XP_NOBEST (hrtime_t)-1
-typedef struct _xprof_stats_node xprof_stats_node;
-
-typedef struct _xprof_stats_data xprof_stats_data;
-
-struct _xprof_stats_data {
- hrtime_t start;
- hrtime_t stop;
- hrtime_t delta;
- hrtime_t best;
- hrtime_t worst;
- hrtime_t count;
- hrtime_t accum;
- int64_t summ;
-};
-
-struct _xprof_stats_node {
- const char *name;
- xprof_stats_data accu;
- xprof_stats_data hist;
-};
-
-typedef xprof_stats_node TimersArray[1];
-
-/* public Data */
-extern TimersArray *xprof_Timers;
-
-/* Exported functions */
-extern void xprof_start(xprof_type type, const char *timer);
-extern void xprof_stop(xprof_type type, const char *timer);
-extern void xprof_event(void *data);
+ typedef struct _xprof_stats_node xprof_stats_node;
+
+ typedef struct _xprof_stats_data xprof_stats_data;
+
+ struct _xprof_stats_data {
+ hrtime_t start;
+ hrtime_t stop;
+ hrtime_t delta;
+ hrtime_t best;
+ hrtime_t worst;
+ hrtime_t count;
+ hrtime_t accum;
+ int64_t summ;
+ };
+
+ struct _xprof_stats_node {
+ const char *name;
+ xprof_stats_data accu;
+ xprof_stats_data hist;
+ };
+
+ typedef xprof_stats_node TimersArray[1];
+
+ /* public Data */
+ extern TimersArray *xprof_Timers;
+
+ /* Exported functions */
+ extern void xprof_start(xprof_type type, const char *timer);
+ extern void xprof_stop(xprof_type type, const char *timer);
+ extern void xprof_event(void *data);
#define PROF_start(type) xprof_start(XPROF_##type, #type)
#define PROF_stop(type) xprof_stop(XPROF_##type, #type)
return 0;
}
end = pos;
- while(end <= (start+len) && *end != '\\' && *end != '\"' && *end > 0x1F && *end != 0x7F)
+ while (end <= (start+len) && *end != '\\' && *end != '\"' && *end > 0x1F && *end != 0x7F)
end++;
if (*end <= 0x1F || *end == 0x7F) {
debugs(66, 2, "failed to parse a quoted-string header field with CTL octet " << (start-pos)
{
return (t2.tv_sec - t1.tv_sec) * 1000 +
(t2.tv_usec - t1.tv_usec) / 1000;
-}
+}
TimeEngine::~TimeEngine()
{}