]>
git.ipfire.org Git - thirdparty/squid.git/blob - include/util.h
4 * AUTHOR: Harvest Derived
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
46 #include <arpa/inet.h>
49 SQUIDCEXTERN
const char *mkhttpdlogtime(const time_t *);
50 SQUIDCEXTERN
const char *mkrfc1123(time_t);
51 SQUIDCEXTERN
char *uudecode(const char *);
52 SQUIDCEXTERN
char *xstrdup(const char *);
53 SQUIDCEXTERN
char *xstrndup(const char *, size_t);
54 SQUIDCEXTERN
const char *xstrerr(int xerrno
);
55 SQUIDCEXTERN
const char *xstrerror(void);
56 SQUIDCEXTERN
int tvSubMsec(struct timeval
, struct timeval
);
57 SQUIDCEXTERN
int tvSubUsec(struct timeval
, struct timeval
);
58 SQUIDCEXTERN
double tvSubDsec(struct timeval
, struct timeval
);
59 SQUIDCEXTERN
char *xstrncpy(char *, const char *, size_t);
60 SQUIDCEXTERN
size_t xcountws(const char *str
);
61 SQUIDCEXTERN
time_t parse_rfc1123(const char *str
);
62 SQUIDCEXTERN
void *xcalloc(size_t, size_t);
63 SQUIDCEXTERN
void *xmalloc(size_t);
64 SQUIDCEXTERN
void *xrealloc(void *, size_t);
65 SQUIDCEXTERN
void Tolower(char *);
66 SQUIDCEXTERN
void xfree(void *);
67 SQUIDCEXTERN
void xxfree(const void *);
70 * Any code using libstdc++ must have externally resolvable overloads
71 * for void * operator new - which means in the .o for the binary,
72 * or in a shared library. static libs don't propogate the symbol
73 * so, look in the translation unit containing main() in squid
74 * for the extern version in squid
76 #ifndef _SQUID_EXTERNNEW_
77 #ifdef __GNUC_STDC_INLINE__
78 #define _SQUID_EXTERNNEW_ extern inline __attribute__((gnu_inline))
80 #define _SQUID_EXTERNNEW_ extern inline
87 SQUIDCEXTERN
char *latin1_to_utf8(char *out
, size_t size
, const char *in
);
90 SQUIDCEXTERN
char *html_quote(const char *);
92 #if XMALLOC_STATISTICS
93 SQUIDCEXTERN
void malloc_statistics(void (*)(int, int, int, void *), void *);
97 #define xmalloc(size) (xmalloc_func="xmalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xmalloc(size))
98 #define xfree(ptr) (xmalloc_func="xfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xfree(ptr))
99 #define xxfree(ptr) (xmalloc_func="xxfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xxfree(ptr))
100 #define xrealloc(ptr,size) (xmalloc_func="xrealloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xrealloc(ptr,size))
101 #define xcalloc(n,size) (xmalloc_func="xcalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xcalloc(n,size))
102 #define xstrdup(ptr) (xmalloc_func="xstrdup",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xstrdup(ptr))
103 extern int xmalloc_line
;
104 extern char *xmalloc_file
;
105 extern char *xmalloc_func
;
106 extern int xmalloc_trace
;
107 extern size_t xmalloc_total
;
108 extern void xmalloc_find_leaks(void);
111 SQUIDCEXTERN
time_t parse_iso3307_time(const char *buf
);
112 SQUIDCEXTERN
char *base64_decode(const char *coded
);
113 SQUIDCEXTERN
const char *base64_encode(const char *decoded
);
114 SQUIDCEXTERN
const char *base64_encode_bin(const char *data
, int len
);
116 SQUIDCEXTERN
double xpercent(double part
, double whole
);
117 SQUIDCEXTERN
int xpercentInt(double part
, double whole
);
118 SQUIDCEXTERN
double xdiv(double nom
, double denom
);
120 SQUIDCEXTERN
const char *xitoa(int num
);
121 SQUIDCEXTERN
const char *xint64toa(int64_t num
);
129 /* gb_type operations */
130 #define gb_flush_limit (0x3FFFFFFF)
131 #define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; }
132 #define gb_incb(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; }
133 #define gb_incc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->count+= delta; }
134 extern double gb_to_double(const gb_t
*);
135 SQUIDCEXTERN
const char *double_to_str(char *buf
, int buf_size
, double value
);
136 extern const char *gb_to_str(const gb_t
*);
137 extern void gb_flush(gb_t
*); /* internal, do not use this */
140 * Returns the amount of known allocated memory
142 int statMemoryAccounted(void);
147 SQUIDCEXTERN
int chroot (const char *);
148 SQUIDCEXTERN
int ftruncate(int, off_t
);
149 #ifndef HAVE_GETTIMEOFDAY
150 SQUIDCEXTERN
int gettimeofday(struct timeval
* ,void *);
152 SQUIDCEXTERN
int kill(pid_t
, int);
153 SQUIDCEXTERN
int statfs(const char *, struct statfs
*);
154 SQUIDCEXTERN
int truncate(const char *, off_t
);
155 SQUIDCEXTERN
const char * wsastrerror(int);
156 SQUIDCEXTERN
struct passwd
*getpwnam(char *);
157 SQUIDCEXTERN
struct group
*getgrnam(char *);
158 SQUIDCEXTERN uid_t
geteuid(void);
159 SQUIDCEXTERN uid_t
getuid(void);
160 SQUIDCEXTERN
int setuid(uid_t
);
161 SQUIDCEXTERN
int seteuid(uid_t
);
162 SQUIDCEXTERN gid_t
getgid(void);
163 SQUIDCEXTERN gid_t
getegid(void);
164 SQUIDCEXTERN
int setgid(gid_t
);
165 SQUIDCEXTERN
int setegid(gid_t
);
166 SQUIDCEXTERN
const char *WIN32_strerror(int);
167 SQUIDCEXTERN
void WIN32_maperror(unsigned long);
169 #endif /* SQUID_UTIL_H */