#ifndef __INC_LIBTHECORE_UTILS_H__ #define __INC_LIBTHECORE_UTILS_H__ // Random number generator #include "effolkronium/random.hpp" using Random = effolkronium::random_static; #include #define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c)) #define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c)) #define str_cmp strcasecmp #define core_dump() core_dump_unix(__FILE__, __LINE__) extern void core_dump_unix(const char *who, WORD line); // Äھ °­Á¦·Î ´ýÇÁ #define TOKEN(string) if (!str_cmp(token_string, string)) // src = ÅäÅ« : °ª extern void parse_token(char * src, char * token, char * value); extern void trim_and_lower(const char * src, char * dest, size_t dest_size); // a¿Í bÀÇ ½Ã°£ÀÌ ¾ó¸¶³ª Â÷À̳ª´ÂÁö ¸®ÅÏ extern struct timeval * timediff(const struct timeval *a, const struct timeval *b); // aÀÇ ½Ã°£¿¡ bÀÇ ½Ã°£À» ´õÇØ ¸®ÅÏ extern struct timeval * timeadd(struct timeval *a, struct timeval *b); // ÇöÀç ½Ã°£ curr_tmÀ¸·Î ºÎÅÍ days°¡ Áö³­ ³¯À» ¸®ÅÏ extern struct tm * tm_calc(const struct tm *curr_tm, int days); extern void thecore_sleep(struct timeval * timeout); // timeout¸¸Å­ ÇÁ·Î¼¼½º ½¬±â extern float get_float_time(); extern DWORD get_dword_time(); extern char * time_str(time_t ct); std::string GetSocketHost(const sockaddr * address); in_port_t GetSocketPort(const sockaddr * address); #define CREATE(result, type, number) do { \ if (!((result) = (type *) calloc ((number), sizeof(type)))) { \ sys_err("calloc failed [%d] %s", errno, strerror(errno)); \ abort(); } } while(0) #define RECREATE(result,type,number) do { \ if (!((result) = (type *) realloc ((result), sizeof(type) * (number)))) { \ sys_err("realloc failed [%d] %s", errno, strerror(errno)); \ abort(); } } while(0) // Next ¿Í Prev °¡ ÀÖ´Â ¸®½ºÆ®¿¡ Ãß°¡ #define INSERT_TO_TW_LIST(item, head, prev, next) \ if (!(head)) \ { \ head = item; \ (head)->prev = (head)->next = NULL; \ } \ else \ { \ (head)->prev = item; \ (item)->next = head; \ (item)->prev = NULL; \ head = item; \ } #define REMOVE_FROM_TW_LIST(item, head, prev, next) \ if ((item) == (head)) \ { \ if (((head) = (item)->next)) \ (head)->prev = NULL; \ } \ else \ { \ if ((item)->next) \ (item)->next->prev = (item)->prev; \ \ if ((item)->prev) \ (item)->prev->next = (item)->next; \ } #define INSERT_TO_LIST(item, head, next) \ (item)->next = (head); \ (head) = (item); \ #define REMOVE_FROM_LIST(item, head, next) \ if ((item) == (head)) \ head = (item)->next; \ else \ { \ temp = head; \ \ while (temp && (temp->next != (item))) \ temp = temp->next; \ \ if (temp) \ temp->next = (item)->next; \ } \ #ifndef MAKEFOURCC #define MAKEFOURCC(ch0, ch1, ch2, ch3) \ ((DWORD)(BYTE) (ch0 ) | ((DWORD)(BYTE) (ch1) << 8) | \ ((DWORD)(BYTE) (ch2) << 16) | ((DWORD)(BYTE) (ch3) << 24)) #endif // defined(MAKEFOURCC) // _countof for gcc/g++ #if !defined(_countof) #if !defined(__cplusplus) #define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0])) #else extern "C++" { template char (*__countof_helper(_CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray]; #define _countof(_Array) sizeof(*__countof_helper(_Array)) } #endif #endif #ifdef __WIN32__ extern void gettimeofday(struct timeval* t, struct timezone* dummy); #endif #endif // __INC_UTILS_H__