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