]> git.ipfire.org Git - thirdparty/squid.git/blame - include/util.h
SourceFormat Enforcement
[thirdparty/squid.git] / include / util.h
CommitLineData
090089c4 1/*
5c193dec 2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
c5dd4956 3 *
5c193dec
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
090089c4 7 */
01fe0751 8
b5638623 9#ifndef SQUID_UTIL_H
10#define SQUID_UTIL_H
090089c4 11
9d90e665 12#if HAVE_TIME_H
13#include <time.h>
14#endif
cc192b50 15#if HAVE_ARPA_INET_H
16#include <arpa/inet.h>
17#endif
090089c4 18
e6ccf245 19SQUIDCEXTERN int tvSubUsec(struct timeval, struct timeval);
20SQUIDCEXTERN double tvSubDsec(struct timeval, struct timeval);
e6ccf245 21SQUIDCEXTERN void Tolower(char *);
605f2c3e 22#if defined(__cplusplus)
c5dd4956 23/*
599b06d5 24 * Any code using libstdc++ must have externally resolvable overloads
f95fe6ed 25 * for void * operator new - which means in the .o for the binary,
26 * or in a shared library. static libs don't propogate the symbol
27 * so, look in the translation unit containing main() in squid
28 * for the extern version in squid
29 */
605f2c3e 30#if !defined(_SQUID_EXTERNNEW_)
c56db9be 31#if defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__)
1f01fdf1
HN
32#define _SQUID_EXTERNNEW_ extern inline __attribute__((gnu_inline))
33#else
f95fe6ed 34#define _SQUID_EXTERNNEW_ extern inline
35#endif
599b06d5 36#endif
f95fe6ed 37#include "SquidNew.h"
a07fad69 38#endif
30a4f2a8 39
e6ccf245 40SQUIDCEXTERN time_t parse_iso3307_time(const char *buf);
6ad85e8a 41
e6ccf245 42SQUIDCEXTERN double xpercent(double part, double whole);
43SQUIDCEXTERN int xpercentInt(double part, double whole);
44SQUIDCEXTERN double xdiv(double nom, double denom);
7021844c 45
e6ccf245 46SQUIDCEXTERN const char *xitoa(int num);
47f6e231 47SQUIDCEXTERN const char *xint64toa(int64_t num);
7021844c 48
d96ceb8e 49typedef struct {
50 size_t count;
51 size_t bytes;
52 size_t gb;
53} gb_t;
54
55/* gb_type operations */
56#define gb_flush_limit (0x3FFFFFFF)
57#define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; }
58#define gb_incb(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; }
59#define gb_incc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->count+= delta; }
60extern double gb_to_double(const gb_t *);
e6ccf245 61SQUIDCEXTERN const char *double_to_str(char *buf, int buf_size, double value);
d96ceb8e 62extern const char *gb_to_str(const gb_t *);
63extern void gb_flush(gb_t *); /* internal, do not use this */
64
2d72d4fd 65/*
66 * Returns the amount of known allocated memory
67 */
68int statMemoryAccounted(void);
69
43d1bbe4
FC
70SQUIDCEXTERN unsigned int RoundTo(const unsigned int num, const unsigned int what);
71
b5638623 72#endif /* SQUID_UTIL_H */
f53969cc 73