Fix the gcc warnings in this module (since we now seem to be
[u/mdw/putty] / misc.h
... / ...
CommitLineData
1#ifndef PUTTY_MISC_H
2#define PUTTY_MISC_H
3
4#include "puttymem.h"
5
6#include <stdarg.h> /* for va_list */
7
8#ifndef FALSE
9#define FALSE 0
10#endif
11#ifndef TRUE
12#define TRUE 1
13#endif
14
15char *dupstr(const char *s);
16char *dupcat(const char *s1, ...);
17char *dupprintf(const char *fmt, ...);
18char *dupvprintf(const char *fmt, va_list ap);
19
20void base64_encode_atom(unsigned char *data, int n, char *out);
21
22struct bufchain_granule;
23typedef struct bufchain_tag {
24 struct bufchain_granule *head, *tail;
25 int buffersize; /* current amount of buffered data */
26} bufchain;
27
28void bufchain_init(bufchain *ch);
29void bufchain_clear(bufchain *ch);
30int bufchain_size(bufchain *ch);
31void bufchain_add(bufchain *ch, const void *data, int len);
32void bufchain_prefix(bufchain *ch, void **data, int *len);
33void bufchain_consume(bufchain *ch, int len);
34void bufchain_fetch(bufchain *ch, void *data, int len);
35
36/*
37 * Debugging functions.
38 *
39 * Output goes to debug.log
40 *
41 * debug(()) (note the double brackets) is like printf().
42 *
43 * dmemdump() and dmemdumpl() both do memory dumps. The difference
44 * is that dmemdumpl() is more suited for when where the memory is is
45 * important (say because you'll be recording pointer values later
46 * on). dmemdump() is more concise.
47 */
48
49#ifdef DEBUG
50void dprintf(char *fmt, ...);
51void debug_memdump(void *buf, int len, int L);
52#define debug(x) (dprintf x)
53#define dmemdump(buf,len) debug_memdump (buf, len, 0);
54#define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
55#else
56#define debug(x)
57#define dmemdump(buf,len)
58#define dmemdumpl(buf,len)
59#endif
60
61#ifndef lenof
62#define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
63#endif
64
65#ifndef min
66#define min(x,y) ( (x) < (y) ? (x) : (y) )
67#endif
68#ifndef max
69#define max(x,y) ( (x) > (y) ? (x) : (y) )
70#endif
71
72#endif