X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/d76ed9a966ee3d955c8ef00ecc02e643c2005e2e..de9510bcaba3fc0377e09259f8b49921c421d269:/src/common.h diff --git a/src/common.h b/src/common.h index 952b1de..a053131 100644 --- a/src/common.h +++ b/src/common.h @@ -1,7 +1,7 @@ /* common.h - Common functions/includes * Copyright 2000-2004 srvx Development Team * - * This file is part of srvx. + * This file is part of x3. * * srvx is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,25 +64,66 @@ extern struct tm *localtime_r(const time_t *clock, struct tm *res); #endif #if defined(WITH_MALLOC_DMALLOC) -#define DMALLOC_FUNC_CHECK 1 -#include -#include +# define DMALLOC_FUNC_CHECK 1 +# include +# include #elif defined(WITH_MALLOC_MPATROL) -#include -#include +# include +# include #elif defined(WITH_MALLOC_BOEHM_GC) -#if !defined(NDEBUG) -#define GC_DEBUG 1 +# if !defined(NDEBUG) +# define GC_DEBUG 1 +# endif +# include +# include +# include +# define malloc(n) GC_MALLOC(n) +# define calloc(m,n) GC_MALLOC((m)*(n)) +# define realloc(p,n) GC_REALLOC((p),(n)) +# define free(p) GC_FREE(p) +# undef HAVE_STRDUP +# undef strdup +#elif defined(WITH_MALLOC_X3) +# undef malloc +# define malloc(n) x3_malloc(__FILE__, __LINE__, (n)) +# undef calloc +# define calloc(m,n) x3_malloc(__FILE__, __LINE__, (m)*(n)) +# undef realloc +# define realloc(p,n) x3_realloc(__FILE__, __LINE__, (p), (n)) +# undef free +# define free(p) x3_free(__FILE__, __LINE__, (p)) +# undef strdup +# define strdup(s) x3_strdup(__FILE__, __LINE__, (s)) +extern void *x3_malloc(const char *, unsigned int, size_t); +extern void *x3_realloc(const char *, unsigned int, void *, size_t); +extern char *x3_strdup(const char *, unsigned int, const char *); +extern void x3_free(const char *, unsigned int, void *); +# if !defined(NDEBUG) +extern void verify(const void *ptr); +# define verify(x) verify(x) +# endif +#elif defined(WITH_MALLOC_SLAB) +# define malloc(n) slab_malloc(__FILE__, __LINE__, (n)) +# undef calloc +# define calloc(m,n) slab_malloc(__FILE__, __LINE__, (m)*(n)) +# undef realloc +# define realloc(p,n) slab_realloc(__FILE__, __LINE__, (p), (n)) +# undef free +# define free(p) slab_free(__FILE__, __LINE__, (p)) +# undef strdup +# define strdup(s) slab_strdup(__FILE__, __LINE__, (s)) +extern void *slab_malloc(const char *, unsigned int, size_t); +extern void *slab_realloc(const char *, unsigned int, void *, size_t); +extern char *slab_strdup(const char *, unsigned int, const char *); +extern void slab_free(const char *, unsigned int, void *); +# if !defined(NDEBUG) +extern void verify(const void *ptr); +# define verify(x) verify(x) +# endif #endif -#include -#include -#include -#define malloc(n) GC_MALLOC(n) -#define calloc(m,n) GC_MALLOC((m)*(n)) -#define realloc(p,n) GC_REALLOC((p),(n)) -#define free(p) GC_FREE(p) -#undef HAVE_STRDUP -#undef strdup + +#ifndef verify +# define verify(ptr) (void)(ptr) #endif extern time_t now; @@ -96,6 +137,7 @@ typedef void (*exit_func_t)(void); void reg_exit_func(exit_func_t handler); void call_exit_funcs(void); +char *mysep(char **sepstr, char *delim); const char *inttobase64(char *buf, unsigned int v, unsigned int count); unsigned long base64toint(const char *s, int count); int split_line(char *line, int irc_colon, int argv_size, char *argv[]); @@ -140,6 +182,7 @@ void STRUCTNAME##_init(struct STRUCTNAME *list) {\ list->list = malloc(list->size*sizeof(list->list[0]));\ }\ void STRUCTNAME##_append(struct STRUCTNAME *list, ITEMTYPE new_item) {\ + verify(list->list);\ if (list->used == list->size) {\ list->size = list->size ? (list->size << 1) : 4;\ list->list = realloc(list->list, list->size*sizeof(list->list[0]));\ @@ -148,6 +191,7 @@ void STRUCTNAME##_append(struct STRUCTNAME *list, ITEMTYPE new_item) {\ }\ int STRUCTNAME##_remove(struct STRUCTNAME *list, ITEMTYPE new_item) {\ unsigned int n, found;\ + verify(list->list);\ for (found=n=0; nused; n++) {\ if (list->list[n] == new_item) {\ memmove(list->list+n, list->list+n+1, (list->used-n-1)*sizeof(list->list[n]));\ @@ -160,6 +204,7 @@ int STRUCTNAME##_remove(struct STRUCTNAME *list, ITEMTYPE new_item) {\ void STRUCTNAME##_clean(struct STRUCTNAME *list) {\ list->used = list->size = 0;\ free(list->list);\ + list->list = NULL;\ } /* The longest string that is likely to be produced in English is "10 @@ -173,6 +218,7 @@ char *intervalString(char *output, time_t interval, struct handle_info *hi); int getipbyname(const char *name, unsigned long *ip); int set_policer_param(const char *param, void *data, void *extra); const char *strtab(unsigned int ii); +char *time2str(time_t thetime); void tools_init(void); void tools_cleanup(void);