8 #include "puttymem.h"
\r
10 #include <stdio.h> /* for FILE * */
\r
11 #include <stdarg.h> /* for va_list */
\r
12 #include <time.h> /* for struct tm */
\r
21 typedef struct Filename Filename;
\r
22 typedef struct FontSpec FontSpec;
\r
24 unsigned long parse_blocksize(const char *bs);
\r
25 char ctrlparse(char *s, char **next);
\r
27 size_t host_strcspn(const char *s, const char *set);
\r
28 char *host_strchr(const char *s, int c);
\r
29 char *host_strrchr(const char *s, int c);
\r
30 char *host_strduptrim(const char *s);
\r
32 char *dupstr(const char *s);
\r
33 char *dupcat(const char *s1, ...);
\r
34 char *dupprintf(const char *fmt, ...)
\r
36 __attribute__ ((format (printf, 1, 2)))
\r
39 char *dupvprintf(const char *fmt, va_list ap);
\r
40 void burnstr(char *string);
\r
42 int toint(unsigned);
\r
44 char *fgetline(FILE *fp);
\r
46 void base64_encode_atom(unsigned char *data, int n, char *out);
\r
47 int base64_decode_atom(char *atom, unsigned char *out);
\r
49 struct bufchain_granule;
\r
50 typedef struct bufchain_tag {
\r
51 struct bufchain_granule *head, *tail;
\r
52 int buffersize; /* current amount of buffered data */
\r
55 void bufchain_init(bufchain *ch);
\r
56 void bufchain_clear(bufchain *ch);
\r
57 int bufchain_size(bufchain *ch);
\r
58 void bufchain_add(bufchain *ch, const void *data, int len);
\r
59 void bufchain_prefix(bufchain *ch, void **data, int *len);
\r
60 void bufchain_consume(bufchain *ch, int len);
\r
61 void bufchain_fetch(bufchain *ch, void *data, int len);
\r
63 int validate_manual_hostkey(char *key);
\r
65 struct tm ltime(void);
\r
67 void smemclr(void *b, size_t len);
\r
70 * Debugging functions.
\r
72 * Output goes to debug.log
\r
74 * debug(()) (note the double brackets) is like printf().
\r
76 * dmemdump() and dmemdumpl() both do memory dumps. The difference
\r
77 * is that dmemdumpl() is more suited for when the memory address is
\r
78 * important (say because you'll be recording pointer values later
\r
79 * on). dmemdump() is more concise.
\r
83 void debug_printf(char *fmt, ...);
\r
84 void debug_memdump(void *buf, int len, int L);
\r
85 #define debug(x) (debug_printf x)
\r
86 #define dmemdump(buf,len) debug_memdump (buf, len, 0);
\r
87 #define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
\r
90 #define dmemdump(buf,len)
\r
91 #define dmemdumpl(buf,len)
\r
95 #define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
\r
99 #define min(x,y) ( (x) < (y) ? (x) : (y) )
\r
102 #define max(x,y) ( (x) > (y) ? (x) : (y) )
\r
105 #define GET_32BIT_LSB_FIRST(cp) \
\r
106 (((unsigned long)(unsigned char)(cp)[0]) | \
\r
107 ((unsigned long)(unsigned char)(cp)[1] << 8) | \
\r
108 ((unsigned long)(unsigned char)(cp)[2] << 16) | \
\r
109 ((unsigned long)(unsigned char)(cp)[3] << 24))
\r
111 #define PUT_32BIT_LSB_FIRST(cp, value) ( \
\r
112 (cp)[0] = (unsigned char)(value), \
\r
113 (cp)[1] = (unsigned char)((value) >> 8), \
\r
114 (cp)[2] = (unsigned char)((value) >> 16), \
\r
115 (cp)[3] = (unsigned char)((value) >> 24) )
\r
117 #define GET_16BIT_LSB_FIRST(cp) \
\r
118 (((unsigned long)(unsigned char)(cp)[0]) | \
\r
119 ((unsigned long)(unsigned char)(cp)[1] << 8))
\r
121 #define PUT_16BIT_LSB_FIRST(cp, value) ( \
\r
122 (cp)[0] = (unsigned char)(value), \
\r
123 (cp)[1] = (unsigned char)((value) >> 8) )
\r
125 #define GET_32BIT_MSB_FIRST(cp) \
\r
126 (((unsigned long)(unsigned char)(cp)[0] << 24) | \
\r
127 ((unsigned long)(unsigned char)(cp)[1] << 16) | \
\r
128 ((unsigned long)(unsigned char)(cp)[2] << 8) | \
\r
129 ((unsigned long)(unsigned char)(cp)[3]))
\r
131 #define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
\r
133 #define PUT_32BIT_MSB_FIRST(cp, value) ( \
\r
134 (cp)[0] = (unsigned char)((value) >> 24), \
\r
135 (cp)[1] = (unsigned char)((value) >> 16), \
\r
136 (cp)[2] = (unsigned char)((value) >> 8), \
\r
137 (cp)[3] = (unsigned char)(value) )
\r
139 #define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
\r
141 #define GET_16BIT_MSB_FIRST(cp) \
\r
142 (((unsigned long)(unsigned char)(cp)[0] << 8) | \
\r
143 ((unsigned long)(unsigned char)(cp)[1]))
\r
145 #define PUT_16BIT_MSB_FIRST(cp, value) ( \
\r
146 (cp)[0] = (unsigned char)((value) >> 8), \
\r
147 (cp)[1] = (unsigned char)(value) )
\r