Simple Terminal from SuckLess
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
658 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include "util.h"
  3. #include <errno.h>
  4. #include <stdarg.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. void *
  9. emallocz(unsigned int size) {
  10. void *res = calloc(1, size);
  11. if(!res)
  12. eprint("fatal: could not malloc() %u bytes\n", size);
  13. return res;
  14. }
  15. void
  16. eprint(const char *errstr, ...) {
  17. va_list ap;
  18. va_start(ap, errstr);
  19. vfprintf(stderr, errstr, ap);
  20. va_end(ap);
  21. exit(EXIT_FAILURE);
  22. }
  23. void
  24. eprintn(const char *errstr, ...) {
  25. va_list ap;
  26. va_start(ap, errstr);
  27. vfprintf(stderr, errstr, ap);
  28. va_end(ap);
  29. fprintf(stderr, ": %s\n", strerror(errno));
  30. exit(EXIT_FAILURE);
  31. }