Robustness fixes for KEXINIT handling and others. In particular, I've
[u/mdw/putty] / misc.h
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
15 char *dupstr(const char *s);
16 char *dupcat(const char *s1, ...);
17 char *dupprintf(const char *fmt, ...);
18 char *dupvprintf(const char *fmt, va_list ap);
19
20 void base64_encode_atom(unsigned char *data, int n, char *out);
21
22 struct bufchain_granule;
23 typedef struct bufchain_tag {
24 struct bufchain_granule *head, *tail;
25 int buffersize; /* current amount of buffered data */
26 } bufchain;
27
28 void bufchain_init(bufchain *ch);
29 void bufchain_clear(bufchain *ch);
30 int bufchain_size(bufchain *ch);
31 void bufchain_add(bufchain *ch, void *data, int len);
32 void bufchain_prefix(bufchain *ch, void **data, int *len);
33 void bufchain_consume(bufchain *ch, int len);
34 void 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
50 void dprintf(char *fmt, ...);
51 void 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