00001 #ifndef COMMONS_DIE_H
00002 #define COMMONS_DIE_H
00003
00004 #include <cerrno>
00005 #include <cstdio>
00006 #include <cstdarg>
00007 #include <cstring>
00008 #include <cstdlib>
00009
00010 namespace commons {
00011
00018 __attribute__((format(printf, 1, 2))) void
00019 die(const char *format, ...)
00020 {
00021 const char *errstr;
00022 va_list val;
00023 va_start(val, format);
00024 errstr = strerror(errno);
00025 vfprintf(stderr, format, val);
00026 if (strchr(format, '\n') == NULL)
00027 fprintf(stderr, ": %s\n", errstr);
00028 exit(1);
00029 }
00030
00031 }
00032
00033 #endif