- fixed the slow memory leak problem.
[codemux.git] / codemuxlib.h
1 #ifndef _APPLIB_H_
2 #define _APPLIB_H_
3
4 #include <stdio.h>
5 #include <sys/time.h>
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <netinet/in.h>
9 #include <sys/mman.h>
10 #include <netdb.h>
11 #include <limits.h>
12 #include <string.h>
13 #ifdef OS_LINUX
14 #include <alloca.h>
15 #endif
16
17 #include "appdef.h"
18
19 typedef void* HANDLE;
20
21 /* stripped version of applib.c for codemux */
22
23 extern char *GetNextLine(FILE *file);
24 extern int   WordCount(char *buf);
25 extern char *GetField(const char *start, int whichField);
26 extern char *GetWord(const char *start, int whichWord);
27 extern int   DoesDotlessSuffixMatch(char *start, int len, char *suffix);
28 extern int   CreatePrivateAcceptSocket(int portNum, int nonBlocking);
29 extern char *StrdupLower(const char *orig);
30 extern void  StrcpyLower(char *dest, const char *src);
31
32 extern int OpenLogF(HANDLE file);
33 extern int WriteLog(HANDLE file, const char* data, int size, int forceFlush);
34 extern void DailyReopenLogF(HANDLE file);
35 extern unsigned int HashString(const char *name, unsigned int hash, 
36                                int endOnQuery, int skipLastIfDot);
37
38 #define FlushLogF(h)  WriteLog(h, NULL, 0, TRUE)
39
40 #define MASK 0xFFFFFFFF
41 #define _rotl(Val, Bits) ((((Val)<<(Bits)) | (((Val) & MASK)>>(32 - (Bits)))) & MASK)
42
43 /* nice exit support */
44 extern void  NiceExitBack(int val, char *reason, char *file, int line);
45 #define NiceExit(val, reason) NiceExitBack(val, reason, __FILE__, __LINE__)
46
47
48 /*  allocate stack memory to copy "src" to "dest" in lower cases */
49 #define LOCAL_STR_DUP_LOWER(dest, src)    \
50   { dest = alloca(strlen(src) + 1);       \
51     StrcpyLower(dest, src);               \
52   }
53   
54 /*  allocate stack memory to copy "src" to "dest" */
55 #define LOCAL_STR_DUP(dest, src)         \
56   { dest = alloca(strlen(src) + 1);      \
57     strcpy(dest, src);                   \
58   }
59 #endif
60