2006-04-23 22:26:03 +04:00
|
|
|
/*
|
|
|
|
* Header for misc.c.
|
|
|
|
*/
|
|
|
|
|
2001-04-28 13:24:19 +04:00
|
|
|
#ifndef PUTTY_MISC_H
|
|
|
|
#define PUTTY_MISC_H
|
|
|
|
|
|
|
|
#include "puttymem.h"
|
|
|
|
|
2004-11-27 16:20:21 +03:00
|
|
|
#include <stdio.h> /* for FILE * */
|
2002-11-07 22:49:03 +03:00
|
|
|
#include <stdarg.h> /* for va_list */
|
2005-01-09 17:45:00 +03:00
|
|
|
#include <time.h> /* for struct tm */
|
2002-11-07 22:49:03 +03:00
|
|
|
|
2001-12-30 18:58:17 +03:00
|
|
|
#ifndef FALSE
|
|
|
|
#define FALSE 0
|
|
|
|
#endif
|
|
|
|
#ifndef TRUE
|
|
|
|
#define TRUE 1
|
|
|
|
#endif
|
|
|
|
|
2003-02-01 15:54:40 +03:00
|
|
|
typedef struct Filename Filename;
|
|
|
|
typedef struct FontSpec FontSpec;
|
|
|
|
|
2004-12-24 16:39:32 +03:00
|
|
|
unsigned long parse_blocksize(const char *bs);
|
2005-04-19 22:58:29 +04:00
|
|
|
char ctrlparse(char *s, char **next);
|
2004-12-24 16:39:32 +03:00
|
|
|
|
2002-11-07 22:49:03 +03:00
|
|
|
char *dupstr(const char *s);
|
|
|
|
char *dupcat(const char *s1, ...);
|
2013-11-17 18:05:44 +04:00
|
|
|
char *dupprintf(const char *fmt, ...)
|
|
|
|
#ifdef __GNUC__
|
|
|
|
__attribute__ ((format (printf, 1, 2)))
|
|
|
|
#endif
|
|
|
|
;
|
2002-11-07 22:49:03 +03:00
|
|
|
char *dupvprintf(const char *fmt, va_list ap);
|
2011-10-02 18:03:47 +04:00
|
|
|
void burnstr(char *string);
|
2001-08-26 19:31:29 +04:00
|
|
|
|
2013-07-14 14:45:54 +04:00
|
|
|
int toint(unsigned);
|
|
|
|
|
2004-11-27 16:20:21 +03:00
|
|
|
char *fgetline(FILE *fp);
|
|
|
|
|
2002-09-21 18:03:05 +04:00
|
|
|
void base64_encode_atom(unsigned char *data, int n, char *out);
|
|
|
|
|
2001-08-25 21:09:23 +04:00
|
|
|
struct bufchain_granule;
|
|
|
|
typedef struct bufchain_tag {
|
|
|
|
struct bufchain_granule *head, *tail;
|
|
|
|
int buffersize; /* current amount of buffered data */
|
|
|
|
} bufchain;
|
|
|
|
|
|
|
|
void bufchain_init(bufchain *ch);
|
|
|
|
void bufchain_clear(bufchain *ch);
|
|
|
|
int bufchain_size(bufchain *ch);
|
2003-01-10 21:33:35 +03:00
|
|
|
void bufchain_add(bufchain *ch, const void *data, int len);
|
2001-08-25 21:09:23 +04:00
|
|
|
void bufchain_prefix(bufchain *ch, void **data, int *len);
|
|
|
|
void bufchain_consume(bufchain *ch, int len);
|
2002-09-21 20:52:21 +04:00
|
|
|
void bufchain_fetch(bufchain *ch, void *data, int len);
|
2001-04-28 13:24:19 +04:00
|
|
|
|
2005-01-09 17:27:48 +03:00
|
|
|
struct tm ltime(void);
|
|
|
|
|
2012-07-28 20:33:51 +04:00
|
|
|
void smemclr(void *b, size_t len);
|
|
|
|
|
2001-04-28 13:24:19 +04:00
|
|
|
/*
|
|
|
|
* Debugging functions.
|
|
|
|
*
|
|
|
|
* Output goes to debug.log
|
|
|
|
*
|
|
|
|
* debug(()) (note the double brackets) is like printf().
|
|
|
|
*
|
|
|
|
* dmemdump() and dmemdumpl() both do memory dumps. The difference
|
2005-03-24 04:01:24 +03:00
|
|
|
* is that dmemdumpl() is more suited for when the memory address is
|
2001-04-28 13:24:19 +04:00
|
|
|
* important (say because you'll be recording pointer values later
|
|
|
|
* on). dmemdump() is more concise.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2003-03-06 16:24:02 +03:00
|
|
|
void debug_printf(char *fmt, ...);
|
2001-05-06 18:35:20 +04:00
|
|
|
void debug_memdump(void *buf, int len, int L);
|
2003-03-06 16:24:02 +03:00
|
|
|
#define debug(x) (debug_printf x)
|
2001-04-28 13:24:19 +04:00
|
|
|
#define dmemdump(buf,len) debug_memdump (buf, len, 0);
|
|
|
|
#define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
|
|
|
|
#else
|
|
|
|
#define debug(x)
|
|
|
|
#define dmemdump(buf,len)
|
|
|
|
#define dmemdumpl(buf,len)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef lenof
|
|
|
|
#define lenof(x) ( (sizeof((x))) / (sizeof(*(x))))
|
|
|
|
#endif
|
|
|
|
|
2002-10-09 22:09:42 +04:00
|
|
|
#ifndef min
|
|
|
|
#define min(x,y) ( (x) < (y) ? (x) : (y) )
|
|
|
|
#endif
|
|
|
|
#ifndef max
|
2002-10-14 13:04:23 +04:00
|
|
|
#define max(x,y) ( (x) > (y) ? (x) : (y) )
|
2002-10-09 22:09:42 +04:00
|
|
|
#endif
|
2001-04-28 13:24:19 +04:00
|
|
|
|
2005-04-13 00:04:56 +04:00
|
|
|
#define GET_32BIT_LSB_FIRST(cp) \
|
|
|
|
(((unsigned long)(unsigned char)(cp)[0]) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[1] << 8) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[2] << 16) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[3] << 24))
|
|
|
|
|
|
|
|
#define PUT_32BIT_LSB_FIRST(cp, value) ( \
|
|
|
|
(cp)[0] = (unsigned char)(value), \
|
|
|
|
(cp)[1] = (unsigned char)((value) >> 8), \
|
|
|
|
(cp)[2] = (unsigned char)((value) >> 16), \
|
|
|
|
(cp)[3] = (unsigned char)((value) >> 24) )
|
|
|
|
|
|
|
|
#define GET_16BIT_LSB_FIRST(cp) \
|
|
|
|
(((unsigned long)(unsigned char)(cp)[0]) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[1] << 8))
|
|
|
|
|
|
|
|
#define PUT_16BIT_LSB_FIRST(cp, value) ( \
|
|
|
|
(cp)[0] = (unsigned char)(value), \
|
|
|
|
(cp)[1] = (unsigned char)((value) >> 8) )
|
|
|
|
|
|
|
|
#define GET_32BIT_MSB_FIRST(cp) \
|
|
|
|
(((unsigned long)(unsigned char)(cp)[0] << 24) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[1] << 16) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[2] << 8) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[3]))
|
|
|
|
|
|
|
|
#define GET_32BIT(cp) GET_32BIT_MSB_FIRST(cp)
|
|
|
|
|
|
|
|
#define PUT_32BIT_MSB_FIRST(cp, value) ( \
|
|
|
|
(cp)[0] = (unsigned char)((value) >> 24), \
|
|
|
|
(cp)[1] = (unsigned char)((value) >> 16), \
|
|
|
|
(cp)[2] = (unsigned char)((value) >> 8), \
|
|
|
|
(cp)[3] = (unsigned char)(value) )
|
|
|
|
|
|
|
|
#define PUT_32BIT(cp, value) PUT_32BIT_MSB_FIRST(cp, value)
|
|
|
|
|
|
|
|
#define GET_16BIT_MSB_FIRST(cp) \
|
|
|
|
(((unsigned long)(unsigned char)(cp)[0] << 8) | \
|
|
|
|
((unsigned long)(unsigned char)(cp)[1]))
|
|
|
|
|
|
|
|
#define PUT_16BIT_MSB_FIRST(cp, value) ( \
|
|
|
|
(cp)[0] = (unsigned char)((value) >> 8), \
|
|
|
|
(cp)[1] = (unsigned char)(value) )
|
|
|
|
|
2001-04-28 13:24:19 +04:00
|
|
|
#endif
|