Sebastian Kuschel reports that pfd_closing can be called for a socket
[u/mdw/putty] / misc.h
CommitLineData
eaf1e20a 1/*
2 * Header for misc.c.
3 */
4
db9c0f86 5#ifndef PUTTY_MISC_H
6#define PUTTY_MISC_H
7
8#include "puttymem.h"
9
39934deb 10#include <stdio.h> /* for FILE * */
57356d63 11#include <stdarg.h> /* for va_list */
d72d0e81 12#include <time.h> /* for struct tm */
57356d63 13
3f2d010c 14#ifndef FALSE
15#define FALSE 0
16#endif
17#ifndef TRUE
18#define TRUE 1
19#endif
20
9a30e26b 21typedef struct Filename Filename;
22typedef struct FontSpec FontSpec;
23
d57f70af 24unsigned long parse_blocksize(const char *bs);
d45d4c07 25char ctrlparse(char *s, char **next);
d57f70af 26
57356d63 27char *dupstr(const char *s);
28char *dupcat(const char *s1, ...);
29char *dupprintf(const char *fmt, ...);
30char *dupvprintf(const char *fmt, va_list ap);
12b9e82d 31void burnstr(char *string);
03f64569 32
b1650067 33int toint(unsigned);
34
39934deb 35char *fgetline(FILE *fp);
36
1549e076 37void base64_encode_atom(unsigned char *data, int n, char *out);
38
5471d09a 39struct bufchain_granule;
40typedef struct bufchain_tag {
41 struct bufchain_granule *head, *tail;
42 int buffersize; /* current amount of buffered data */
43} bufchain;
44
45void bufchain_init(bufchain *ch);
46void bufchain_clear(bufchain *ch);
47int bufchain_size(bufchain *ch);
e0e7dff8 48void bufchain_add(bufchain *ch, const void *data, int len);
5471d09a 49void bufchain_prefix(bufchain *ch, void **data, int *len);
50void bufchain_consume(bufchain *ch, int len);
7983f47e 51void bufchain_fetch(bufchain *ch, void *data, int len);
db9c0f86 52
aca589d9 53struct tm ltime(void);
54
b9e4cb98 55void smemclr(void *b, size_t len);
56
db9c0f86 57/*
58 * Debugging functions.
59 *
60 * Output goes to debug.log
61 *
62 * debug(()) (note the double brackets) is like printf().
63 *
64 * dmemdump() and dmemdumpl() both do memory dumps. The difference
523c5dd3 65 * is that dmemdumpl() is more suited for when the memory address is
db9c0f86 66 * important (say because you'll be recording pointer values later
67 * on). dmemdump() is more concise.
68 */
69
70#ifdef DEBUG
d0912d1f 71void debug_printf(char *fmt, ...);
32874aea 72void debug_memdump(void *buf, int len, int L);
d0912d1f 73#define debug(x) (debug_printf x)
db9c0f86 74#define dmemdump(buf,len) debug_memdump (buf, len, 0);
75#define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
76#else
77#define debug(x)
78#define dmemdump(buf,len)
79#define dmemdumpl(buf,len)
80#endif
81
db9c0f86 82#ifndef lenof
83#define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
84#endif
85
1709795f 86#ifndef min
87#define min(x,y) ( (x) < (y) ? (x) : (y) )
88#endif
89#ifndef max
7ffb2b52 90#define max(x,y) ( (x) > (y) ? (x) : (y) )
1709795f 91#endif
db9c0f86 92
51e9d3c0 93#define GET_32BIT_LSB_FIRST(cp) \
94 (((unsigned long)(unsigned char)(cp)[0]) | \
95 ((unsigned long)(unsigned char)(cp)[1] << 8) | \
96 ((unsigned long)(unsigned char)(cp)[2] << 16) | \
97 ((unsigned long)(unsigned char)(cp)[3] << 24))
98
99#define PUT_32BIT_LSB_FIRST(cp, value) ( \
100 (cp)[0] = (unsigned char)(value), \
101 (cp)[1] = (unsigned char)((value) >> 8), \
102 (cp)[2] = (unsigned char)((value) >> 16), \
103 (cp)[3] = (unsigned char)((value) >> 24) )
104
105#define GET_16BIT_LSB_FIRST(cp) \
106 (((unsigned long)(unsigned char)(cp)[0]) | \
107 ((unsigned long)(unsigned char)(cp)[1] << 8))
108
109#define PUT_16BIT_LSB_FIRST(cp, value) ( \
110 (cp)[0] = (unsigned char)(value), \
111 (cp)[1] = (unsigned char)((value) >> 8) )
112
113#define GET_32BIT_MSB_FIRST(cp) \
114 (((unsigned long)(unsigned char)(cp)[0] << 24) | \
115 ((unsigned long)(unsigned char)(cp)[1] << 16) | \
116 ((unsigned long)(unsigned char)(cp)[2] << 8) | \
117 ((unsigned long)(unsigned char)(cp)[3]))
118
119#define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
120
121#define PUT_32BIT_MSB_FIRST(cp, value) ( \
122 (cp)[0] = (unsigned char)((value) >> 24), \
123 (cp)[1] = (unsigned char)((value) >> 16), \
124 (cp)[2] = (unsigned char)((value) >> 8), \
125 (cp)[3] = (unsigned char)(value) )
126
127#define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
128
129#define GET_16BIT_MSB_FIRST(cp) \
130 (((unsigned long)(unsigned char)(cp)[0] << 8) | \
131 ((unsigned long)(unsigned char)(cp)[1]))
132
133#define PUT_16BIT_MSB_FIRST(cp, value) ( \
134 (cp)[0] = (unsigned char)((value) >> 8), \
135 (cp)[1] = (unsigned char)(value) )
136
db9c0f86 137#endif