error.h 489 B

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