]> git.ipfire.org Git - thirdparty/squid.git/blob - include/util.h
Merge from trunk rev.13584
[thirdparty/squid.git] / include / util.h
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #ifndef SQUID_UTIL_H
10 #define SQUID_UTIL_H
11
12 #if HAVE_TIME_H
13 #include <time.h>
14 #endif
15 #if HAVE_ARPA_INET_H
16 #include <arpa/inet.h>
17 #endif
18
19 SQUIDCEXTERN int tvSubUsec(struct timeval, struct timeval);
20 SQUIDCEXTERN double tvSubDsec(struct timeval, struct timeval);
21 SQUIDCEXTERN void Tolower(char *);
22 #if defined(__cplusplus)
23 /*
24 * Any code using libstdc++ must have externally resolvable overloads
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 */
30 #if !defined(_SQUID_EXTERNNEW_)
31 #if defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__)
32 #define _SQUID_EXTERNNEW_ extern inline __attribute__((gnu_inline))
33 #else
34 #define _SQUID_EXTERNNEW_ extern inline
35 #endif
36 #endif
37 #include "SquidNew.h"
38 #endif
39
40 SQUIDCEXTERN time_t parse_iso3307_time(const char *buf);
41
42 SQUIDCEXTERN double xpercent(double part, double whole);
43 SQUIDCEXTERN int xpercentInt(double part, double whole);
44 SQUIDCEXTERN double xdiv(double nom, double denom);
45
46 SQUIDCEXTERN const char *xitoa(int num);
47 SQUIDCEXTERN const char *xint64toa(int64_t num);
48
49 typedef 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; }
60 extern double gb_to_double(const gb_t *);
61 SQUIDCEXTERN const char *double_to_str(char *buf, int buf_size, double value);
62 extern const char *gb_to_str(const gb_t *);
63 extern void gb_flush(gb_t *); /* internal, do not use this */
64
65 /*
66 * Returns the amount of known allocated memory
67 */
68 int statMemoryAccounted(void);
69
70 SQUIDCEXTERN unsigned int RoundTo(const unsigned int num, const unsigned int what);
71
72 #endif /* SQUID_UTIL_H */