error.h 550 B

12345678910111213141516171819202122232425262728
  1. #ifndef _ERROR_H_
  2. #define _ERROR_H_
  3. #include <stdarg.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <errno.h>
  8. static unsigned int error_message_count = 0;
  9. static inline void error(int status, int errnum, const char* format, ...)
  10. {
  11. va_list ap;
  12. fprintf(stderr, "%s: ", program_invocation_name);
  13. va_start(ap, format);
  14. vfprintf(stderr, format, ap);
  15. va_end(ap);
  16. if (errnum)
  17. fprintf(stderr, ": %s", strerror(errnum));
  18. fprintf(stderr, "\n");
  19. error_message_count++;
  20. if (status)
  21. exit(status);
  22. }
  23. #endif /* _ERROR_H_ */