1 /* 2 * $Id: qslib.h,v 1.14 2005/08/12 16:40:51 mitry Exp $ 3 * 4 * $Log: qslib.h,v $ 5 * Revision 1.14 2005/08/12 16:40:51 mitry 6 * Added wktime_str() 7 * 8 * Revision 1.13 2005/08/12 15:36:19 mitry 9 * Changed gmtoff() 10 * 11 * Revision 1.12 2005/05/16 11:20:13 mitry 12 * Updated function prototypes. Changed code a bit. 13 * 14 * Revision 1.11 2005/05/11 20:26:25 mitry 15 * Cosmetic change 16 * 17 * Revision 1.10 2005/05/11 18:08:04 mitry 18 * Changed xrealloc() code 19 * 20 * Revision 1.9 2005/05/06 20:41:08 mitry 21 * Changed setproctitle() code 22 * 23 * Revision 1.8 2005/04/05 09:31:12 mitry 24 * New xstrcpy() and xstrcat() 25 * 26 * Revision 1.7 2005/03/31 19:40:38 mitry 27 * Update function prototypes and it's duplication 28 * 29 * Revision 1.6 2005/03/28 17:02:53 mitry 30 * Pre non-blocking i/o update. Mostly non working. 31 * 32 * Revision 1.5 2005/02/09 11:18:44 mitry 33 * More proper writing for XBLANK 34 * 35 * Revision 1.4 2005/02/08 20:02:21 mitry 36 * New define for SIZES and SIZEC 37 * 38 */ 39 40 #ifndef __QSLIB_H__ 41 #define __QSLIB_H__ 42 43 extern char progname[]; 44 extern char version[]; 45 extern char cvsdate[]; 46 extern char *osname; 47 48 extern char *hexdigitslower; 49 extern char *hexdigitsupper; 50 extern char *hexdigitsall; 51 extern char *engms[]; 52 extern char *infostrs[]; 53 54 #define FETCH32(p) (((byte*)(p))[0]+(((byte*)(p))[1]<<8)+ \ 55 (((byte*)(p))[2]<<16)+(((byte*)(p))[3]<<24)) 56 #define STORE32(p,i) ((byte*)(p))[0]=i;((byte*)(p))[1]=i>>8; \ 57 ((byte*)(p))[2]=i>>16;((byte*)(p))[3]=i>>24; 58 #define INC32(p) p=(byte*)(p)+4 59 #define FETCH16(p) (((byte*)(p))[0]+(((byte*)(p))[1]<<8)) 60 #define STORE16(p,i) ((byte*)(p))[0]=i;((byte*)(p))[1]=i>>8; 61 #define INC16(p) p=(byte*)(p)+2 62 63 #define BYTES ((dword) 9999) 64 #define KBYTES ((dword) 10238976) 65 #define MBYTES ((dword) 10484711424) 66 67 #define SIZES(x) ( ((dword)(x)<BYTES) ? (x) : ( ((dword)(x)<KBYTES) ? ((dword)(x)/1024) : ((dword)(x)/1048576) )) 68 #define SIZEC(x) ( ((dword)(x)<BYTES) ? 'b' : ( ((dword)(x)<KBYTES) ? 'K' : 'M' )) 69 70 /* 71 #define SIZES(x) (((x)<1024) ? (x) : (((x)<1048576) ? ((x)/1024) : (((x)<1073741824) ? ((x)/1048576) : ((x)/1073741824)))) 72 #define SIZEC(x) (((x)<1024) ? 'b' : (((x)<1048576) ? 'K' : (((x)<1073741824) ? 'M' : 'G' ))) 73 */ 74 75 #define xfree(p) \ 76 do { \ 77 if ( p ) \ 78 free(p); \ 79 (p) = NULL; \ 80 } while(0) 81 82 #define SS(str) ((str)?(str):"") 83 84 #define XBLANK( str ) ( *(str) && isspace( *(str) )) 85 #define xmalloc(n) _xmalloc((size_t)(n)) 86 #define xcalloc(n,s) _xcalloc((size_t)(n),(size_t)(s)) 87 88 void *_xmalloc(size_t); 89 void *_xcalloc(size_t, size_t); 90 void *xrealloc(void *, size_t); 91 char *xstrdup(const char *); 92 93 char *restrcpy(char **, const char *); 94 char *restrcat(char **, const char *); 95 void strlwr(char *); 96 void strupr(char *); 97 void strtr(char *, char, char); 98 void chop(char *, int); 99 size_t chopc(char *, char); 100 char *skip_blanks(char *); 101 void skip_blanksr(char *); 102 103 char *xstrcpy(char *, const char *, size_t); 104 char *xstrcat(char *, const char *, size_t); 105 106 void bin2strhex(void *, const void *, size_t); 107 int strhex2bin(void *, const void *); 108 109 time_t gmtoff(time_t); 110 char *wktime_str(const char *); 111 112 #ifndef HAVE_SETPROCTITLE 113 114 void initsetproctitle(int, char **, char **); 115 void setproctitle(const char *, ...); 116 117 #else 118 119 #define initsetproctitle(x,y,z) 120 #define SPT_TYPE SPT_BUILTIN 121 122 #endif /* !HAVE_SETPROCTITLE */ 123 124 void u_vers(const char *); 125 126 #endif 127