1 /* 2 * Copyright (C) 2016 Jakub Kruszona-Zawadzki, Core Technology Sp. z o.o. 3 * 4 * This file is part of MooseFS. 5 * 6 * MooseFS is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, version 2 (only). 9 * 10 * MooseFS 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 MooseFS; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA 18 * or visit http://www.gnu.org/licenses/gpl-2.0.html 19 */ 20 21 #ifndef _MASSERT_H_ 22 #define _MASSERT_H_ 23 24 #include <stdio.h> 25 #include <syslog.h> 26 #include <stdlib.h> 27 #include <errno.h> 28 29 #include "strerr.h" 30 31 #define massert(e,msg) ((e) ? (void)0 : (fprintf(stderr,"failed assertion '%s' : %s\n",#e,(msg)),syslog(LOG_ERR,"failed assertion '%s' : %s",#e,(msg)),abort())) 32 // #define passert(ptr) ((ptr!=NULL) ? (ptr!=(void*)(-1)) ? (void)0 : : (fprintf(stderr,"out of memory: %s is NULL\n",#ptr),syslog(LOG_ERR,"out of memory: %s is NULL",#ptr),abort())) 33 #define sassert(e) ((e) ? (void)0 : (fprintf(stderr,"failed assertion '%s'\n",#e),syslog(LOG_ERR,"failed assertion '%s'",#e),abort())) 34 #define passert(ptr) if (ptr==NULL) { \ 35 fprintf(stderr,"out of memory: %s is NULL\n",#ptr); \ 36 syslog(LOG_ERR,"out of memory: %s is NULL",#ptr); \ 37 abort(); \ 38 } else if (ptr==((void*)(-1))) { \ 39 const char *_mfs_errorstring = strerr(errno); \ 40 syslog(LOG_ERR,"mmap error on %s, error: %s",#ptr,_mfs_errorstring); \ 41 fprintf(stderr,"mmap error on %s, error: %s\n",#ptr,_mfs_errorstring); \ 42 abort(); \ 43 } 44 #define eassert(e) if (!(e)) { \ 45 const char *_mfs_errorstring = strerr(errno); \ 46 syslog(LOG_ERR,"failed assertion '%s', error: %s",#e,_mfs_errorstring); \ 47 fprintf(stderr,"failed assertion '%s', error: %s\n",#e,_mfs_errorstring); \ 48 abort(); \ 49 } 50 #define zassert(e) if ((e)!=0) { \ 51 const char *_mfs_errorstring = strerr(errno); \ 52 syslog(LOG_ERR,"unexpected status, '%s' returned: %s",#e,_mfs_errorstring); \ 53 fprintf(stderr,"unexpected status, '%s' returned: %s\n",#e,_mfs_errorstring); \ 54 abort(); \ 55 } 56 57 #endif 58