Skip to content

Instantly share code, notes, and snippets.

@koenbollen
Created February 20, 2012 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koenbollen/1871533 to your computer and use it in GitHub Desktop.
Save koenbollen/1871533 to your computer and use it in GitHub Desktop.
Old useful C header
/**
* bail.h supplies the macro bail( expr, s ); "no description, read the code"
* version 1.0
* Copyright (C) 2008, Koen Bollen
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* http://www.gnu.org/licenses/gpl.txt
*/
#ifdef BAIL_H
# undef BAIL_H
# undef bail
#endif /* BAIL_H */
#define BAIL_H 1
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef NDEBUG
# define bail( expr, s ) \
if( expr ) { \
fprintf( stderr, "error: %s: %s\n", s, strerror( errno ) ); \
exit( 1 ); \
}
#else /* NDEBUG */
# define bail( expr, s ) \
if( expr ) { \
fprintf( stderr, "%s:%d: %s: %s ( %s )\n", __FILE__, __LINE__, s, strerror( errno ), #expr ); \
exit( 1 ); \
}
#endif /* NDEBUG */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment