/* $Id: misc.h,v 1.3 2006/09/17 08:19:15 maxim Exp $ * */ #ifndef MISC_H #define MISC_H #include #include "configure.h" int fdSize(int fd); int fileSize(char* filename); int fileSizeKb(char* filename); time_t fileTime(char* filename); char exists(char* filename); char makedir(char* dir); char removedir(char* name); int rename2(char* from, char* to); char writePidFile(char* name, char daemon, char exclusive); char* readFile(char* fileName, int* size); char removeDir(char* name); int addCount(char* file, char doFlush); enum { LOCAL_TIME, LOCAL_DATE, TODAY_TIME, SQL_DATE, SQL_TIME, HTTP_TIME, COOKIE_TIME }; //#define TM_DAY(TM) (((TM.tm_year-100) * 366) + TM.tm_yday) //#define TM_DAY(TM) (((TM.tm_year-100) << 9) + (TM.tm_mon << 5) + TM.tm_mday) //#define TM_DAY(TM) ((TM.tm_year-100)*10000 + (TM.tm_mon+1)*100 + TM.tm_mday) char* time2str(time_t t, char type); time_t getTime(); short getDay(struct tm* tm); struct tm* getDate(short day); unsigned biRound(unsigned value, unsigned n); short countBits(int v); #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) #define min(a,b) ((a) < (b) ? (a) : (b)) #define max(a,b) ((a) > (b) ? (a) : (b)) #define MALLOC(size) malloc_wrapper(size, __FILE__, __LINE__) #define CALLOC(size) calloc_wrapper(size, __FILE__, __LINE__) #define REALLOC(ptr, size) realloc_wrapper(ptr, size, __FILE__, __LINE__) #define STRDUP(str) strdup_wrapper(str, __FILE__, __LINE__) void* malloc_wrapper(size_t size, char* file, int line); void* calloc_wrapper(size_t size, char* file, int line); void* realloc_wrapper(void* ptr, size_t size, char* file, int line); char* strdup_wrapper(char* src, char* file, int line); #if DEBUGLOG #define FREE(ptr) free_wrapper(ptr, __FILE__, __LINE__) void* free_wrapper(void* ptr, char* file, int line); #else #define FREE(ptr) free_wrapper(ptr) void* free_wrapper(void* ptr); #endif #define DEBUG 0 #define MESSAGE 1 #define ERROR 2 #define ACTION 3 #define ACCESS 4 #define CLOSE_LOGS 7 #define TYPE_MASK 7 #define SYS_MASK (1 << 4) #define MY (0 << 4) #define SYS (1 << 4) #if DEBUGLOG #define message(flags, fmt, X...) message__(__FILE__, __LINE__, flags, fmt, ##X) char message__(char* file, int pos, int flags, char* fmt, ...); #else #define message(flags, fmt, X...) message__(flags, fmt, ##X) char message__(int flags, char* fmt, ...); #endif #if DEBUGLOG #define debug(fmt, X...) message(DEBUG, fmt, ##X) #else #define debug(fmt, X...) #endif extern time_t now; extern struct tm now_tm; extern short now_day; extern char now_str[]; extern int Debug; extern int myPID; extern char* progName; extern char* logName[TYPE_MASK+1]; #endif