1 /* 2 * wzdftpd - a modular and cool ftp server 3 * Copyright (C) 2002-2004 Pierre Chifflier 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * As a special exemption, Pierre Chifflier 20 * and other respective copyright holders give permission to link this program 21 * with OpenSSL, and distribute the resulting executable, without including 22 * the source code for OpenSSL in the source distribution. 23 */ 24 25 #ifndef __WZD_DEBUG__ 26 #define __WZD_DEBUG__ 27 28 #ifdef DEBUG 29 30 #define WZD_ASSERT_VOID(x) if (!(x)) { fprintf(stderr,"Assertion Failed "#x" on %s:%d\n",__FILE__,__LINE__); return ; } 31 #define WZD_ASSERT(x) if (!(x)) { fprintf(stderr,"Assertion Failed "#x" on %s:%d\n",__FILE__,__LINE__); return -1; } 32 #define WZD_ASSERT_RETURN(x,r) if (!(x)) { fprintf(stderr,"Assertion Failed "#x" on %s:%d\n",__FILE__,__LINE__); return (r); } 33 34 #else 35 36 #define WZD_ASSERT_VOID(x) 37 #define WZD_ASSERT(x) 38 #define WZD_ASSERT_RETURN(x,y) 39 40 #endif 41 42 #if defined(_MSC_VER) && (_MSC_VER < 1310) 43 # define __FUNCTION__ "unknown" 44 #endif 45 46 /** Check if fd is a valid file descriptor */ 47 int fd_is_valid(int fd); 48 49 /** Memory allocation */ 50 void * wzd_malloc(size_t size); 51 52 /** Memory reallocation */ 53 void * wzd_realloc(void * ptr, size_t size); 54 55 /** Copy memory area. The memory areas may overlap. */ 56 void * wzd_memmove(void * dst, const void * src, size_t size); 57 58 /** Free memory allocated by wzd_malloc */ 59 void wzd_free(void *ptr); 60 61 /** Copy with allocation */ 62 char * wzd_strdup(const char *s); 63 64 /** Copy with allocation, at most \a n bytes */ 65 char * wzd_strndup(const char *s, size_t n); 66 67 /** same as strncpy, but write only one zero at end of string */ 68 char * wzd_strncpy(char *dst, const char *src, size_t n); 69 70 /** Find the length of \a s , but scan at most \a n characters. */ 71 size_t wzd_strnlen (const char *s, size_t n); 72 73 /** init all debug functions */ 74 void wzd_debug_init(void); 75 76 /** end all debug functions */ 77 void wzd_debug_fini(void); 78 79 int fd_register(int fd, const char *desc, const char *file, unsigned int line, const char *function); 80 int fd_unregister(int fd, const char *desc, const char *file, unsigned int line, const char *function); 81 void fd_dump(void); 82 #ifdef DEBUG 83 # define FD_REGISTER(fd,desc) fd_register(fd,desc,__FILE__,__LINE__,__FUNCTION__) 84 # define FD_UNREGISTER(fd,desc) fd_unregister(fd,desc,__FILE__,__LINE__,__FUNCTION__) 85 #else 86 # define FD_REGISTER(fd,desc) 87 # define FD_UNREGISTER(fd,desc) 88 #endif 89 90 /** try to print the backtrace */ 91 void dump_backtrace(void); 92 93 /** \brief Check current context for corruptions */ 94 int check_context(struct wzd_context_t * context); 95 96 #ifdef DEBUG 97 98 /* debug file cache */ 99 /*#define ENABLE_CACHE*/ 100 /*#define WZD_DBG_CACHE*/ 101 102 /* debug users/groups cache */ 103 /*#define WZD_DBG_UGCACHE*/ 104 105 /* debug cookies parsing code */ 106 /*#define WZD_DBG_COOKIES*/ 107 108 /* debug crontab */ 109 /*#define WZD_DBG_CRONTAB*/ 110 111 /* debug events */ 112 /*#define WZD_DBG_EVENT*/ 113 114 /* debug ident */ 115 /*#define WZD_DBG_IDENT*/ 116 117 /* locking/unlocking files */ 118 /*#define WZD_DBG_LOCK*/ 119 120 /* modules loading/unloading */ 121 /*#define WZD_DBG_MODULES*/ 122 123 /* do not call abort() when trapping SIGSEGV */ 124 /*#define WZD_DBG_NOABORT*/ 125 126 /* debug permissions */ 127 /*#define WZD_DBG_PERMS*/ 128 129 /* debug tls */ 130 /*#define WZD_DBG_TLS*/ 131 132 /* debug vfs */ 133 /*#define WZD_DBG_VFS*/ 134 135 #ifdef HAVE_MPATROL 136 #include <mpatrol.h> 137 #endif 138 139 #endif /* DEBUG */ 140 141 #endif /* __WZD_DEBUG__ */ 142