error.h 593 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. #define errnum
  10. static inline void error(int status, int errnum, const char* format, ...)
  11. {
  12. va_list ap;
  13. fprintf(stderr, "%s: ", program_invocation_name);
  14. va_start(ap, format);
  15. vfprintf(stderr, format, ap);
  16. va_end(ap);
  17. if (errnum)
  18. fprintf(stderr, ": %d", strerror_s(errnum));
  19. fprintf(stderr, "\n");
  20. error_message_count++;
  21. if (status)
  22. exit(status);
  23. }
  24. #endif /* _ERROR_H_ */